Java Code Examples for java.util.Collections#synchronizedSortedMap()

The following examples show how to use java.util.Collections#synchronizedSortedMap() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private synchronized void setAllMapping(List<Map<Integer, Integer>> solutions) {
        try {
            int counter = 0;
            int bestSolSize = 0;
            for (Map<Integer, Integer> solution : solutions) {
//                System.out.println("Number of MCS solution: " + solution);
                Map<Integer, Integer> validSolution = Collections.synchronizedSortedMap(new TreeMap<>());

                solution.entrySet().stream().forEach((map) -> {
                    validSolution.put(map.getKey(), map.getValue());
                });

                if (validSolution.size() > bestSolSize) {
                    bestSolSize = validSolution.size();
                    counter = 0;
                    allMCS.clear();
                }
                if (validSolution.size() == bestSolSize) {
                    allMCS.add(counter++, validSolution);
                }
            }

        } catch (Exception ex) {
        }
    }
 
Example 2
@Test
public void givenSynchronizedSorteMap_whenTwoThreadsAddElements_thenCorrectSortedMapSize() throws InterruptedException {
    Map<Integer, String> syncSortedMap = Collections.synchronizedSortedMap(new TreeMap<>());
    
    Runnable sortedMapOperations = () -> {
        syncSortedMap.put(1, "One");
        syncSortedMap.put(2, "Two");
        syncSortedMap.put(3, "Three");
    };
    Thread thread1 = new Thread(sortedMapOperations);
    Thread thread2 = new Thread(sortedMapOperations);
    thread1.start();
    thread2.start();
    thread1.join();
    thread2.join();
    
    assertThat(syncSortedMap.size()).isEqualTo(3);
}
 
Example 3
protected BondEnergies() {

        int key = 1;
        bondEngergies = Collections.synchronizedSortedMap(new TreeMap<Integer, BondEnergy>());

//      =========Hydrogen Block==============
        key = setHydrogenBlock(key);
//       ==================Group 13=================
        key = setGroup13(key);
//      ===================Group 14 Part 1=================
        key = setGroup14Part1(key);
//      ===================Group 14 Part 2=================
        key = setGroup14Part2(key);
//      ===================Group 15=================
        key = setGroup15(key);
//      ===================Group 16=================
        key = setGroup16(key);
//      ===================Group 17=================
        key = setGroup17(key);
//      ===================Group 18=================
        key = setGroup18(key);
    }
 
Example 4
Source Project: j2objc   File: OldCollectionsTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * java.util.Collections#synchronizedSortedMap(java.util.SortedMap)
 */
public void test_synchronizedSortedMapLjava_util_SortedMap() {
    try {
        // Regression for HARMONY-93
        Collections.synchronizedSortedMap(null);
        fail("Assert 0: synchronizedSortedMap(null) must throw NPE");
    } catch (NullPointerException e) {
        // expected
    }
}
 
Example 5
/**
 * Sort MCS solution by bond breaking energy.
 *
 * @throws CDKException
 */
public synchronized void sortResultsByEnergies() throws CDKException {
    Map<Integer, AtomAtomMapping> allEnergyAtomMCS = Collections.synchronizedSortedMap(new TreeMap<>());
    Map<Integer, Double> stereoScoreMap = Collections.synchronizedSortedMap(new TreeMap<>());
    Map<Integer, Integer> fragmentScoreMap = Collections.synchronizedSortedMap(new TreeMap<>());
    Map<Integer, Double> energySelectionMap = Collections.synchronizedSortedMap(new TreeMap<>());

    initializeMaps(allEnergyAtomMCS, stereoScoreMap, fragmentScoreMap, energySelectionMap);
    double lowestEnergyScore = energyFilter.sortResults(allEnergyAtomMCS, energySelectionMap);
    clear();

    int counter = 0;
    for (Map.Entry<Integer, Double> map : energySelectionMap.entrySet()) {
        if (lowestEnergyScore == map.getValue()) {
            addSolution(counter, map.getKey(),
                    allEnergyAtomMCS,
                    stereoScoreMap,
                    energySelectionMap,
                    fragmentScoreMap);
            counter++;
        }
    }

    if (lowestEnergyScore != EnergyFilter.MAX_ENERGY) {
        clear(allEnergyAtomMCS, stereoScoreMap, fragmentScoreMap, energySelectionMap);
    }
}
 
Example 6
Source Project: netbeans   File: SaasGroup.java    License: Apache License 2.0 5 votes vote down vote up
public List<SaasGroup> getChildrenGroups() {
    if (children == null) {
        children = Collections.synchronizedSortedMap(new TreeMap<String,SaasGroup>());
        for (Group g : delegate.getGroup()) {
            SaasGroup sg = new SaasGroup(this, g);
            children.put(sg.getName(), sg);
        }
    }
    return new ArrayList<SaasGroup>(children.values());
}
 
Example 7
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.synchronizedSortedMap(map);
}
 
Example 8
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 9
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 10
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.synchronizedSortedMap(map);
}
 
Example 11
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 12
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.synchronizedSortedMap(map);
}
 
Example 13
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 14
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.synchronizedSortedMap(map);
}
 
Example 15
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 16
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 17
public TellstickBinding() {
    messageQue = Collections.synchronizedSortedMap(new TreeMap<TellstickDevice, TellstickSendEvent>());
    controller = new TellstickController(messageQue);
    controllerThread = new Thread(controller);
}
 
Example 18
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.synchronizedSortedMap(map);
}
 
Example 19
@Override
public Object create(final Object sourceCollection) {
    return Collections.synchronizedSortedMap((SortedMap<?, ?>) sourceCollection);
}
 
Example 20
/**
 * Returns a synchronized sorted map backed by the given sorted map.
 * <p>
 * You must manually synchronize on the returned buffer's iterator to 
 * avoid non-deterministic behavior:
 *  
 * <pre>
 * Map m = MapUtils.synchronizedSortedMap(myMap);
 * Set s = m.keySet();  // outside synchronized block
 * synchronized (m) {  // synchronized on MAP!
 *     Iterator i = s.iterator();
 *     while (i.hasNext()) {
 *         process (i.next());
 *     }
 * }
 * </pre>
 * 
 * This method uses the implementation in {@link java.util.Collections Collections}.
 * 
 * @param map  the map to synchronize, must not be null
 * @return a synchronized map backed by the given map
 * @throws IllegalArgumentException  if the map is null
 */
public static Map synchronizedSortedMap(SortedMap map) {
    return Collections.synchronizedSortedMap(map);
}