How to create hashMap that has a list of hashmap in kotlin? - kotlin

What I am trying to achieve is is a map that has a list of maps in which the first key is ID and value obviously is a map of which the key is Session and the value is an OBJECT.
var newSession = ConcurrentHashMap<String, ConcurrentHashMap<WebSocketSession, String>>()
What if I want to save multiple session maps with the same ID? Whenever I pass an ID I want to get a map from which I should be able to search a particular session?
Sorry for not being so clear, but I am stuck here for a while and am kinda newbie in Kotlin!
Thanks in advance!

Related

How do you edit all values in a map without knowing the keys?

(context)
I'm doing more Minecraft spigot things, and my plugin idea is that enchantments strengthen over time, exponentially. I have a timer that is in the onEnable thing that runs a function every 2 1/2 minutes.
The function currently does:
Get a list of players,
Get inventory of those players,
Get all items of those inventories,
Get the enchantment maps for each of the items.
The problem is, I don't know every enchantment's code name(plus it would be very tedious to list every single one out), therefore I can't test every key(enchant name) to get the values(the enchantment strength). I want to just edit all of the values and set them to ceil(lvl1.2)* so I can get the strengthened enchantments to apply to the items, then apply those items to those inventories, then inventories to players.
TL;DR
How to you edit every value of a map given that you don't know the keys?
You can use Map's entrySet() method to iterate through each enchantment/level.
for (Map.Entry<Enchantment, Integer> entry : enchantmentMap.entrySet()) {
Enchantment enchantment = entry.getKey();
int level = entry.getValue();
}

Android QuickBlox - CustomObject Push to Array Field

Hi I'm using CustomObject to bulid friends list but I'm facing below problem.
When I try to push a number to an array field it returns null value and the field is not updated but if I add it as a normal field (not pushing to array) it works fine.
Below is my code:
QBCustomObject friendsList = new QBCustomObject();
friendsList.setClassName("Friends");
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put("push[friendsId][]", "00001111");
friendsList.setFields(fields);
and logcat shows below api request:
https://api.quickblox.com/data/Friends.json?push[friendsId][]=00001111
but if I use below code it works but not append to array. It adds new record:
fields.put("friendsId", "00001111");
friendsList.setFields(fields);
Is there anything wrong with my way?
To update your record, your URL should look like
https://api.quickblox.com/data/Friends/id.json?push[friendsId][]= 00001111,
where id is a record id.
For example,
https://api.quickblox.com/data/Friends/111c0ec5535c12669c000721.json?push[friendsId][]= 00001111
Did my answer helped you ?
You can rewrite the whole record. Don't try to add an object separately into an array, update the whole record.

Neo4j/Lucene - How to create a unique index?

I'm using Neo4j, and I wonder if it is possible to create a lucene index with a unique field. (that is, every key/value pair can be associated with only one node)
For example, i want to achieve the following behavior:
someIndex.add(node1, "firstName", "Roy");
someIndex.add(node2, "firstName", "John");
// Here I expect to recieve an exception because the key/value pair (firstName, Roy) is already associated with node1
someIndex.add(node3, "firstName", "Roy");
Is it possible to achieve something like that?
Thanks!
On Java API level you can use UniqueFactory. For usage example, check out http://docs.neo4j.org/chunked/stable/transactions-unique-nodes.html.
In my code I'm using the BatchInserterIndex and add a map of key and values I need to be indexed..
The code is something like this:
BatchInserterIndex myIndex = indexProvider.nodeIndex("myIndex", MapUtil.stringMap("type", "exact"));
Map<String, Object> key_Value_IndexMap = new ConcurrentHashMap<String, Object>();
key_Value_IndexMap.put("ID", value);
myIndex.add(createdNodeId, key_Value_IndexMap);

Native Query Mapping on the fly openJPA

I am wondering if it is possible to map a named native query on the fly instead of getting back a list of Object[] and then looping through and setting up the object that way. I have a call which I know ill return a massive data set and I want to be able to map it right to my entity. Can I do that or will I have to continue looping through the result set.
Here is what I am doing now...
List<Provider> ObjList = (List<Provider>) emf.createNativeQuery(assembleQuery(organizationIDs, 5)).getResultList();
That is my entity, the List (my entity is the provider). Normally I would just return a List<Object[]>
and then I would loop through that to get back all the objects and set them up as new providers and add them to a list....
//List<Provider> provList = new ArrayList<Provider>();
/*for(Object[] obj: ObjList)
{
provList.add(this.GetProviderFromObj(obj));
}*/
As you can see I commented that section of the code out to try this out. I know you can map named native queries if you put your native query in the entity itself and then call it via createNamedQuery. I would do it that way, but I need to use the IN oracle keyword because I have a list of ID's that I want to check against. It is not just one that is needed. And as we all know, native queruies don't handle the in keyword to well. Any advice?
Sigh, If only the IN keyword was supported well for NamedNativeQueries.
Assuming that Provider is configured as a JPA entity, you should be able to specify the class as the second parameter to your createNativeQuery call. For example:
List<Provider> ObjList = (List<Provider>) emf.createNativeQuery(assembleQuery(organizationIDs, 5), Provider.class).getResultList();
According to the documentation, "At a minimum, your SQL must select the class' primary key columns, discriminator column (if mapped), and version column (also if mapped)."
See the OpenJPA documentation for more details.

Data structure to use in Sencha Touch similar to Vector in Blackberry

I am a beginner to sencha Touch, basically i am a blackberry developer. Currently we are migrating our application to support Sencha Touch 1.1. Now i have some business solutions like i want to store the selected values in the local database. I mean i have multiple screens where, Once the user selects a value in each of the screen the data should save in the below following format.
[{'key1': "value1", 'key2': "value2", 'key3': "value3" ,'key4': "value4", 'key5': "value5"}]
1. First, the values need to be saved in key value pairs
2. The keys should play the role of primary key, key shouldn't be duplicated.
3. Should be available till the application life cycle or application session, don't need to save the data permanently.
I have come across the concepts like LocalStorageProxy, JsonStore and some others. I don't understand which one i can use for my specific requirements.
May be my question is bit more confusing. I have achieved the same using vector, in Blackberry Java so any data structure similar to this could help me. Need the basic operations like
Create
Add
Remove
Remove all
Fetch elements based on key
Please suggest me some samples or some code snapshots, which may help me to achieve this.
Edit: 1
I have done the changes as per #Ilya139 's answer. Now I am able to add the data with key,
// this is my Object declared in App.js
NSDictionary: {},
// adding the data to object with key
MyApp.NSDictionary['PROD'] = 'SONY JUKE BOX';
//trying to retrieve the elements from vector
var prod = MyApp.NSDictionary['PROD'];
Nut not able to retrieve the elements using the above syntax.
If you don't need to save the data permanently then you can just have a global object with the properties you need. First define the object like this:
new Ext.Application({
name: 'MyApp',
vectorYouNeed: {},
launch: function () { ...
Then add the key-value pairs to the object like this
MyApp.vectorYouNeed[key] = value;
And fetch them like this
value = MyApp.vectorYouNeed[key];
Note that key is a string object i.e. var key='key1'; and value can be any type of object.
To remove one value MyApp.vectorYouNeed[key] = null; And to remove all of them MyApp.vectorYouNeed = {};