@Override public Map readObject(ObjectInput input) throws IOException, ClassNotFoundException { return Immutables.immutableMapWrap(MarshallUtil.unmarshallMap(input, HashMap::new)); }
private Set<Object> getChildrenNames(AdvancedCache<?, ?> cache) { return Immutables.immutableSetCopy(getStructure(cache).keySet()); }
/** * Converts a Collections into an immutable Set by copying it. * * @param collection the collection to convert/copy * @return a new immutable set containing the elements in collection */ public static <T> Set<T> immutableSetConvert(Collection<? extends T> collection) { return immutableSetWrap(new HashSet<T>(collection)); }
/** * Creates an immutable copy of the specified map. * * @param map the map to copy from * @return an immutable map copy */ public static <K, V> Map<K, V> immutableMapCopy(Map<K, V> map) { if (map == null) return null; if (map.isEmpty()) return Collections.emptyMap(); if (map.size() == 1) { Map.Entry<K, V> me = map.entrySet().iterator().next(); return Collections.singletonMap(me.getKey(), me.getValue()); } Map<? extends K, ? extends V> copy = ObjectDuplicator.duplicateMap(map); if (copy == null) copy = attemptCopyConstructor(map, Map.class); if (copy == null) copy = new HashMap<>(map); return new ImmutableMapWrapper<>(copy); }
/** * @deprecated use {@link AbstractTypedPropertiesConfiguration#AbstractTypedPropertiesConfiguration(AttributeSet)} instead */ @Deprecated protected AbstractTypedPropertiesConfiguration(Properties properties) { this.attributes = attributeSet(); this.attributes = attributes.protect(); this.properties = this.attributes.attribute(PROPERTIES); this.attributes.attribute(PROPERTIES).set(immutableTypedProperties(TypedProperties.toTypedProperties(properties))); }
static List<ProtocolConfiguration> copy(List<ProtocolConfiguration> protocols) { // Make a safe copy of the protocol stack to avoid concurrent modification issues List<ProtocolConfiguration> copy = new ArrayList<ProtocolConfiguration>(protocols.size()); for (ProtocolConfiguration p : protocols) copy.add(new ProtocolConfiguration( p.getProtocolName(), immutableMapCopy(p.getProperties()))); return copy; } }
/** * Creates a new immutable copy of the specified Collection. * * @param collection the collection to copy * @return an immutable copy */ public static <T> Collection<T> immutableCollectionCopy(Collection<T> collection) { if (collection == null) return null; if (collection.isEmpty()) return Collections.emptySet(); if (collection.size() == 1) return Collections.singleton(collection.iterator().next()); Collection<? extends T> copy = ObjectDuplicator.duplicateCollection(collection); if (copy == null) copy = attemptCopyConstructor(collection, Collection.class); if (copy == null) copy = new ArrayList<>(collection); return new ImmutableCollectionWrapper<>(copy); }
protected AbstractTypedPropertiesConfiguration(AttributeSet attributes) { this.attributes = attributes.checkProtection(); this.properties = this.attributes.attribute(PROPERTIES); if (properties.isModified()) { properties.set(immutableTypedProperties(properties.get())); } }
private void removeChildren(AdvancedCache<?, ?> cache) { startAtomic(); try { Map<Object, Fqn> s = getStructure(cache); for (Object o : Immutables.immutableSetCopy(s.keySet())) removeChild(cache, o); } finally { endAtomic(); } }
@Override public Set readObject(ObjectInput input) throws IOException, ClassNotFoundException { Set<Object> set = MarshallUtil.unmarshallCollection(input, HashSet::new); return Immutables.immutableSetWrap(set); }
public void testMapMarshalling() throws Exception { Map<Integer, GlobalTransaction> m1 = new HashMap<>(); Map<Integer, GlobalTransaction> m2 = new TreeMap<>(); Map<Integer, GlobalTransaction> m3 = new HashMap<>(); Map<Integer, GlobalTransaction> m4 = new FastCopyHashMap<>(); for (int i = 0; i < 10; i++) { JGroupsAddress jGroupsAddress = new JGroupsAddress(UUID.randomUUID()); GlobalTransaction gtx = gtf.newGlobalTransaction(jGroupsAddress, false); m1.put(1000 * i, gtx); m2.put(1000 * i, gtx); m4.put(1000 * i, gtx); } Map m5 = Immutables.immutableMapWrap(m3); marshallAndAssertEquality(m1); marshallAndAssertEquality(m2); byte[] bytes = marshaller.objectToByteBuffer(m4); Map<Integer, GlobalTransaction> m4Read = (Map<Integer, GlobalTransaction>) marshaller.objectFromByteBuffer(bytes); for (Map.Entry<Integer, GlobalTransaction> entry : m4.entrySet()) { assert m4Read.get(entry.getKey()).equals(entry.getValue()) : "Writen[" + entry.getValue() + "] and read[" + m4Read.get(entry.getKey()) + "] objects should be the same"; } marshallAndAssertEquality(m5); }
/** * Creates an immutable copy of the specified set. * * @param set the set to copy from * @return an immutable set copy */ public static <T> Set<T> immutableSetCopy(Set<T> set) { if (set == null) return null; if (set.isEmpty()) return Collections.emptySet(); if (set.size() == 1) return Collections.singleton(set.iterator().next()); Set<? extends T> copy = ObjectDuplicator.duplicateSet(set); if (copy == null) // Set uses Collection copy-ctor copy = attemptCopyConstructor(set, Collection.class); if (copy == null) copy = new HashSet<>(set); return new ImmutableSetWrapper<>(copy); }
.immutableSetCopy(originalValues.keySet()), true)))).iterator();
private Set<Node<K, V>> getChildren(AdvancedCache<?, ?> cache) { startAtomic(); try { Set<Node<K, V>> result = new HashSet<Node<K, V>>(); for (Fqn f : getStructure().values()) { NodeImpl<K, V> n = new NodeImpl<K, V>(f, cache, batchContainer); result.add(n); } return Immutables.immutableSetWrap(result); } finally { endAtomic(); } }
.immutableSetCopy(originalValues.keySet()), true)))).iterator();