return put(new CustomProperty(p, key));
/** * Compares two custom properties for equality. The method returns * {@code true} if all attributes of the two custom properties are * equal. * * @param o The custom property to compare with. * @return {@code true} if both custom properties are equal, else * {@code false}. * * @see java.util.AbstractSet#equals(java.lang.Object) */ public boolean equalsContents(final Object o) { final CustomProperty c = (CustomProperty) o; final String name1 = c.getName(); final String name2 = this.getName(); boolean equalNames = true; if (name1 == null) { equalNames = name2 == null; } else { equalNames = name1.equals(name2); } return equalNames && c.getID() == this.getID() && c.getType() == this.getType() && c.getValue().equals(this.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 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); }
/** * Gets the custom properties. * * @return The custom properties. */ public CustomProperties getCustomProperties() { CustomProperties cps = null; if (getSectionCount() >= 2) { cps = new CustomProperties(); final Section section = getSections().get(1); final Map<Long,String> dictionary = section.getDictionary(); final Property[] properties = section.getProperties(); int propertyCount = 0; for (Property p : properties) { final long id = p.getID(); if (id == PropertyIDMap.PID_CODEPAGE) { cps.setCodepage((Integer)p.getValue()); } else if (id > PropertyIDMap.PID_CODEPAGE) { propertyCount++; final CustomProperty cp = new CustomProperty(p, dictionary.get(id)); cps.put(cp.getName(), cp); } } if (cps.size() != propertyCount) { cps.setPure(false); } } return cps; }
/** * Checks against both the property, and its values. */ @Override public boolean containsValue(Object value) { if(value instanceof CustomProperty) { return props.containsValue(value); } for(CustomProperty cp : props.values()) { if(cp.getValue() == value) { return true; } } return false; }
/** * <p>Gets the codepage.</p> * * @return the codepage or -1 if the codepage is undefined. */ public int getCodepage() { int codepage = -1; for (final Iterator<CustomProperty> i = this.values().iterator(); codepage == -1 && i.hasNext();) { final CustomProperty cp = i.next(); if (cp.getID() == PropertyIDMap.PID_CODEPAGE) codepage = ((Integer) cp.getValue()).intValue(); } return codepage; }
/** * @see java.util.AbstractSet#hashCode() */ @Override public int hashCode() { return (int) this.getID(); }
@Override public boolean equals(Object o) { return (o instanceof CustomProperty) ? equalsContents(o) : false; } }
final CustomProperty cp = new CustomProperty(p, dictionary.get(Long.valueOf(id))); cps.put(cp.getName(), cp);
/** * <p>Puts a {@link CustomProperty} into this map. It is assumed that the * {@link CustomProperty} already has a valid ID. Otherwise use * {@link #put(CustomProperty)}.</p> */ 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."); /* Register name and ID in the dictionary. Mapping in both directions is possible. If there is already a */ final Long idKey = Long.valueOf(cp.getID()); final Long oldID = dictionaryNameToID.get(name); dictionaryIDToName.remove(oldID); dictionaryNameToID.put(name, idKey); dictionaryIDToName.put(idKey, name); /* Put the custom property into this map. */ final CustomProperty oldCp = super.remove(oldID); super.put(idKey, cp); return oldCp; }
/** * @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); }
/** * <p>Gets the codepage.</p> * * @return the codepage or -1 if the codepage is undefined. */ public int getCodepage() { int codepage = -1; for (final Iterator<CustomProperty> i = this.values().iterator(); codepage == -1 && i.hasNext();) { final CustomProperty cp = i.next(); if (cp.getID() == PropertyIDMap.PID_CODEPAGE) codepage = ((Integer) cp.getValue()).intValue(); } return codepage; }
/** * @see java.util.AbstractSet#hashCode() */ public int hashCode() { return (int) this.getID(); }
@Override public boolean equals(Object o) { return (o instanceof CustomProperty) ? equalsContents(o) : false; } }
/** * <p>Compares two custom properties for equality. The method returns * <code>true</code> if all attributes of the two custom properties are * equal.</p> * * @param o The custom property to compare with. * @return <code>true</code> if both custom properties are equal, else * <code>false</code>. * * @see java.util.AbstractSet#equals(java.lang.Object) */ public boolean equalsContents(final Object o) { final CustomProperty c = (CustomProperty) o; final String name1 = c.getName(); final String name2 = this.getName(); boolean equalNames = true; if (name1 == null) equalNames = name2 == null; else equalNames = name1.equals(name2); return equalNames && c.getID() == this.getID() && c.getType() == this.getType() && c.getValue().equals(this.getValue()); }
envelope.setOutputSoapObject(new CustomProperty(null, "request", "34"));
final CustomProperty cp = new CustomProperty(p, dictionary.get(Long.valueOf(id))); cps.put(cp.getName(), cp);