java.util.Collections.synchronizedSortedMap()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(253)

本文整理了Java中java.util.Collections.synchronizedSortedMap()方法的一些代码示例,展示了Collections.synchronizedSortedMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.synchronizedSortedMap()方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:synchronizedSortedMap

Collections.synchronizedSortedMap介绍

[英]Returns a wrapper on the specified sorted map which synchronizes all access to the sorted map.
[中]返回指定排序映射上的包装器,该包装器同步对排序映射的所有访问。

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy

/**
 * A convenience method for creating a synchronized SortedMap.
 *
 * @param self a SortedMap
 * @return a synchronized SortedMap
 * @see java.util.Collections#synchronizedSortedMap(java.util.SortedMap)
 * @since 1.0
 */
public static <K,V> SortedMap<K,V> asSynchronized(SortedMap<K,V> self) {
  return Collections.synchronizedSortedMap(self);
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * 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);
}

代码示例来源:origin: wildfly/wildfly

/**
 * 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);
}

代码示例来源:origin: org.apache.commons/commons-collections4

/**
 * 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 <K>  the key type
 * @param <V>  the value type
 * @param map  the map to synchronize, must not be null
 * @return a synchronized map backed by the given map
 * @throws NullPointerException  if the map is null
 */
public static <K, V> SortedMap<K, V> synchronizedSortedMap(final SortedMap<K, V> map) {
  return Collections.synchronizedSortedMap(map);
}

代码示例来源:origin: wildfly/wildfly

classes.add(Collections.synchronizedNavigableSet(Collections.emptyNavigableSet()).getClass());
classes.add(Collections.synchronizedSet(Collections.emptySet()).getClass());
classes.add(Collections.synchronizedSortedMap(Collections.emptySortedMap()).getClass());
classes.add(Collections.synchronizedSortedSet(Collections.emptySortedSet()).getClass());

代码示例来源:origin: protostuff/protostuff

PojoWithObjectMapFields fill()
{
  TreeMap<String, String> tm = new TreeMap<String, String>();
  tm.put("foo", "bar");
  EnumMap<GuitarPickup, Size> em = new EnumMap<GuitarPickup, Size>(
      GuitarPickup.class);
  em.put(GuitarPickup.CONTACT, Size.SMALL);
  emptyMap = Collections.emptyMap();
  singletonMap = Collections.singletonMap("key", "value");
  unmodifiableMap = Collections.unmodifiableMap(Collections
      .emptyMap());
  unmodifiableSortedMap = Collections.unmodifiableSortedMap(tm);
  synchronizedMap = Collections.synchronizedMap(em);
  synchronizedSortedMap = Collections.synchronizedSortedMap(tm);
  checkedMap = Collections.checkedMap(em, GuitarPickup.class,
      Size.class);
  checkedSortedMap = Collections.checkedSortedMap(tm, String.class,
      String.class);
  return this;
}

代码示例来源:origin: spring-projects/spring-roo

/**
 * Create a base 64 encoded SHA1 hash key for a given XML element. The key
 * is based on the element name, the attribute names and their values. Child
 * elements are ignored. Attributes named 'z' are not concluded since they
 * contain the hash key itself.
 *
 * @param element The element to create the base 64 encoded hash key for
 * @return the unique key
 */
public static String calculateUniqueKeyFor(final Element element) {
 final StringBuilder sb = new StringBuilder();
 sb.append(element.getTagName());
 final NamedNodeMap attributes = element.getAttributes();
 final SortedMap<String, String> attrKVStore =
   Collections.synchronizedSortedMap(new TreeMap<String, String>());
 for (int i = 0, n = attributes.getLength(); i < n; i++) {
  final Node attr = attributes.item(i);
  if (!"z".equals(attr.getNodeName()) && !attr.getNodeName().startsWith("_")) {
   attrKVStore.put(attr.getNodeName(), attr.getNodeValue());
  }
 }
 for (final Entry<String, String> entry : attrKVStore.entrySet()) {
  sb.append(entry.getKey()).append(entry.getValue());
 }
 return Base64.encodeBase64String(sha1(sb.toString().getBytes()));
}

代码示例来源:origin: apache/accumulo

.synchronizedSortedMap(new TreeMap<>());
 .synchronizedSortedMap(new TreeMap<>());

代码示例来源:origin: de.javakaffee/kryo-serializers

@Override
  public Object create( final Object sourceCollection ) {
    return Collections.synchronizedSortedMap( (SortedMap<?, ?>) sourceCollection );
  }
};

