Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

I had a Java array of Strings. I needed to be able to quickly locate each item, so I fed it into a LinkedHashSet.

                Map<String, Boolean> newTableNames = new LinkedHashMap<>(pokerTableNames.length);
                for (String pokerTableName : pokerTableNames) {
                    newTableNames.put(pokerTableName, false);
                }

Later in the code, I needed to grab an item out of the list. My first cut was involved a for-loop. I got the first KeyValueSet, then called remove witht the value.

An easier way seems to be…

String candidateTableName  = newTableNames.entrySet().iterator().next().getKey();

February 27th, 2015

Posted In: Java, java ninja, Javaninja

Tags: , ,

Leave a Comment

I needed to iterate over the values contained in a replicatedMap. I thought it would be as simple as:

hz.<Long, GameInfo>replicatedMap(DO.DESK_MAP, DO.DESK_MAP).values();

It would show that there were 2006 entries, but I couldn’t touch them.

I later stumbled upon the following:

hz.mapValues(DO.DESK_MAP);

This gave me a Collection of the values that I could iterate over.

February 26th, 2015

Posted In: Hazelcast, Java, java ninja, Javaninja

Tags: , , , ,

2 Comments

LinkedIn Auto Publish Powered By : XYZScripts.com