/** * Writes the content to the stream for serialization. * * @param stream the output stream * @throws IOException if an error occurs while writing to the stream */ private void writeObject(final ObjectOutputStream stream) throws IOException{ stream.defaultWriteObject(); stream.writeInt(this.size()); for (final Entry<K, V> entry : entrySet()) { stream.writeObject(entry.getKey()); stream.writeObject(entry.getValue()); } }
/** * Puts a {@link CustomProperty} that has not yet a valid ID into this * map. The method will allocate a suitable ID for the custom property: * * <ul> * <li>If there is already a property with the same name, take the ID * of that property. * * <li>Otherwise find the highest ID and use its value plus one. * </ul> * * @param customProperty The {@link CustomProperty} to add. * @return If there was already a property with the same name, the old property * @throws ClassCastException */ private Object put(final CustomProperty customProperty) throws ClassCastException { final String name = customProperty.getName(); /* Check whether a property with this name is in the map already. */ final Long oldId = (name == null) ? null : dictionary.getKey(name); if (oldId != null) { customProperty.setID(oldId); } else { long lastKey = (dictionary.isEmpty()) ? 0 : dictionary.lastKey(); long nextKey = Math.max(lastKey,PropertyIDMap.PID_MAX)+1; customProperty.setID(nextKey); } return this.put(name, customProperty); }
/** * Puts all the mappings from the specified map into this map. * <p> * All keys and values must implement <code>Comparable</code>. * * @param map the map to copy from */ @Override public void putAll(final Map<? extends K, ? extends V> map) { for (final Map.Entry<? extends K, ? extends V> e : map.entrySet()) { put(e.getKey(), e.getValue()); } }
/** * Checks against both String Name and Long ID */ @Override public boolean containsKey(Object key) { return ((key instanceof Long && dictionary.containsKey(key)) || dictionary.containsValue(key)); }
final TreeBidiMap<Long,Long> offset2Id = new TreeBidiMap<>(); for (int i = 0; i < propertyCount; i++) { offset2Id.put(off, id); Long cpOffset = offset2Id.getKey((long)PropertyIDMap.PID_CODEPAGE); for (Map.Entry<Long,Long> me : offset2Id.entrySet()) { long off = me.getKey(); long id = me.getValue(); try { id = Math.max(PropertyIDMap.PID_MAX, offset2Id.inverseBidiMap().lastKey())+1; setProperty(new Property(id, leis, pLen, codepage)); } catch (RuntimeException e) {
/** * Puts a {@link CustomProperty} into this map. It is assumed that the * {@link CustomProperty} already has a valid ID. Otherwise use * {@link #put(CustomProperty)}. * * @param name the property name * @param cp the property * * @return the previous property stored under this name */ public CustomProperty put(final String name, final CustomProperty cp) { if (name == null) { /* Ignoring a property without a name. */ isPure = false; return null; } if (!name.equals(cp.getName())) { throw new IllegalArgumentException("Parameter \"name\" (" + name + ") and custom property's name (" + cp.getName() + ") do not match."); } checkCodePage(name); /* Register name and ID in the dictionary. Mapping in both directions is possible. If there is already a */ props.remove(dictionary.getKey(name)); dictionary.put(cp.getID(), name); /* Put the custom property into this map. */ return props.put(cp.getID(), cp); }
/** * Returns a set of all the IDs of our custom properties * * @return a set of all the IDs of our custom properties */ public Set<Long> idSet() { return Collections.unmodifiableSet(dictionary.keySet()); }
@Override public Set<Entry<String, Object>> entrySet() { Map<String,Object> set = new LinkedHashMap<>(props.size()); for (Entry<Long,String> se : dictionary.entrySet()) { set.put(se.getValue(), props.get(se.getKey()).getValue()); } return Collections.unmodifiableSet(set.entrySet()); }
@Override public OrderedMapIterator<K, V> mapIterator() { if (isEmpty()) { return EmptyOrderedMapIterator.<K, V>emptyOrderedMapIterator(); } return new ViewMapIterator(KEY); }
this.config = config; final BidiMap virtuals = new TreeBidiMap(); for (int i = 0; config.resource_resolver_virtual() != null && i < config.resource_resolver_virtual().length; i++) { final String[] parts = Mapping.split(config.resource_resolver_virtual()[i]);
/** * Gets a named value from the custom properties - only works for keys of type String * * @param key the name of the value to get * @return the value or {@code null} if a value with the specified * name is not found in the custom properties. */ @Override public Object get(final Object key) { final Long id = dictionary.getKey(key); final CustomProperty cp = props.get(id); return cp != null ? cp.getValue() : null; }
final TreeBidiMap<Long,Long> offset2Id = new TreeBidiMap<>(); for (int i = 0; i < propertyCount; i++) { offset2Id.put(off, id); Long cpOffset = offset2Id.getKey((long)PropertyIDMap.PID_CODEPAGE); for (Map.Entry<Long,Long> me : offset2Id.entrySet()) { long off = me.getKey(); long id = me.getValue(); try { id = Math.max(PropertyIDMap.PID_MAX, offset2Id.inverseBidiMap().lastKey())+1; setProperty(new Property(id, leis, pLen, codepage)); } catch (RuntimeException e) {
/** * Puts a {@link CustomProperty} into this map. It is assumed that the * {@link CustomProperty} already has a valid ID. Otherwise use * {@link #put(CustomProperty)}. * * @param name the property name * @param cp the property * * @return the previous property stored under this name */ public CustomProperty put(final String name, final CustomProperty cp) { if (name == null) { /* Ignoring a property without a name. */ isPure = false; return null; } if (!name.equals(cp.getName())) { throw new IllegalArgumentException("Parameter \"name\" (" + name + ") and custom property's name (" + cp.getName() + ") do not match."); } checkCodePage(name); /* Register name and ID in the dictionary. Mapping in both directions is possible. If there is already a */ props.remove(dictionary.getKey(name)); dictionary.put(cp.getID(), name); /* Put the custom property into this map. */ return props.put(cp.getID(), cp); }
/** * Checks against both String Name and Long ID */ @Override public boolean containsKey(Object key) { return ((key instanceof Long && dictionary.containsKey(key)) || dictionary.containsValue(key)); }
/** * @return the list of properties */ public List<CustomProperty> properties() { List<CustomProperty> list = new ArrayList<>(props.size()); for (Long l : dictionary.keySet()) { list.add(props.get(l)); } return Collections.unmodifiableList(list); }
@Override public Set<Entry<String, Object>> entrySet() { Map<String,Object> set = new LinkedHashMap<>(props.size()); for (Entry<Long,String> se : dictionary.entrySet()) { set.put(se.getValue(), props.get(se.getKey()).getValue()); } return Collections.unmodifiableSet(set.entrySet()); }
/** * Gets a named value from the custom properties - only works for keys of type String * * @param key the name of the value to get * @return the value or {@code null} if a value with the specified * name is not found in the custom properties. */ @Override public Object get(final Object key) { final Long id = dictionary.getKey(key); final CustomProperty cp = props.get(id); return cp != null ? cp.getValue() : null; }
/** * Puts a {@link CustomProperty} that has not yet a valid ID into this * map. The method will allocate a suitable ID for the custom property: * * <ul> * <li>If there is already a property with the same name, take the ID * of that property. * * <li>Otherwise find the highest ID and use its value plus one. * </ul> * * @param customProperty The {@link CustomProperty} to add. * @return If there was already a property with the same name, the old property * @throws ClassCastException */ private Object put(final CustomProperty customProperty) throws ClassCastException { final String name = customProperty.getName(); /* Check whether a property with this name is in the map already. */ final Long oldId = (name == null) ? null : dictionary.getKey(name); if (oldId != null) { customProperty.setID(oldId); } else { long lastKey = (dictionary.isEmpty()) ? 0 : dictionary.lastKey(); long nextKey = Math.max(lastKey,PropertyIDMap.PID_MAX)+1; customProperty.setID(nextKey); } return this.put(name, customProperty); }
/** * @return the list of property values - use {@link #properties()} for the wrapped values */ @Override public Collection<Object> values() { List<Object> list = new ArrayList<>(props.size()); for (Long l : dictionary.keySet()) { list.add(props.get(l).getValue()); } return Collections.unmodifiableCollection(list); }
/** * Reads the content of the stream. * * @param stream the input stream * @throws IOException if an error occurs while reading from the stream * @throws ClassNotFoundException if an object read from the stream can not be loaded */ @SuppressWarnings("unchecked") // This will fail at runtime if the stream is incorrect private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException{ stream.defaultReadObject(); rootNode = new Node[2]; final int size = stream.readInt(); for(int i = 0; i < size; i++){ final K k =(K) stream.readObject(); final V v =(V) stream.readObject(); put(k, v); } }