enumeration

Why aren't Enumerations Iterable?

被刻印的时光 ゝ 提交于 2019-11-27 23:24:30
In Java 5 and above you have the foreach loop, which works magically on anything that implements Iterable : for (Object o : list) { doStuff(o); } However, Enumerable still does not implement Iterable , meaning that to iterate over an Enumeration you must do the following: for(; e.hasMoreElements() ;) { doStuff(e.nextElement()); } Does anyone know if there is a reason why Enumeration still does not implement Iterable ? Edit: As a clarification, I'm not talking about the language concept of an enum , I'm talking a Java-specific class in the Java API called ' Enumeration '. Enumeration hasn't

Is the order in which handles are returned by EnumWindows meaningful?

时间秒杀一切 提交于 2019-11-27 20:58:57
问题 From a couple of preliminary tests it seems that EnumWindows always returns windows in reverse instantiation order, i.e. most recently instantiated window first. Is that a valid observation? If so, is it true across all versions of Windows? And is this a reliable assumption, i.e. is that behaviour documented somewhere? Context: I'm dealing with a situation where I am triggering a third-party application to open several non-modal windows and I need to send some window messages to those windows

case class copy 'method' with superclass

自闭症网瘾萝莉.ら 提交于 2019-11-27 19:43:24
I want to do something like this: sealed abstract class Base(val myparam:String) case class Foo(override val myparam:String) extends Base(myparam) case class Bar(override val myparam:String) extends Base(myparam) def getIt( a:Base ) = a.copy(myparam="changed") I can't, because in the context of getIt, I haven't told the compiler that every Base has a 'copy' method, but copy isn't really a method either so I don't think there's a trait or abstract method I can put in Base to make this work properly. Or, is there? If I try to define Base as abstract class Base{ def copy(myparam:String):Base } ,

Overriding Scala Enumeration Value

ぃ、小莉子 提交于 2019-11-27 19:01:20
As far as I can tell, Scala has definitions for the Enumeration Value class for Value(Int), Value(String), and Value(Int, String). Does anyone know of an example for creating a new Value subclass to support a different constructor? For example, If I want to create an Enumeration with Value(Int, String, String) objects, how would I do it? I would like all of the other benefits of using the Enumeration class. Thanks. Thomas Jung The Enumeration values are instance of the Val class. This class can be extended and a factory method can be added. object My extends Enumeration { val A = Value("name",

What are the differences between a Java enum and a class with private constructor? [duplicate]

被刻印的时光 ゝ 提交于 2019-11-27 17:19:54
This question already has an answer here: What's the advantage of a Java enum versus a class with public static final fields? 15 answers I was trying to understand how Java enum really works and I have come to the conclusion that it is very similar to a normal Java class that has its constructor declared private. I have just come to this conclusion and it isn't based on much thinking, but Id like to know whether I miss anything. So below is an implementation of a simple Java enum and an equivalent Java class. public enum Direction { ENUM_UP(0, -1), ENUM_DOWN(0, 1), ENUM_RIGHT(1, 0), ENUM_LEFT(

BitArray returns bits the wrong way around?

蹲街弑〆低调 提交于 2019-11-27 15:04:19
This code: BitArray bits = new BitArray(new byte[] { 7 }); foreach (bool bit in bits) { Console.WriteLine(bit ? 1 : 0); } Gives me the following output: 11100000 Shouldn't it be the other way around? Like this: 00000111 I am aware that there is little and big endian, although those terms only refer to the position of bytes. As far as I know, they don't affect bits. The documentation for BitArray states: The first byte in the array represents bits 0 through 7, the second byte represents bits 8 through 15, and so on. The Least Significant Bit of each byte represents the lowest index value: "

How to count the number of lines in an Objective-C string (NSString)?

Deadly 提交于 2019-11-27 13:46:03
问题 I want to count the lines in an NSString in Objective-C. NSInteger lineNum = 0; NSString *string = @"abcde\nfghijk\nlmnopq\nrstu"; NSInteger length = [string length]; NSRange range = NSMakeRange(0, length); while (range.location < length) { range = [string lineRangeForRange:NSMakeRange(range.location, 0)]; range.location = NSMaxRange(range); lineNum += 1; } Is there an easier way? 回答1: well, a not very efficient, but nice(ish) looking way is NSString *string = @"abcde\nfghijk\nlmnopq\nrstu";

How can I enumerate/list all installed applications in Windows XP?

人走茶凉 提交于 2019-11-27 12:31:39
When I say "installed application", I basically mean any application visible in [Control Panel]->[Add/Remove Programs]. I would prefer to do it in Python, but C or C++ is also fine. If you mean the list of installed applications that is shown in Add\Remove Programs in the control panel, you can find it in the registry key: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall more info about how the registry tree is structured can be found here . You need to use the winreg API in python to read the values from the registry. Check out the Win32_Product WMI (Windows Management

How to add a method to Enumeration in Scala?

半城伤御伤魂 提交于 2019-11-27 11:54:24
In Java you could: public enum Enum { ONE { public String method() { return "1"; } }, TWO { public String method() { return "2"; } }, THREE { public String method() { return "3"; } }; public abstract String method(); } How do you do this in Scala? EDIT / Useful links: https://github.com/rbricks/itemized http://pedrorijo.com/blog/scala-enums/ Sean Ross Here is an example of adding attributes to scala enums by extending the Enumeration.Val class. object Planet extends Enumeration { protected case class Val(val mass: Double, val radius: Double) extends super.Val { def surfaceGravity: Double =

How to get the name of enumeration value in Swift?

﹥>﹥吖頭↗ 提交于 2019-11-27 11:44:19
If I have an enumeration with raw Integer values: enum City: Int { case Melbourne = 1, Chelyabinsk, Bursa } let city = City.Melbourne How can I convert a city value to a string Melbourne ? Is this kind of a type name introspection available in the language? Something like (this code will not work): println("Your city is \(city.magicFunction)") > Your city is Melbourne Stuart As of Xcode 7 beta 5 (Swift version 2) you can now print type names and enum cases by default using print(_:) , or convert to String using String 's init(_:) initializer or string interpolation syntax. So for your example: