| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.sdk; |
| | |
| | | |
| | | |
| | | |
| | | boolean addAll(final LinkedAttribute attribute, |
| | | final Collection<? extends ByteString> values, |
| | | final Collection<? super ByteString> duplicateValues) |
| | | throws NullPointerException |
| | | { |
| | | // TODO: could optimize if values is a BasicAttribute. |
| | | ensureCapacity(attribute, values.size()); |
| | | boolean modified = false; |
| | | for (final ByteString value : values) |
| | | { |
| | | if (add(attribute, value)) |
| | | { |
| | | modified = true; |
| | | } |
| | | else if (duplicateValues != null) |
| | | { |
| | | duplicateValues.add(value); |
| | | } |
| | | } |
| | | resize(attribute); |
| | | return modified; |
| | | } |
| | | |
| | | |
| | | |
| | | abstract void clear(LinkedAttribute attribute); |
| | | |
| | | |
| | |
| | | boolean containsAll(final LinkedAttribute attribute, |
| | | final Collection<?> values) |
| | | { |
| | | // TODO: could optimize if objects is a BasicAttribute. |
| | | // TODO: could optimize if objects is a LinkedAttribute having the same |
| | | // equality matching rule. |
| | | for (final Object value : values) |
| | | { |
| | | if (!contains(attribute, ByteString.valueOf(value))) |
| | |
| | | |
| | | |
| | | |
| | | abstract void ensureCapacity(LinkedAttribute attribute, int size); |
| | | |
| | | |
| | | |
| | | abstract ByteString firstValue(LinkedAttribute attribute) |
| | | throws NoSuchElementException; |
| | | |
| | |
| | | |
| | | |
| | | |
| | | <T> boolean removeAll(final LinkedAttribute attribute, |
| | | final Collection<T> values, final Collection<? super T> missingValues) |
| | | { |
| | | // TODO: could optimize if objects is a BasicAttribute. |
| | | boolean modified = false; |
| | | for (final T value : values) |
| | | { |
| | | if (remove(attribute, ByteString.valueOf(value))) |
| | | { |
| | | modified = true; |
| | | } |
| | | else if (missingValues != null) |
| | | { |
| | | missingValues.add(value); |
| | | } |
| | | } |
| | | return modified; |
| | | } |
| | | |
| | | |
| | | |
| | | abstract void resize(LinkedAttribute attribute); |
| | | |
| | | |
| | | |
| | | abstract <T> boolean retainAll(LinkedAttribute attribute, |
| | | Collection<T> values, Collection<? super T> missingValues); |
| | | |
| | |
| | | |
| | | |
| | | @Override |
| | | void ensureCapacity(final LinkedAttribute attribute, final int size) |
| | | { |
| | | // Nothing to do. |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | ByteString firstValue(final LinkedAttribute attribute) |
| | | throws NoSuchElementException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public boolean hasNext() |
| | | { |
| | | return iterator.hasNext(); |
| | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public ByteString next() |
| | | { |
| | | if (attribute.pimpl != expectedImpl) |
| | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void remove() |
| | | { |
| | | if (attribute.pimpl != expectedImpl) |
| | |
| | | |
| | | |
| | | @Override |
| | | void resize(final LinkedAttribute attribute) |
| | | { |
| | | // May need to resize if initial size estimate was wrong (e.g. all |
| | | // values in added collection were the same). |
| | | switch (attribute.multipleValues.size()) |
| | | { |
| | | case 0: |
| | | attribute.multipleValues = null; |
| | | attribute.pimpl = ZERO_VALUE_IMPL; |
| | | break; |
| | | case 1: |
| | | final Map.Entry<ByteString, ByteString> e = attribute.multipleValues |
| | | .entrySet().iterator().next(); |
| | | attribute.singleValue = e.getValue(); |
| | | attribute.normalizedSingleValue = e.getKey(); |
| | | attribute.multipleValues = null; |
| | | attribute.pimpl = SINGLE_VALUE_IMPL; |
| | | break; |
| | | default: |
| | | // Nothing to do. |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | <T> boolean retainAll(final LinkedAttribute attribute, |
| | | final Collection<T> values, final Collection<? super T> missingValues) |
| | | { |
| | | // TODO: could optimize if objects is a BasicAttribute. |
| | | // TODO: could optimize if objects is a LinkedAttribute having the same |
| | | // equality matching rule. |
| | | if (values.isEmpty()) |
| | | { |
| | | clear(attribute); |
| | |
| | | { |
| | | return attribute.multipleValues.size(); |
| | | } |
| | | |
| | | |
| | | |
| | | private void resize(final LinkedAttribute attribute) |
| | | { |
| | | // May need to resize if initial size estimate was wrong (e.g. all |
| | | // values in added collection were the same). |
| | | switch (attribute.multipleValues.size()) |
| | | { |
| | | case 0: |
| | | attribute.multipleValues = null; |
| | | attribute.pimpl = ZERO_VALUE_IMPL; |
| | | break; |
| | | case 1: |
| | | final Map.Entry<ByteString, ByteString> e = attribute.multipleValues |
| | | .entrySet().iterator().next(); |
| | | attribute.singleValue = e.getValue(); |
| | | attribute.normalizedSingleValue = e.getKey(); |
| | | attribute.multipleValues = null; |
| | | attribute.pimpl = SINGLE_VALUE_IMPL; |
| | | break; |
| | | default: |
| | | // Nothing to do. |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | @Override |
| | | void ensureCapacity(final LinkedAttribute attribute, final int size) |
| | | { |
| | | if (size == 0) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | attribute.multipleValues = new LinkedHashMap<ByteString, ByteString>( |
| | | 1 + size); |
| | | attribute.multipleValues.put(attribute.normalizedSingleValue, |
| | | attribute.singleValue); |
| | | attribute.singleValue = null; |
| | | attribute.normalizedSingleValue = null; |
| | | attribute.pimpl = MULTI_VALUE_IMPL; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | ByteString firstValue(final LinkedAttribute attribute) |
| | | throws NoSuchElementException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public boolean hasNext() |
| | | { |
| | | return hasNext; |
| | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public ByteString next() |
| | | { |
| | | if (attribute.pimpl != expectedImpl) |
| | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void remove() |
| | | { |
| | | if (attribute.pimpl != expectedImpl) |
| | |
| | | |
| | | |
| | | @Override |
| | | void resize(final LinkedAttribute attribute) |
| | | { |
| | | // Nothing to do. |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | <T> boolean retainAll(final LinkedAttribute attribute, |
| | | final Collection<T> values, final Collection<? super T> missingValues) |
| | | { |
| | | // TODO: could optimize if objects is a BasicAttribute. |
| | | // TODO: could optimize if objects is a LinkedAttribute having the same |
| | | // equality matching rule. |
| | | if (values.isEmpty()) |
| | | { |
| | | clear(attribute); |
| | |
| | | boolean retained = false; |
| | | for (final T value : values) |
| | | { |
| | | final ByteString normalizedValue = normalizeValue(attribute, ByteString |
| | | .valueOf(value)); |
| | | final ByteString normalizedValue = normalizeValue(attribute, |
| | | ByteString.valueOf(value)); |
| | | if (normalizedSingleValue.equals(normalizedValue)) |
| | | { |
| | | if (missingValues == null) |
| | |
| | | |
| | | |
| | | @Override |
| | | void ensureCapacity(final LinkedAttribute attribute, final int size) |
| | | { |
| | | if (size < 2) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | attribute.multipleValues = new LinkedHashMap<ByteString, ByteString>(size); |
| | | attribute.pimpl = MULTI_VALUE_IMPL; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | ByteString firstValue(final LinkedAttribute attribute) |
| | | throws NoSuchElementException |
| | | { |
| | |
| | | { |
| | | return new Iterator<ByteString>() |
| | | { |
| | | @Override |
| | | public boolean hasNext() |
| | | { |
| | | return false; |
| | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public ByteString next() |
| | | { |
| | | if (attribute.pimpl != ZERO_VALUE_IMPL) |
| | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void remove() |
| | | { |
| | | if (attribute.pimpl != ZERO_VALUE_IMPL) |
| | |
| | | |
| | | |
| | | @Override |
| | | void resize(final LinkedAttribute attribute) |
| | | { |
| | | // Nothing to do. |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | <T> boolean retainAll(final LinkedAttribute attribute, |
| | | final Collection<T> values, final Collection<? super T> missingValues) |
| | | { |
| | |
| | | */ |
| | | public static final AttributeFactory FACTORY = new AttributeFactory() |
| | | { |
| | | @Override |
| | | public Attribute newAttribute( |
| | | final AttributeDescription attributeDescription) |
| | | throws NullPointerException |
| | |
| | | * @param values |
| | | * The attribute values. |
| | | * @throws NullPointerException |
| | | * If {@code attributeDescription} or {@code values} was {@code |
| | | * null}. |
| | | * If {@code attributeDescription} or {@code values} was |
| | | * {@code null}. |
| | | */ |
| | | public LinkedAttribute(final AttributeDescription attributeDescription, |
| | | final ByteString... values) throws NullPointerException |
| | |
| | | * @param values |
| | | * The attribute values. |
| | | * @throws NullPointerException |
| | | * If {@code attributeDescription} or {@code values} was {@code |
| | | * null}. |
| | | * If {@code attributeDescription} or {@code values} was |
| | | * {@code null}. |
| | | */ |
| | | public LinkedAttribute(final AttributeDescription attributeDescription, |
| | | final Collection<ByteString> values) throws NullPointerException |
| | |
| | | * If {@code attributeDescription} could not be decoded using the |
| | | * default schema. |
| | | * @throws NullPointerException |
| | | * If {@code attributeDescription} or {@code values} was {@code |
| | | * null}. |
| | | * If {@code attributeDescription} or {@code values} was |
| | | * {@code null}. |
| | | */ |
| | | public LinkedAttribute(final String attributeDescription, |
| | | final Object... values) throws LocalizedIllegalArgumentException, |
| | |
| | | throws NullPointerException |
| | | { |
| | | Validator.ensureNotNull(values); |
| | | return pimpl.addAll(this, values, duplicateValues); |
| | | |
| | | // TODO: could optimize if objects is a LinkedAttribute having the same |
| | | // equality matching rule. |
| | | boolean modified = false; |
| | | for (final ByteString value : values) |
| | | { |
| | | if (add(value)) |
| | | { |
| | | modified = true; |
| | | } |
| | | else if (duplicateValues != null) |
| | | { |
| | | duplicateValues.add(value); |
| | | } |
| | | } |
| | | return modified; |
| | | } |
| | | |
| | | |
| | |
| | | final Collection<? super T> missingValues) throws NullPointerException |
| | | { |
| | | Validator.ensureNotNull(values); |
| | | return pimpl.removeAll(this, values, missingValues); |
| | | |
| | | // TODO: could optimize if objects is a LinkedAttribute having the same |
| | | // equality matching rule. |
| | | boolean modified = false; |
| | | for (final T value : values) |
| | | { |
| | | if (remove(ByteString.valueOf(value))) |
| | | { |
| | | modified = true; |
| | | } |
| | | else if (missingValues != null) |
| | | { |
| | | missingValues.add(value); |
| | | } |
| | | } |
| | | return modified; |
| | | } |
| | | |
| | | |