enumeration

C - forward declaration of enums?

。_饼干妹妹 提交于 2019-12-05 01:32:12
Forward declaration of enums in C does not work for me. I searched the internet and stackoverflow but all of the questions regarding forward declarations of enumerators refer to c++. What do you do for declaring enumerators in C? Put them at the top of each file (or in an include) so that all functions in the file can access them? Thanks Put them in a header so that all files that need them can access the header and use the declarations from it. When compiled with the options: $ /usr/bin/gcc -g -std=c99 -Wall -Wextra -c enum.c $ GCC 4.2.1 (on MacOS X 10.7.1) accepts the following code: enum

Hibernate Enumeration Mapping

做~自己de王妃 提交于 2019-12-04 20:45:53
I have a legacy database table that, for simplicity sake looks like: table address{ varchar line1 varchar line2 varchar line3 varchar(1) deliveryline } There is a check constraint on deliveryline guaranteeing it has the values '1,'2', or '3' . This seems like a good candidate for enumeration in hibernate. I have an entity that looks like this representing the Address table: public class Address{ String line1; String line2; String line3; DeliveryLine deliveryLine; } I normally use @Enumerated(EnumType.STRING) on when mapping enums, but that strategy does not work here. For example: public enum

Enumerate Possible Matches of Regular Expression in Java

穿精又带淫゛_ 提交于 2019-12-04 19:33:33
问题 I want to enumerate all the possible values of a finite regular expression in Java for testing purposes. For some context, I have a regular expression that I'm using to match allowable color values in words. Here's a shortened version of it as an example: (white|black)|((light|dark) )?(red|green|blue|gray) I wanted to create a unit test that would enumerate all these values and pass each of them to my utility class which produces a Color object from these, that way if I change the regular

Best way to enumerate a cartesian product with labels in python?

核能气质少年 提交于 2019-12-04 15:02:29
Given a dictionary mapping variables to possible outcomes: { 'lblA' : [False, True], 'lblB' : [False, True], 'lblC' : [0,1,2] } I want to enumerate all possible dictionary outcomes: [ { 'lblA' : False , 'lblB' : False, 'lblC' : 0 }, { 'lblA' : True , 'lblB' : False, 'lblC' : 0 }, { 'lblA' : False , 'lblB' : True, 'lblC' : 0 }, { 'lblA' : True , 'lblB' : True, 'lblC' : 0 }, { 'lblA' : False , 'lblB' : False, 'lblC' : 1 }, { 'lblA' : True , 'lblB' : False, 'lblC' : 1 }, { 'lblA' : False , 'lblB' : True, 'lblC' : 1 }, { 'lblA' : True , 'lblB' : True, 'lblC' : 1 }, { 'lblA' : False , 'lblB' :

iterating through Enumeration of hastable keys throws NoSuchElementException error

左心房为你撑大大i 提交于 2019-12-04 14:55:27
问题 I am trying to iterate through a list of keys from a hash table using enumeration however I keep getting a NoSuchElementException at the last key in list? Hashtable<String, String> vars = new Hashtable<String, String>(); vars.put("POSTCODE","TU1 3ZU"); vars.put("EMAIL","job.blogs@lumesse.com"); vars.put("DOB","02 Mar 1983"); Enumeration<String> e = vars.keys(); while(e.hasMoreElements()){ System.out.println(e.nextElement()); String param = (String) e.nextElement(); } Console output: EMAIL

Finding Strings Neighbors By Up To 2 Differing Positions

北城以北 提交于 2019-12-04 13:59:33
Given a seed string, I want to find its neighbors with at most differ in 2 positions. All the digits involve in generating string are only four (i.e. 0,1,2,3). This is the example for what I mean: # In this example, 'first' column # are neighbors with only 1 position differ. # The rest of the columns are 2 positions differ Seed = 000 100 110 120 130 101 102 103 200 210 220 230 201 202 203 300 310 320 330 301 302 303 010 011 012 013 020 021 022 023 030 031 032 033 001 002 003 Seed = 001 101 111 121 131 100 102 103 201 211 221 231 200 202 203 301 311 321 331 300 302 303 011 010 012 013 021 020

Differences Between PowerShell and C# when Enumerating a Collection

喜夏-厌秋 提交于 2019-12-04 11:13:50
Here is a simple scenario in C#: var intList = new List<int>(); intList.Add(4); intList.Add(7); intList.Add(2); intList.Add(9); intList.Add(6); foreach (var num in intList) { if (num == 9) { intList.Remove(num); Console.WriteLine("Removed item: " + num); } Console.WriteLine("Number is: " + num); } This throws an InvalidOperationException because I am modifying the collection while enumerating it. Now consider similar PowerShell code: $intList = 4, 7, 2, 9, 6 foreach ($num in $intList) { if ($num -eq 9) { $intList = @($intList | Where-Object {$_ -ne $num}) Write-Host "Removed item: " $num }

Java extendable enumeration

泄露秘密 提交于 2019-12-04 05:31:29
Is there a way to write an enumeration that can be extended. I have several methods that I would like to always have available for my enumerations. For example I use an enumeration for my database fields. I include the actual field name in the database. public enum ORDERFIELDS { OrderID("Order_ID"); private String FieldName; private ORDERFIELDS(String fname) { this.FieldName = fname; } public String getFieldName() { return FieldName; } } Dónal If I understand correctly, what you'd like to do is something like this: public abstract class DatabaseField { private String fieldName; private

XSD: How to restrict enumeration values of a derived complex type?

末鹿安然 提交于 2019-12-04 05:18:55
Given the following example: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="Book" abstract="true"> <xs:sequence> <xs:element name="titel" type="xs:string"> </xs:element> <xs:element name="bookCode" type="BookEnum"/> </xs:sequence> </xs:complexType> <xs:complexType name="Lyric"> <xs:complexContent> <xs:extension base="Book"> <xs:sequence> <xs:element name="author" type="xs:string"> </xs:element> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:simpleType name="BookEnum"> <xs:restriction base="xs:int"> <xs:enumeration value="Paperback"/>

.NET databinding a combobox to a string enum with Description attributes

一世执手 提交于 2019-12-04 04:26:22
I have an enum like this: public enum Cities { [Description("New York City")] NewYork, [Description("Los Angeles")] LosAngeles, Washington, [Description("San Antonio")] SanAntonio, Chicago } I want to bind this to a combobox and I've tried this: comboBox.DataSource = Enum.GetNames(typeof(Cities)); But that displays the values in the combobox rather than the String description. So I switched to this: public static string GetEnumDescription(Enum value) { FieldInfo fi = value.GetType().GetField(value.ToString()); DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes