enums

Python: How to decode enum type from json

淺唱寂寞╮ 提交于 2021-02-11 06:48:04
问题 class MSG_TYPE(IntEnum): REQUEST = 0 GRANT = 1 RELEASE = 2 FAIL = 3 INQUIRE = 4 YIELD = 5 def __json__(self): return str(self) class MessageEncoder(JSONEncoder): def default(self, obj): return obj.__json__() class Message(object): def __init__(self, msg_type, src, dest, data): self.msg_type = msg_type self.src = src self.dest = dest self.data = data def __json__(self): return dict (\ msg_type=self.msg_type, \ src=self.src, \ dest=self.dest, \ data=self.data,\ ) def ToJSON(self): return json

Generate typed dictionary with a for loop using an enum as key type but without using `?` to mark undefined in TypeScript

烂漫一生 提交于 2021-02-11 04:35:01
问题 The problem is that I want to use enum as key for a dictionary but I want to dynamically generate the entries using a loop. But I will prefer not to use ? operator because I know I'll fill all keys and I don't want to force ! evaluation for each call. enum Students { A, B, C, // many many students } // class Info(); // some properties like grades and teacher const studentInfo: { [key in Students]: Info }; // won't work const must be initialized const studentInfo: { [key in Students]: Info } =

Generate typed dictionary with a for loop using an enum as key type but without using `?` to mark undefined in TypeScript

只愿长相守 提交于 2021-02-11 04:31:12
问题 The problem is that I want to use enum as key for a dictionary but I want to dynamically generate the entries using a loop. But I will prefer not to use ? operator because I know I'll fill all keys and I don't want to force ! evaluation for each call. enum Students { A, B, C, // many many students } // class Info(); // some properties like grades and teacher const studentInfo: { [key in Students]: Info }; // won't work const must be initialized const studentInfo: { [key in Students]: Info } =

Generate typed dictionary with a for loop using an enum as key type but without using `?` to mark undefined in TypeScript

限于喜欢 提交于 2021-02-11 04:30:10
问题 The problem is that I want to use enum as key for a dictionary but I want to dynamically generate the entries using a loop. But I will prefer not to use ? operator because I know I'll fill all keys and I don't want to force ! evaluation for each call. enum Students { A, B, C, // many many students } // class Info(); // some properties like grades and teacher const studentInfo: { [key in Students]: Info }; // won't work const must be initialized const studentInfo: { [key in Students]: Info } =

How to search an enum in list of strings by postgresql query?

末鹿安然 提交于 2021-02-10 22:31:53
问题 Consider a SQL Statement: select * from table where status in <statuses> Where status is an enum: CREATE TYPE statusType AS ENUM ( 'enum1', 'enum2'; In Java I have a list of the enums in string representation: List<String> list = new ArrayList<>(); list.add("enum1"); list.add("enum2"); I then try to build and execute the query using SqlStatement: handle.createQuery("select * from table where status in <statuses>") .bindList("statuses", statuses) .map(Mapper.instance) .list()); I keep getting

How to search an enum in list of strings by postgresql query?

笑着哭i 提交于 2021-02-10 22:28:47
问题 Consider a SQL Statement: select * from table where status in <statuses> Where status is an enum: CREATE TYPE statusType AS ENUM ( 'enum1', 'enum2'; In Java I have a list of the enums in string representation: List<String> list = new ArrayList<>(); list.add("enum1"); list.add("enum2"); I then try to build and execute the query using SqlStatement: handle.createQuery("select * from table where status in <statuses>") .bindList("statuses", statuses) .map(Mapper.instance) .list()); I keep getting

List all enums defined in a package recursively

感情迁移 提交于 2021-02-10 18:33:42
问题 Was using org.reflections API to find that it doesn't work with Enums : List<ClassLoader> classLoadersList = new LinkedList<>(); classLoadersList.add(ClasspathHelper.contextClassLoader()); classLoadersList.add(ClasspathHelper.staticClassLoader()); Reflections reflections = new Reflections(new org.reflections.util.ConfigurationBuilder() .setScanners(new SubTypesScanner(false), new ResourcesScanner()) .setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))

How to check if string exists in Enum of strings?

给你一囗甜甜゛ 提交于 2021-02-10 07:10:49
问题 I have created the following Enum: from enum import Enum class Action(str, Enum): NEW_CUSTOMER = "new_customer" LOGIN = "login" BLOCK = "block" I have inherited from str , too, so that I can do things such as: action = "new_customer" ... if action == Action.NEW_CUSTOMER: ... I would now like to be able to check if a string is in this Enum, such as: if "new_customer" in Action: .... I have tried adding the following method to the class: def __contains__(self, item): return item in [i for i in

How to check if string exists in Enum of strings?

风格不统一 提交于 2021-02-10 07:10:15
问题 I have created the following Enum: from enum import Enum class Action(str, Enum): NEW_CUSTOMER = "new_customer" LOGIN = "login" BLOCK = "block" I have inherited from str , too, so that I can do things such as: action = "new_customer" ... if action == Action.NEW_CUSTOMER: ... I would now like to be able to check if a string is in this Enum, such as: if "new_customer" in Action: .... I have tried adding the following method to the class: def __contains__(self, item): return item in [i for i in

How to check if string exists in Enum of strings?

倖福魔咒の 提交于 2021-02-10 07:05:28
问题 I have created the following Enum: from enum import Enum class Action(str, Enum): NEW_CUSTOMER = "new_customer" LOGIN = "login" BLOCK = "block" I have inherited from str , too, so that I can do things such as: action = "new_customer" ... if action == Action.NEW_CUSTOMER: ... I would now like to be able to check if a string is in this Enum, such as: if "new_customer" in Action: .... I have tried adding the following method to the class: def __contains__(self, item): return item in [i for i in