I have a Map&lt;String, Id&gt; and i want to sort them based on ENUM with sort order..   Map values: Apple, 1             Banana, 2             Grapes, 3             Coconut, 4             Mango, 5             Avocado, 6   my ENUM compose of   FruitName(sortOrder, id)   What is the best way to do the sorting?
1054
I am relatively new to Java, and often find that I need to sort a Map&lt;Key, Value&gt; on the values.  Since the values are not unique, I find myself converting the keySet into an array, and sorting that array through array sort with a custom comparator that sorts on the value associated with the key.  Is there an easier way?
69100
As an example take the following code:  public enum ExampleEnum { FooBar, BarFoo }  public class ExampleClass : INotifyPropertyChanged {     private ExampleEnum example;      public ExampleEnum ExampleProperty      { get { return example; } { /* set and notify */; } } }   I want a to databind the property ExampleProperty to a ComboBox, so that it shows the options "FooBar" and "BarFoo" and works in mode TwoWay. Optimally I want my ComboBox definition to look something like this:  &lt;ComboBox ItemsSource="What goes here?" SelectedItem="{Binding Path=ExampleProperty}" /&gt;   Currently I have handlers for the ComboBox.SelectionChanged and ExampleClass.PropertyChanged events installed in my Window where I do the binding manually.  Is there a better or some kind of canonical way? Would you usually use Converters and how would you populate the ComboBox with the right values? I don't even want to get started with i18n right now.  Edit  So one question was answered: How do I populate the ComboBox with the right values.  Retrieve Enum values as a list of strings via an ObjectDataProvider from the static Enum.GetValues method:  &lt;Window.Resources&gt;     &lt;ObjectDataProvider MethodName="GetValues"         ObjectType="{x:Type sys:Enum}"         x:Key="ExampleEnumValues"&gt;         &lt;ObjectDataProvider.MethodParameters&gt;             &lt;x:Type TypeName="ExampleEnum" /&gt;         &lt;/ObjectDataProvider.MethodParameters&gt;     &lt;/ObjectDataProvider&gt; &lt;/Window.Resources&gt;   This I can use as an ItemsSource for my ComboBox:  &lt;ComboBox ItemsSource="{Binding Source={StaticResource ExampleEnumValues}}"/&gt;
122810
can someone please explain to me how to count the number of topological sorts  for poset(A|) where A = {2,3,4,8,9,16,27,81} ? Quick example would be nice. Please help...I have an exam in several hours. Thanks !
11195
I found an example in the  for Dynamic LINQ that allows you to use a sql-like string (e.g. OrderBy("Name, Age DESC")) for ordering. Unfortunately, the method included only works on IQueryable&lt;T&gt;. Is there any way to get this functionality on IEnumerable&lt;T&gt;?
99253
I like how Java has a Map where you can define the types of each entry in the map, for example &lt;String, Integer&gt;.   What I'm looking for is a type of collection where each element in the collection is a pair of values.  Each value in the pair can have its own type (like the String and Integer example above), which is defined at declaration time.    The collection will maintain its given order and will not treat one of the values as a unique key (as in a map).    Essentially I want to be able to define an ARRAY of type &lt;String,Integer&gt; or any other 2 types.    I realize that I can make a class with nothing but the 2 variables in it, but that seems overly verbose.    I also realize that I could use a 2D array, but because of the different types I need to use, I'd have to make them arrays of OBJECT, and then I'd have to cast all the time.    I only need to store pairs in the collection, so I only need two values per entry.  Does something like this exist without going the class route?  Thanks!
85212
Is there an ordered (by insertion) map in bash?  I know there's an  data structure in bash, but when iterating over it, the order of the elements is not by insertion. Example below.  I'd like to keep the map ordered by insertion.  Associative array not preserving insertion order:  declare -A REPLACE_MAP REPLACE_MAP['b']='2' REPLACE_MAP['a']='1' for key in "${!REPLACE_MAP[@]}"; do     echo "$key - ${REPLACE_MAP["$key"]}"     value=${REPLACE_MAP["$key"]} done   Result:  a - 1 b - 2   I'd like a data structure that will yield the following result:  b - 2 a - 1
53255
In my spring application context file, I have something like:  &lt;util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.lang.String"&gt;     &lt;entry key="some_key" value="some value" /&gt;     &lt;entry key="some_key_2" value="some value" /&gt;    &lt;/util:map&gt;   In java class, the implementation looks like:  private Map&lt;String, String&gt; someMap = new HashMap&lt;String, String&gt;(); someMap = (HashMap&lt;String, String&gt;)getApplicationContext().getBean("someMap");   In Eclipse, I see a warning that says:  Type safety: Unchecked cast from Object to HashMap  What did I do wrong? How do I resolve the issue?
83783
$ sort -t $'\t' -k 1rn,1 -k 2,2rn -k 3f,4 listaprezzi  2050        900           bananas     5 1905        700           grapes      17 250         4000          oranges     10 230         9200          figs        4 220         5000          lemons      10 200         8000          pears       8   I want to sort 1st column of listaprezzi numerically in reverse (option rn), 2nd also rn, and third alphabetically (f). What is the correct command?  I've tried many ways but having no success.
82429
Why can't enum's constructor access static fields and methods? This is perfectly valid with a class, but is not allowed with an enum.  What I'm trying to do is store my enum instances in a static Map. Consider this example code which allows lookup by abbreivation:  public enum Day {     Sunday("Sun"), Monday("Mon"), Tuesday("Tue"), Wednesday("Wed"), Thursday("Thu"), Friday("Fri"), Saturday("Sat");      private final String abbreviation;      private static final Map&lt;String, Day&gt; ABBREV_MAP = new HashMap&lt;String, Day&gt;();      private Day(String abbreviation) {         this.abbreviation = abbreviation;         ABBREV_MAP.put(abbreviation, this);  // Not valid     }      public String getAbbreviation() {         return abbreviation;     }      public static Day getByAbbreviation(String abbreviation) {         return ABBREV_MAP.get(abbreviation);     } }   This will not work as enum doesn't allow static references in its constructor. It however works just find if implemented as a class:  public static final Day SUNDAY = new Day("Sunday", "Sun"); private Day(String name, String abbreviation) {     this.name = name;     this.abbreviation = abbreviation;     ABBREV_MAP.put(abbreviation, this);  // Valid }
220
I know that PHP doesn't yet have native Enumerations. But I have become accustomed to them from the Java world. I would love to use enums as a way to give predefined values which IDEs' auto-completion features could understand. Constants do the trick, but there's the namespace collision problem and (or actually because) they're global. Arrays don't have the namespace problem, but they're too vague, they can be overwritten at runtime and IDEs rarely know how to autofill their keys without additional static analysis annotations or attributes. Are there any solutions/workarounds you commonly use? Does anyone recall whether the PHP guys have had any thoughts or decisions around enumerations?
71802
Is there a good way to have a Map&lt;String, ?&gt; get and put ignoring case?
21008
I was wondering in C++ if I have an enum can I access the value at the second index?  For example I have  enum Test{hi, bye};   if I want 'hi', can I do something like Test[0], thanks.
28573
I want to make an enumerated list in the following format:  [1] foo foo [2] foo foo ...    How I can do that using enumerated lists? I have tried the following:  \begin{enumerate}[\left[ 1 \right]]   but it does not work.
118496
I want to sort a list of objects of a class by 2 ways. I am able to do custom sort by overwriting the compareTo method.  But I have two lists and I want to sort them differently.  Can I still accomplish this by calling the list.sort() method?  global class myClass implements Comparable{      public integer Total{get;set;}     public integer numOfDays{get;set;}      global Integer compareTo(Object compareTo) {         myClass compareToEmp = (myClass)compareTo;         if (Total == myClass.Total) return 0;         if (Total &gt; myClass.Total) return 1;         return -1;             } }   In the above example, how can I also be able to sort by "numOfDays"?  //UPDATE:  I actually wanted to sort list by single property.   But use different properties to sort different lists.  I ended up adding a new field to my class for sorting purpose.  global class myClass implements Comparable{      public integer Total{get;set;}     public integer numOfDays{get;set;}     public boolean isA {get;set;}      global Integer compareTo(Object compareTo) {         myClass compareToEmp = (myClass)compareTo;         if(isA){          if (Total == myClass.Total) return 0;         if (Total &gt; myClass.Total) return 1;             return -1; }         else{              if (Total == myClass.numOfDays) return 0;         if (Total &gt; myClass.numOfDays) return 1;             return -1;          }            } }
112859
Is there a better way to do this?  string[] s = {"zero", "one", "two", "three", "four", "five"};  var x =  s .Select((a,i) =&gt; new {Value = a, Index = i}) .Where(b =&gt; b.Value.StartsWith("t")) .Select(c =&gt; c.Index);   i.e. I'm looking for a more efficient or more elegant way to get the positions of the items matching the criteria.
118273
I'm trying to parse json response.. but keep getting this error      Invalid conversion from runtime type List ANY> to Map String,ANY>   Map&lt;String, Object&gt; MapLv3 = new Map&lt;String, Object&gt;();      Integer x2 = 0; for (Object oh : CallsList){     MapLv3.put(String.valueof(x2), oh);     x2++; } index = x2; System.debug('Map Lv 3 ==&gt;'+MapLv3);  Map&lt;String, Map &lt;String, Object&gt;&gt; Map3 = new Map&lt;String, Map &lt;String, Object&gt;&gt;(); for (Integer a2 = 0; a2 &lt; index; a2++){     Map3.put(String.valueof(a2),(Map&lt;String,Object&gt;) MapLv3.get(String.valueof(a2))); } System.debug('Segment ==&gt;'+Map3.get('0').get('segments'));
89955
If I have the following enum:  public enum ReturnValue{     Success = 0,     FailReason1 = 1,     FailReason2 = 2     //Etc... }   Can I avoid casting when I return, like this:  public static int main(string[] args){     return (int)ReturnValue.Success; }   If not, why isn't an enum value treated as an int by default?