enumeration

iterating through Enumeration of hastable keys throws NoSuchElementException error

天大地大妈咪最大 提交于 2019-12-03 09:17:35
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 POSTCODE Exception in thread "main" java.util.NoSuchElementException: Hashtable Enumerator at java.util

Scala Best Practices: Trait Inheritance vs Enumeration

ⅰ亾dé卋堺 提交于 2019-12-03 08:22:03
问题 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

enum implementation inside interface - Java

╄→尐↘猪︶ㄣ 提交于 2019-12-03 08:14:52
问题 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

Enumerate through a subset of a Collection in C#?

眉间皱痕 提交于 2019-12-03 07:00:27
Is there a good way to enumerate through only a subset of a Collection in C#? That is, I have a collection of a large number of objects (say, 1000), but I'd like to enumerate through only elements 250 - 340. Is there a good way to get an Enumerator for a subset of the collection, without using another Collection? Edit: should have mentioned that this is using .NET Framework 2.0. Try the following var col = GetTheCollection(); var subset = col.Skip(250).Take(90); Or more generally public static IEnumerable<T> GetRange(this IEnumerable<T> source, int start, int end) { // Error checking removed

working pattern of yield return

 ̄綄美尐妖づ 提交于 2019-12-03 06:47:44
When i have a code block static void Main() { foreach (int i in YieldDemo.SupplyIntegers()) { Console.WriteLine("{0} is consumed by foreach iteration", i); } } class YieldDemo { public static IEnumerable<int> SupplyIntegers() { yield return 1; yield return 2; yield return 3; } } can i interpret the principle behind yield return as Main() calls the SupplyIntegers() |1| |2| |3| are stored in contiguous memory block.Pointer of "IEnumerator" Moves to |1| Control returns from SupplyInteger() to Main(). Main() prints the value Pointer Moves to |2|, and so on. Clarifications : (1) Normally we will

How to handle an “infinite” IEnumerable?

二次信任 提交于 2019-12-03 05:38:37
问题 A trivial example of an "infinite" IEnumerable would be IEnumerable<int> Numbers() { int i=0; while(true) { yield return unchecked(i++); } } I know, that foreach(int i in Numbers().Take(10)) { Console.WriteLine(i); } and var q = Numbers(); foreach(int i in q.Take(10)) { Console.WriteLine(i); } both work fine (and print out the number 0-9). But are there any pitfalls when copying or handling expressions like q ? Can I rely on the fact, that they are always evaluated "lazy"? Is there any danger

Which Hierarchical model should I use? Adjacency, Nested, or Enumerated?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 05:19:19
问题 I have a table which contains a location of all geographical locations in the world and their relationships. Here is a example that shows the hierarchy. You will see that the data is actually stored as all three Enumerated Path Adjacency list Nested Set The data obviously never changes either. Below is an example of direct ancestors of the location Brighton in England which has a woeid of 13911. Table: geoplanet_places (Has 5.6million rows) Large Image: http://tinyurl.com/68q4ndx I then have

Enumerate NSDictionary with keys and objects, PHP style

落爺英雄遲暮 提交于 2019-12-03 05:18:05
I know you can Enumerate the keys or values of NSMutableDictionary using NSEnumerator . Is it possible to do both together? I'm looking for something similar to the PHP foreach enumerator like: foreach ($dictionary as $key => $value); Perhaps look into NSDictionary's method: enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop)) If you're not familiar with blocks in C/Objective-C, this is a good tutorial: http://thirdcog.eu/pwcblocks/ NSDictionary* d = [NSDictionary dictionaryWithObjectsAndKeys:@"obj1",@"key1", @"obj2",@"key2", @"obj3",@"key3", @"obj4",@"key4",nil]; for (id

Singular or plural for enumerations?

不想你离开。 提交于 2019-12-03 04:00:42
问题 Do you use singular or plural for enumerations? I think it makes best sense with plural in the declaration enum Weekdays { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } ... but I think it makes more sense with singular when using the type, e.g. Weekday firstDayOfWeek = Weekday.Monday; I read a recommendation somewhere to use singular whith regular enums and plural with flags, but I would like to hear some more pros and cons. 回答1: Here it is straight from Microsoft: http:/

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

我们两清 提交于 2019-12-03 03:45:16
问题 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! 回答1: The best and simplest way to do it is like this: public enum AgeRange { A18TO23 ("18-23"), A24TO29 ("24-29"), A30TO35("30-35"); private