/** * 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); }
@Override protected Object clone() throws CloneNotSupportedException { EmitContext context = new EmitContext(_context.clone()); return context; } }
@Override public EnumMap<TranslationStatus, Integer> getTranslationStatusMetrics() { if (ts == null) { return null; } return ts.clone(); }
public CommonConfiguration(CommonConfiguration configuration) { this.logger = configuration.logger; this.configurationValues = configuration.configurationValues.clone(); }
public CommonConfiguration(CommonConfiguration configuration) { this.logger = configuration.logger; this.configurationValues = configuration.configurationValues.clone(); }
@Override public Message clone() throws CloneNotSupportedException { final Message m = (Message) super.clone(); m.properties = properties.clone(); return m; }
@Override public void restore() { THEAD_LOCAL_ANNOTATIONS.set(data.clone()); } };
/** * Returns a clone of this {@code Colors}. * * @return a clone of this {@code Colors}. */ @Override public Colors clone() { final Colors clone; try { clone = (Colors) super.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError(e); } clone.map = clone.map.clone(); clone.isImmutable = false; return clone; }
/** * Returns a clone of this {@code Colors}. * * @return a clone of this {@code Colors}. */ @Override public Colors clone() { final Colors clone; try { clone = (Colors) super.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError(e); } clone.map = clone.map.clone(); clone.isImmutable = false; return clone; }
/** * Creates a copy of TypeMetadata {@code other} with a shallow copy the other's metadata contents. * * @param other the TypeMetadata to copy contents from. */ public TypeMetadata(TypeMetadata other) { Assert.checkNonNull(other); contents = other.contents.clone(); }
@Override public DataMap clone() { return new DataMap(super.clone()); }
/** * Returns a new QueryHints object with the given hint and value. * * @throws IllegalArgumentException if hint or value is null */ public QueryHints with(QueryHint hint, Object value) { if (hint == null) { throw new IllegalArgumentException("Null hint"); } if (value == null) { throw new IllegalArgumentException("Null value"); } EnumMap<QueryHint, Object> map; if (mMap == null) { map = new EnumMap<QueryHint, Object>(QueryHint.class); } else { map = mMap.clone(); } map.put(hint, value); return new QueryHints(map); }
/** * Returns a new QueryHints object with the given hint and value. * * @throws IllegalArgumentException if hint or value is null */ public QueryHints with(QueryHint hint, Object value) { if (hint == null) { throw new IllegalArgumentException("Null hint"); } if (value == null) { throw new IllegalArgumentException("Null value"); } EnumMap<QueryHint, Object> map; if (mMap == null) { map = new EnumMap<QueryHint, Object>(QueryHint.class); } else { map = mMap.clone(); } map.put(hint, value); return new QueryHints(map); }
/** * Returns a new QueryHints object without the given hint. */ public QueryHints without(QueryHint hint) { if (hint == null || mMap == null || !mMap.containsKey(hint)) { return this; } EnumMap<QueryHint, Object> map = mMap.clone(); map.remove(hint); if (map.size() == 0) { map = null; } return new QueryHints(map); }
/** * Returns a new QueryHints object without the given hint. */ public QueryHints without(QueryHint hint) { if (hint == null || mMap == null || !mMap.containsKey(hint)) { return this; } EnumMap<QueryHint, Object> map = mMap.clone(); map.remove(hint); if (map.size() == 0) { map = null; } return new QueryHints(map); }
public void visit(Tree.PackageDescriptor that) { EnumMap<E, Integer> priorCounts = counts.clone(); EnumMap<E,Boolean> added = pre(that.getAnnotationList()); super.visit(that); post(priorCounts, added, that.getAnnotationList()); }
public void visit(Tree.Assertion that) { EnumMap<E, Integer> priorCounts = counts.clone(); EnumMap<E,Boolean> added = pre(that.getAnnotationList()); super.visit(that); post(priorCounts, added, that.getAnnotationList()); }
public void visit(Tree.Declaration that) { if (!TreeUtil.isForUnsupportedBackend(that.getAnnotationList(), that.getUnit())) { EnumMap<E, Integer> priorCounts = counts.clone(); EnumMap<E,Boolean> added = pre(that.getAnnotationList()); super.visit(that); post(priorCounts, added, that.getAnnotationList()); } }
public void visit(Tree.ModuleDescriptor that) { if (!TreeUtil.isForUnsupportedBackend(that.getAnnotationList(), that.getUnit())) { EnumMap<E, Integer> priorCounts = counts.clone(); EnumMap<E,Boolean> added = pre(that.getAnnotationList()); super.visit(that); post(priorCounts, added, that.getAnnotationList()); } }
public void visit(Tree.ImportModule that) { if (!TreeUtil.isForUnsupportedBackend(that.getAnnotationList(), that.getUnit())) { EnumMap<E, Integer> priorCounts = counts.clone(); EnumMap<E,Boolean> added = pre(that.getAnnotationList()); super.visit(that); post(priorCounts, added, that.getAnnotationList()); } }