enumeration

Ruby: How do you set an Enumerator's state?

别说谁变了你拦得住时间么 提交于 2019-12-22 12:37:21
问题 I'm doing a base 64 permutation incrementor. I've already written all the working code. But seeing as how Ruby already as Array::permutation which produces an Enumerator; I'd like to use that and take it a step further. Without having to go through every permutation by using 'next', can I set the start point? x = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + ['+','/'] y = x.permutation(12) y.peek.join => "ABCDEFGHIJKL" y.next y.peek.join => "ABCDEFGHIJKM" . # DO SOMETHING LIKE THIS y

Is it possible to use reflection to find the actual type of a field declared to be a Scala Enumeration subtype?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 08:54:32
问题 I want to automatically convert/coerce strings into Scala Enumeration Values, but without knowing beforehand what Enumeration subclass (subobject?) the declaration is from. So, given: object MyEnumeration extends Enumeration { type MyEnumeration = Value val FirstValue, SecondValue = Value } and class MyThing { import MyEnumeration._ var whichOne: MyEnumeration = FirstValue } how would I implement the following? val myThing = new MyThing() setByReflection(myThing, "whichOne", "SecondValue")

Is there a way to iterate through HttpServletRequest.getAttributeNames() more than once?

拈花ヽ惹草 提交于 2019-12-22 05:41:49
问题 I'm trying to log the contents of the HttpServletRequest attributes collection. I need to do this when the servlet first starts, and again right before the servlet is finished. I'm doing this in an attempt to understand a crufty and ill-maintained servlet. Because I need to have as little impact as possible, servlet filters are not an option. So here's the problem. When the servlet starts, I'll iterate through the enumeration returned by HttpServletRequest.getAttributeNames(). However, when I

What is the enumerable argument for in Object.create?

泄露秘密 提交于 2019-12-22 05:17:27
问题 In what usages of Object.create do you want to set enumerable to true ? 回答1: A property of an object should be enumerable if you want to be able to have access to it when you iterate through all the objects properties. Example: var obj = {prop1: 'val1', prop2:'val2'}; for (var prop in obj){ console.log(prop, obj[prop]); } In this type of instantiation, enumerable is always true, this will give you an output of: prop1 val1 prop2 val2 If you would have used Object.create() like so: obj = Object

C - forward declaration of enums?

你。 提交于 2019-12-22 02:01:23
问题 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 回答1: 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

Finding Strings Neighbors By Up To 2 Differing Positions

帅比萌擦擦* 提交于 2019-12-21 20:00:14
问题 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

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

谁说我不能喝 提交于 2019-12-21 13:06:29
问题 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

Discovering the class where a property is first published with multiple levels of inheritance

扶醉桌前 提交于 2019-12-21 12:20:13
问题 Using the Typinfo unit, it is easy to enumerate properties as seen in the following snippet: procedure TYRPropertiesMap.InitFrom(AClass: TClass; InheritLevel: Integer = 0); var propInfo: PPropInfo; propCount: Integer; propList: PPropList; propType: PPTypeInfo; pm: TYRPropertyMap; classInfo: TClassInfo; ix: Integer; begin ClearMap; propCount := GetPropList(PTypeInfo(AClass.ClassInfo), propList); for ix := 0 to propCount - 1 do begin propInfo := propList^[ix]; propType := propInfo^.PropType; if

Java Enumerating list in mockito's thenReturn

爱⌒轻易说出口 提交于 2019-12-21 09:37:03
问题 Is there a way to enumerate the items in a list within mockito's thenReturn function so I return each item in a list. So far I've done this: List<Foo> returns = new ArrayList<Foo>(); //populate returns list Mockito.when( /* some function is called */ ).thenReturn(returns.get(0), returns.get(1), returns.get(2), returns.get(3)); This works exactly how I want it to. Each time the function is called, it returns a different object from the list, e.g get(1) , get(2) etc. But I want to simplify this

How to convert Enumeration to Seq/List in scala?

别说谁变了你拦得住时间么 提交于 2019-12-21 07:07:34
问题 I'm writing a servlet, and need to get all parameters from the request. I found request.getParameterNames returns a java.util.Enumeration , so I have to write code as: val names = request.getParameterNames while(names.hasMoreElements) { val name = names.nextElement } I wanna know is there any way to convert a Enumeration to a Seq/List , then I can use the map method? 回答1: You can build it yourself like this val nameIterator = Iterator.continually((names, names.nextElement)).takeWhile(_._1