java.util.TreeMap.clone()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(122)

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

TreeMap.clone介绍

[英]Returns a shallow copy of this TreeMap instance. (The keys and values themselves are not cloned.)
[中]返回此树映射实例的浅层副本。(不会克隆键和值本身。)

代码示例

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

@Override
public VectorClock clone() {
  return (VectorClock) super.clone();
}

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

/**
 * Copy all of the mappings from the specified map to this one, replacing
 * any mappings with the same keys.
 *
 * @param in  the map whose mappings are to be copied
 */
public void putAll(Map in) {
  if (fast) {
    synchronized (this) {
      TreeMap temp = (TreeMap) map.clone();
      temp.putAll(in);
      map = temp;
    }
  } else {
    synchronized (map) {
      map.putAll(in);
    }
  }
}

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

/**
 * Remove any mapping for this key, and return any previously
 * mapped value.
 *
 * @param key  the key whose mapping is to be removed
 * @return the value removed, or null
 */
public Object remove(Object key) {
  if (fast) {
    synchronized (this) {
      TreeMap temp = (TreeMap) map.clone();
      Object result = temp.remove(key);
      map = temp;
      return (result);
    }
  } else {
    synchronized (map) {
      return (map.remove(key));
    }
  }
}

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

protected Map copyMap(Map map) {
  if (map instanceof HashMap) {
    return (Map) ((HashMap) map).clone();
  }
  if (map instanceof SortedMap) {
    if (map instanceof TreeMap) {
      return (Map) ((TreeMap) map).clone();
    } else {
      return new TreeMap((SortedMap) map);
    }
  } 
  return new HashMap(map);
}

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

/**
 * Associate the specified value with the specified key in this map.
 * If the map previously contained a mapping for this key, the old
 * value is replaced and returned.
 *
 * @param key  the key with which the value is to be associated
 * @param value  the value to be associated with this key
 * @return the value previously mapped to the key, or null
 */
public Object put(Object key, Object value) {
  if (fast) {
    synchronized (this) {
      TreeMap temp = (TreeMap) map.clone();
      Object result = temp.put(key, value);
      map = temp;
      return (result);
    }
  } else {
    synchronized (map) {
      return (map.put(key, value));
    }
  }
}

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

/**
 * Copy all of the mappings from the specified map to this one, replacing
 * any mappings with the same keys.
 *
 * @param in  the map whose mappings are to be copied
 */
public void putAll(Map in) {
  if (fast) {
    synchronized (this) {
      TreeMap temp = (TreeMap) map.clone();
      temp.putAll(in);
      map = temp;
    }
  } else {
    synchronized (map) {
      map.putAll(in);
    }
  }
}

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

/**
 * Remove any mapping for this key, and return any previously
 * mapped value.
 *
 * @param key  the key whose mapping is to be removed
 * @return the value removed, or null
 */
public Object remove(Object key) {
  if (fast) {
    synchronized (this) {
      TreeMap temp = (TreeMap) map.clone();
      Object result = temp.remove(key);
      map = temp;
      return (result);
    }
  } else {
    synchronized (map) {
      return (map.remove(key));
    }
  }
}

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

/**
 * Associate the specified value with the specified key in this map.
 * If the map previously contained a mapping for this key, the old
 * value is replaced and returned.
 *
 * @param key  the key with which the value is to be associated
 * @param value  the value to be associated with this key
 * @return the value previously mapped to the key, or null
 */
public Object put(Object key, Object value) {
  if (fast) {
    synchronized (this) {
      TreeMap temp = (TreeMap) map.clone();
      Object result = temp.put(key, value);
      map = temp;
      return (result);
    }
  } else {
    synchronized (map) {
      return (map.put(key, value));
    }
  }
}

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

/**
 * Returns a new {@code TreeSet} with the same elements, size and comparator
 * as this {@code TreeSet}.
 *
 * @return a shallow copy of this {@code TreeSet}.
 * @see java.lang.Cloneable
 */
@SuppressWarnings("unchecked")
@Override
public Object clone() {
  try {
    TreeSet<E> clone = (TreeSet<E>) super.clone();
    if (backingMap instanceof TreeMap) {
      clone.backingMap = (NavigableMap<E, Object>) ((TreeMap<E, Object>) backingMap)
          .clone();
    } else {
      clone.backingMap = new TreeMap<E, Object>(backingMap);
    }
    return clone;
  } catch (CloneNotSupportedException e) {
    throw new AssertionError(e);
  }
}

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

public boolean retainAll(Collection o) {
  if (fast) {
    synchronized (FastTreeMap.this) {
      TreeMap temp = (TreeMap) map.clone();
      boolean r = get(temp).retainAll(o);
      map = temp;
      return r;
    }
  } else {
    synchronized (map) {
      return get(map).retainAll(o);
    }
  }
}

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

