Freemarker - access value at a particular key in map - java

I have Map variable in my Freemarker template. How can I fetch a value at a particular key in the map, as we do in Java (map.get(<key>)).
I know how to iterate through keys and values of a map in a FTL. But I want a solution without iteration, on the lines of Java get() method of Map interface.

map[dynamicKey] or map.staticKey if the key is a string. Due to historical limitations, if the key isn't a string, map?api.get(nonStringKey).

Related

Will rocksDB support nested keys for one value?

I am new to RocksDB. I am testing it on java spring boot(dependency: org.rocksdb.rocksdbjni). Will it support on storing nested keys for one value and retrieve a value using nested keys.
Example:
In Java, I am using the following data structure. Map<Type1, Map<Type2, Type3>>().
Will it workout in rocksDB implementation?. Here 'Type1' is the outer key, 'Type2' is the inner key and 'Type3' is the value for the respective keys.
RocksDB does not support Map within a Map, you could look at other databases that are built over RocksDB.
Though One way you could represent Map within a Map is to use to keys with the following form:
"type1/type2/type3": value

Storing java entities in hashmap for faster retrieval

I have an object so that
class MyObj{
public long id_1;
...
}
My HBM (hibernate mapping file) tells that this id_1 is my Id. Now what i want to do is to cache this entity in HashMap so that HashMap<MyObj, NestObj> i.e., MyObj will become the key for the hashMap.
Now the question that I wanted to ask
I want to make sure that even though i have saved the whole object as the key, I want to keep object retrieval/storing in the hashmap based on the MyObj.id_1 value. The easiest way i can do so is to after retrieving all objects, I have to do a for loop to add them in a map as Map <Integer, MyObj> but in that case i would have maintain two maps (one for MyObj and other for NestedObj) which i want to avoid.
How can i dictate my HashMap to use MyObj.id_1 column to use as comparator, hash etc. Shall i override hash and equal function ? But if i do so, would it affect hibnerate comparison while storing/retrieving entities ?

Map collection separate Object values

I have a Map collection that stores "stops" as Key and a set of grid and time results as an Object value. e.g.
Key: [stops]
Value: [[{grid_item=Grid1, time=09:30}, {grid_item=Grid13, time=10:00}, {grid_item=Grid3, time=10:15}, {grid_item=Grid10, time=10:35}]]
Is there a way to separate the Value results, because i would like to use the grid_item and time to send them to another method. How can i get those values specifically?
Or should i store again the values in a Map but now the keys are grid_item and time. But how can i do that?
Any Suggestions?
You can access a specific object in your value's array this way:
map.get(stops)[0] // grid_item=Grid1, time=09:30
map.get(stops)[1] // grid_item=Grid13, time=10:00
....
where stops is the key that you are using.

JAVA - eclipse debug remove/change a key in map

I have a situation where I need to change(remove will also work) value corresponding to a key in a Map.
There are so many pairs in map. I don't want to copy all and create new map in change value for Map.
Is there any way I can directly change/remove value corresponding to a key.
I have tried changing complete map like :
Map m = commandParameters;
m.put("AID","");
return m;
But commandParameters is not resolved.
I tried changing that particular entry using random expressions, but could not work out.
Is there any way to do so?
**EDIT : ** commandParameters is original map.
Just do a remove on the map for a specific key.
commandParameters.remove("AID");
commandParameters.put("AID", "newvalue");
return commandParameters;

How to access a hashmap in XSLT

I have some java code which returns me a map, and I want to access this in XSLT.
I just saved the result in some variable called $map.
Tried accessing the value as key($map,'key1') with no luck.
where $map is what some java method returned and key1 is the key of one map entry.
I want to fetch its value.
Any suggestions ?

Categories

Resources