0

Sorry, new to java, actally coding in jython but I would think java syntax should work.

I have a hashmap that looks like this:

Hashmap = {21035179={WEIGHT=1}, 2300={WEIGHT=0}, 21035180={EMA_FIRST=1000.11615393169158, EMA_SECOND=966.8684105279658}}

The values are of an enum type, not sure how that changes things cause I'm not that familiar with that type.

I want to get the weight of 2300, I would think the syntax for this is:

Count = 2300
Hashmap.get(Count).get(enum.WEIGHT) 

but this doesn't work, I get a None type back.

What am I doing wrong here?

WhitneyChia
  • 746
  • 2
  • 11
  • 28

1 Answers1

0

Answering for java, your structure seems to be Integer -> enum -> double. This would be represented in Java as:

public enum Field {
    WEIGHT, EMA_FIRST, EMA_SECOND;
}
Map<Integer, Map<Field, Double>> myMap

Because you are using an enum as the key, you should create the values as EnumMap:

myMap.put(2300, new EnumMap(Field.class));
myMap.get(2300).put(Field.WEIGHT, 34.7);

Getting the weight for 2300 would then be myMap.get(2300).get(Field.WEIGHT).

sprinter
  • 27,148
  • 6
  • 47
  • 78