public boolean remove(Object o) {
  if (fast) {
    synchronized (FastTreeMap.this) {
      TreeMap temp = (TreeMap) map.clone();
      boolean r = get(temp).remove(o);
      map = temp;
      return r;
    }
  } else {
    synchronized (map) {
      return get(map).remove(o);
    }
  }
}

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

public boolean removeAll(Collection o) {
  if (fast) {
    synchronized (FastTreeMap.this) {
      TreeMap temp = (TreeMap) map.clone();
      boolean r = get(temp).removeAll(o);
      map = temp;
      return r;
    }
  } else {
    synchronized (map) {
      return get(map).removeAll(o);
    }
  }
}

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

public boolean removeAll(Collection o) {
  if (fast) {
    synchronized (FastTreeMap.this) {
      TreeMap temp = (TreeMap) map.clone();
      boolean r = get(temp).removeAll(o);
      map = temp;
      return r;
    }
  } else {
    synchronized (map) {
      return get(map).removeAll(o);
    }
  }
}

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

public boolean retainAll(Collection o) {
  if (fast) {
    synchronized (FastTreeMap.this) {
      TreeMap temp = (TreeMap) map.clone();
      boolean r = get(temp).retainAll(o);
      map = temp;
      return r;
    }
  } else {
    synchronized (map) {
      return get(map).retainAll(o);
    }
  }
}

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

public boolean remove(Object o) {
  if (fast) {
    synchronized (FastTreeMap.this) {
      TreeMap temp = (TreeMap) map.clone();
      boolean r = get(temp).remove(o);
      map = temp;
      return r;
    }
  } else {
    synchronized (map) {
      return get(map).remove(o);
    }
  }
}

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

public Object clone() throws CloneNotSupportedException {
  Node n=new Node(name, fqn, parent != null? (Node)parent.clone() : null, data);
  if(children != null) n.children=(TreeMap)children.clone();
  return n;
}

代码示例来源:origin: SpongePowered/SpongeAPI

/**
 * Attempts to use native {@link Object#clone()} methods on available map
 * types. If a map cannot be properly cloned, a new {@link HashMap} is
 * returned.
 *
 * @param map The map input
 * @param <K> The key type
 * @param <V> The value type
 * @return A copied map
 */
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> copyMap(Map<? extends K, ? extends V> map) {
  try {
    if (map instanceof HashMap) {
      return (Map<K, V>) ((HashMap<? extends K, ? extends V>) map).clone();
    } else if (map instanceof IdentityHashMap) {
      return (Map<K, V>) ((IdentityHashMap<?, ?>) map).clone();
    } else if (map instanceof EnumMap) {
      return (Map<K, V>) ((EnumMap<?, V>) map).clone();
    } else if (map instanceof TreeMap) {
      return (Map<K, V>) ((TreeMap<K, V>) map).clone();
    } else if (map instanceof ConcurrentHashMap) {
      return (Map<K, V>) new ConcurrentHashMap<>(map);
    }
  } catch (Exception ignored) {
  }
  return new HashMap<>(map);
}

代码示例来源:origin: hsz/idea-gitignore

/**
   * Returns a shallow copy of this <tt>HashMap</tt> instance: the keys and
   * values themselves are not cloned.
   *
   * @return a shallow copy of this map
   */
  @Override
  public IgnoreLanguagesSettings clone() {
    IgnoreLanguagesSettings copy = (IgnoreLanguagesSettings) super.clone();
    for (Map.Entry<IgnoreLanguage, TreeMap<IgnoreLanguagesSettings.KEY, Object>> entry : copy.entrySet()) {
      @SuppressWarnings("unchecked")
      TreeMap<IgnoreLanguagesSettings.KEY, Object> data = (TreeMap<KEY, Object>) entry.getValue().clone();
      copy.put(entry.getKey(), data);
    }
    return copy;
  }
}

代码示例来源:origin: org.osgi/org.osgi.compendium

TreeMap tempPrincipalPermissions = (TreeMap) base.principalPermissions.clone();
int tempGlobalPermissions = base.globalPermissions;

代码示例来源:origin: BaseXdb/basex

/**
 * Constructor with options to be copied.
 * @param opts options
 */
@SuppressWarnings("unchecked")
protected Options(final Options opts) {
 options = (TreeMap<String, Option<?>>) opts.options.clone();
 values = (TreeMap<String, Object>) opts.values.clone();
 free = (HashMap<String, String>) opts.free.clone();
 user.add(opts.user);
 file = opts.file;
}

相关文章

微信公众号

最新文章

更多