代码示例来源:origin: magro/kryo-serializers

@Override
  public Object create( final Object sourceCollection ) {
    return Collections.synchronizedSortedMap( (SortedMap<?, ?>) sourceCollection );
  }
};

代码示例来源:origin: net.java.dev/pdf-renderer

/** Creates a new instance of NameTable */
protected NameTable() {
  super (TrueTypeTable.NAME_TABLE);
  
  records = Collections.synchronizedSortedMap(new TreeMap<NameRecord,String>());
}

代码示例来源:origin: com.github.rjolly/pdf-renderer

/** Creates a new instance of NameTable */
protected NameTable() {
  super (TrueTypeTable.NAME_TABLE);
  
  records = Collections.synchronizedSortedMap(new TreeMap<NameRecord,String>());
}

代码示例来源:origin: tflobbe/solrmeter

@Inject
public OperationTimeHistory() {
  queriesTime = Collections.synchronizedSortedMap(new TreeMap<Long, Long>());
  updatesTime = Collections.synchronizedSortedMap(new TreeMap<Long, Long>());
  commitTime = Collections.synchronizedSortedMap(new TreeMap<Long, Long>());
  optimizeTime = Collections.synchronizedSortedMap(new TreeMap<Long, Long>());
  initTime = new Date().getTime();
}

代码示例来源:origin: stackoverflow.com

SortedMap<String, String> treeMap = new TreeMap<String, String>();
// prints true
System.out.println(treeMap.keySet() instanceof SortedSet);   
// prints false
System.out.println(Collections.synchronizedSortedMap(treeMap).keySet() instanceof SortedSet);

代码示例来源:origin: com.github.rjolly/pdf-renderer

/** Creates a new instance of CmapTable */
protected CmapTable() {
  super(TrueTypeTable.CMAP_TABLE);
  
  setVersion((short) 0x0);

  subtables = Collections.synchronizedSortedMap(new TreeMap<CmapSubtable,CMap>());
}

代码示例来源:origin: net.sf.taverna.t2.component/component-activity

@Override
public final SortedMap<Integer, Version> getComponentVersionMap() {
  synchronized (versionMap) {
    checkComponentVersionMap();
    return synchronizedSortedMap(versionMap);
  }
}

代码示例来源:origin: org.maltparser/maltparser

public SortedMap<ColumnDescription, String> getLabels() {
  SortedMap<ColumnDescription, String> nodeLabels = Collections.synchronizedSortedMap(new TreeMap<ColumnDescription, String>());
  for (Integer key : labels.keySet()) {
    nodeLabels.put(graph.getDataFormat().getColumnDescription(key), labels.get(key));
  }
  return nodeLabels;
}

代码示例来源:origin: org.kaazing/snmp4j-agent

public DefaultMOServer() {
 this.registry =
   Collections.synchronizedSortedMap(new TreeMap(new MOScopeComparator()));
 this.contexts = new LinkedHashSet(10);
 this.lockList = new Hashtable(10);
}

代码示例来源:origin: org.terracotta.modules/tim-tree-map-cache

protected TerracottaTreeCache(boolean isThreadSafe) {        
  if (isThreadSafe) {
    cacheTree = Collections.synchronizedSortedMap(new TreeMap<Fqn,Map>(new Fqn()));
    fqnSet = Collections.synchronizedSortedSet(new TreeSet<Fqn>(new Fqn()));
  } else {
    cacheTree = new TreeMap<Fqn,Map>(new Fqn());
    fqnSet = new TreeSet<Fqn>(new Fqn());
  }
}

代码示例来源:origin: apache/asterixdb

private MetadataProperties mockMetadataProperties() {
  SortedMap<Integer, ClusterPartition> clusterPartitions = Collections.synchronizedSortedMap(new TreeMap<>());
  Map<String, ClusterPartition[]> nodePartitionsMap = new ConcurrentHashMap<>();
  nodePartitionsMap.put(METADATA_NODE, new ClusterPartition[] { new ClusterPartition(0, METADATA_NODE, 0) });
  MetadataProperties metadataProperties = Mockito.mock(MetadataProperties.class);
  Mockito.when(metadataProperties.getMetadataNodeName()).thenReturn(METADATA_NODE);
  Mockito.when(metadataProperties.getClusterPartitions()).thenReturn(clusterPartitions);
  Mockito.when(metadataProperties.getNodePartitions()).thenReturn(nodePartitionsMap);
  return metadataProperties;
}

相关文章

微信公众号

最新文章

更多

Collections类方法