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

The following examples show how to use java.util.Collections#synchronizedSortedMap() . 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
Source File: SynchronizedSortedMapUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@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 2
Source File: BondEnergies.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 3
Source File: MCSPlusMapper.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 4
Source File: OldCollectionsTest.java    From j2objc with 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
Source File: ChemicalFilters.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 File: SaasGroup.java    From netbeans with 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
Source File: java_util_Collections_SynchronizedSortedMap.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 8
Source File: SynchronizedCollectionsSerializer.java    From Iron with Apache License 2.0 4 votes vote down vote up
@Override
public Object create(final Object sourceCollection) {
    return Collections.synchronizedSortedMap((SortedMap<?, ?>) sourceCollection);
}
 
Example 9
Source File: java_util_Collections_SynchronizedSortedMap.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.synchronizedSortedMap(map);
}
 
Example 10
Source File: TellstickBinding.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
public TellstickBinding() {
    messageQue = Collections.synchronizedSortedMap(new TreeMap<TellstickDevice, TellstickSendEvent>());
    controller = new TellstickController(messageQue);
    controllerThread = new Thread(controller);
}
 
Example 11
Source File: java_util_Collections_SynchronizedSortedMap.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 12
Source File: java_util_Collections_SynchronizedSortedMap.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 13
Source File: java_util_Collections_SynchronizedSortedMap.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.synchronizedSortedMap(map);
}
 
Example 14
Source File: java_util_Collections_SynchronizedSortedMap.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 15
Source File: java_util_Collections_SynchronizedSortedMap.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.synchronizedSortedMap(map);
}
 
Example 16
Source File: java_util_Collections_SynchronizedSortedMap.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.synchronizedSortedMap(map);
}
 
Example 17
Source File: java_util_Collections_SynchronizedSortedMap.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 18
Source File: java_util_Collections_SynchronizedSortedMap.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.synchronizedSortedMap(map);
}
 
Example 19
Source File: java_util_Collections_SynchronizedSortedMap.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.synchronizedSortedMap(map);
}
 
Example 20
Source File: MapUtils.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}