enumeration

Iterate an Enumeration in Java 8

余生颓废 提交于 2019-12-03 02:31:17
问题 Is it possible to iterate an Enumeration by using Lambda Expression? What will be the Lambda representation of the following code snippet: Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); while (nets.hasMoreElements()) { NetworkInterface networkInterface = nets.nextElement(); } I didn't find any stream within it. 回答1: In case you don’t like the fact that Collections.list(Enumeration) copies the entire contents into a (temporary) list before the iteration starts,

Why is the enumeration value from a multi dimensional array not equal to itself?

瘦欲@ 提交于 2019-12-03 02:29:11
问题 Consider: using System; public class Test { enum State : sbyte { OK = 0, BUG = -1 } static void Main(string[] args) { var s = new State[1, 1]; s[0, 0] = State.BUG; State a = s[0, 0]; Console.WriteLine(a == s[0, 0]); // False } } How can this be explained? It occurs in debug builds in Visual Studio 2015 when running in the x86 JIT. A release build or running in the x64 JIT prints True as expected. To reproduce from the command line: csc Test.cs /platform:x86 /debug ( /debug:pdbonly , /debug

Delphi 2010 RTTI : Explore Enumerations

大憨熊 提交于 2019-12-03 02:13:23
Considering such an enumeration : type TTypeOfData = ( [XmlName('ABC')] todABC, [XmlName('DEF')] todDEF, [XmlName('GHI')] todGHI ); Where XmlName is a custom attribute used to define the serialization string for members of this enumeration. How can I explore the attributes attached to each member of this enumeration ? Attributes associated with elements in enumerations are not currently stored in Win32 RTTI data in the executable. RTTI is already responsible for a fair increase in the size of executables, so some lines had to be drawn somewhere. Attributes in Delphi Win32 are supported on

Get an Enumeration (for the Keys) of a Map (HashMap) in Java?

半腔热情 提交于 2019-12-02 22:23:53
As far as I understand this, it seems that there is not a direct way of getting an Enumeration directly for the Keys of a HashMap . I can only get a keySet() . From that Set , I can get an Iterator but an Iterator seems to be something different than an Enumeration . What is the best and most performant way to directly get an Enumeration from the Keys of a HashMap ? Background: I am implementing my own ResourceBundle (=> getKeys() Method), and I have to provide/implement a method that returns the Enumeration of all Keys. But my implementation is based on a HashMap so I need to somehow figure

Scala Best Practices: Trait Inheritance vs Enumeration

…衆ロ難τιáo~ 提交于 2019-12-02 22:22:49
I'm currently experimenting with Scala and looking for best practices. I found myself having two opposite approaches to solving a single problem. I'd like to know which is better and why, which is more conventional, and if maybe you know of some other better approaches. The second one looks prettier to me. 1. Enumeration-based solution import org.squeryl.internals.DatabaseAdapter import org.squeryl.adapters.{H2Adapter, MySQLAdapter, PostgreSqlAdapter} import java.sql.Driver object DBType extends Enumeration { val MySql, PostgreSql, H2 = Value def fromUrl(url: String) = { url match { case u if

Possible multiple enumeration of IEnumerable? [duplicate]

為{幸葍}努か 提交于 2019-12-02 22:03:27
This question already has an answer here: Handling warning for possible multiple enumeration of IEnumerable 7 answers why is that ? how can I fix it ? There is nothing to fix here. Any() will iterate the enumeration but stop after the first element (after which it returns true). Multiple enumerations are mainly a problem in two cases: Performance: Generally you want to avoid multiple iterations if you can, because it is slower. This does not apply here since Any() will just confirm there is at least one element and is a required check for you. Also you are not accessing any remote/external

enum implementation inside interface - Java

元气小坏坏 提交于 2019-12-02 21:56:11
I have a question about putting a Java enum in the interface. To make it clearer, please see the following code: public interface Thing{ public enum Number{ one(1), two(2), three(3); private int value; private Number(int value) { this.value = value; } public int getValue(){ return value; } } public Number getNumber(); public void method2(); ... } I know that an interface consists of methods with empty bodies . However, the enum I used here needs a constructor and a method to get an associated value. In this example, the proposed interface will not just consist of methods with empty bodies. Is

Deleting registry key values

对着背影说爱祢 提交于 2019-12-02 20:13:54
问题 In MSDN it says that RegEnumValue should not be used when calling function that change the registry keys being enumerated. So does this also apply to deleting registry key values? Like this code does: if (RegOpenKeyEx(m_hkey,m_path.c_str(),0,KEY_ALL_ACCESS,&key) == ERROR_SUCCESS) { bool error=false; idx=0; while (RegEnumValue(key,idx,name,&namesize,NULL,NULL,NULL,NULL) == ERROR_SUCCESS && !error) { error=(RegDeleteValue(key,name)!=ERROR_SUCCESS); idx++; } RegCloseKey(key); } 回答1: Your code

How to convert string result of enum with overridden toString() back to enum?

◇◆丶佛笑我妖孽 提交于 2019-12-02 17:13:06
Given the following java enum: public enum AgeRange { A18TO23 { public String toString() { return "18 - 23"; } }, A24TO29 { public String toString() { return "24 - 29"; } }, A30TO35 { public String toString() { return "30 - 35"; } }, } Is there any way to convert a string value of "18 - 23" to the corresponding enum value i.e. AgeRange.A18TO23 ? Thanks! sakana The best and simplest way to do it is like this: public enum AgeRange { A18TO23 ("18-23"), A24TO29 ("24-29"), A30TO35("30-35"); private String value; AgeRange(String value){ this.value = value; } public String toString(){ return value; }

Iterate an Enumeration in Java 8

 ̄綄美尐妖づ 提交于 2019-12-02 16:04:21
Is it possible to iterate an Enumeration by using Lambda Expression? What will be the Lambda representation of the following code snippet: Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); while (nets.hasMoreElements()) { NetworkInterface networkInterface = nets.nextElement(); } I didn't find any stream within it. In case you don’t like the fact that Collections.list(Enumeration) copies the entire contents into a (temporary) list before the iteration starts, you can help yourself out with a simple utility method: public static <T> void forEachRemaining(Enumeration<T