예제 #1
0
 private Entry _sibling(Entry current, N name) throws StaxNavException {
   if (current != null) {
     Entry element = current;
     while (true) {
       Entry next = element.next();
       if (next != null && next.getElement().getDepth() >= current.getElement().getDepth()) {
         if (next.getElement().getDepth() == current.getElement().getDepth()) {
           if (name == null) {
             current = next;
             return current;
           } else {
             N siblingName = naming.getName(next.getElement().getName());
             if (name.equals(siblingName)) {
               current = next;
               return current;
             } else {
               element = next;
             }
           }
         } else {
           element = next;
         }
       } else {
         break;
       }
     }
   }
   return null;
 }
예제 #2
0
 private Entry _current(Entry current, N name) throws StaxNavException {
   if (current != null) {
     if (name == null || name.equals(naming.getName(current.getElement().getName()))) {
       return current;
     }
   }
   return null;
 }
예제 #3
0
 protected Entry next(int depth) throws StaxNavException {
   Entry next = next();
   if (next != null && next.getElement().getDepth() > depth) {
     return next;
   } else {
     return null;
   }
 }
예제 #4
0
 public Map<String, String> getAttributes()
     throws NullPointerException, IllegalStateException, StaxNavException {
   Map<String, String> attributes = current.getElement().getAttributes();
   if (attributes.isEmpty()) {
     return Collections.emptyMap();
   } else {
     return attributes;
   }
 }
예제 #5
0
 public String getAttribute(String name)
     throws NullPointerException, IllegalStateException, StaxNavException {
   Map<String, String> attributes = current.getElement().getAttributes();
   if (attributes.isEmpty()) {
     return null;
   } else {
     return attributes.get(name);
   }
 }
예제 #6
0
 public boolean find(N name) throws StaxNavException {
   if (name == null) {
     throw new NullPointerException("No null name accepted");
   }
   if (name.equals(naming.getName(current.getElement().getName()))) {
     return true;
   } else {
     return navigate(Axis.FOLLOWING, name);
   }
 }
예제 #7
0
 private int _descendant(N name) throws StaxNavException {
   Entry element = current;
   while (true) {
     Entry next = element.next();
     if (next != null && next.getElement().getDepth() >= current.getElement().getDepth()) {
       N descendantName = naming.getName(next.getElement().getName());
       if (name.equals(descendantName)) {
         int diff = next.getElement().getDepth() - current.getElement().getDepth();
         current = next;
         return diff;
       } else {
         element = next;
       }
     } else {
       break;
     }
   }
   return -1;
 }
예제 #8
0
 @Override
 public Entry<E> pollLastEntry() {
   Iterator<Entry<E>> entryIterator = descendingEntryIterator();
   if (entryIterator.hasNext()) {
     Entry<E> result = entryIterator.next();
     result = Multisets.immutableEntry(result.getElement(), result.getCount());
     entryIterator.remove();
     return result;
   }
   return null;
 }
예제 #9
0
 SerializedForm(Multiset<?> multiset) {
   int distinct = multiset.entrySet().size();
   elements = new Object[distinct];
   counts = new int[distinct];
   int i = 0;
   for (Entry<?> entry : multiset.entrySet()) {
     elements[i] = entry.getElement();
     counts[i] = entry.getCount();
     i++;
   }
 }
예제 #10
0
 private Entry _next(Entry current, N name) throws StaxNavException {
   if (current != null) {
     Entry next = current.next(depth);
     if (next != null
         && (name == null || name.equals(naming.getName(next.getElement().getName())))) {
       current = next;
       return current;
     }
   }
   return null;
 }
예제 #11
0
 public <V> V parseContent(ValueType<V> valueType)
     throws IllegalStateException, NullPointerException, StaxNavException {
   if (valueType == null) {
     throw new NullPointerException();
   }
   Entry element = current;
   String content = element.getElement().getContent(true);
   if (content == null) {
     throw new IllegalStateException("No content available for parsing");
   }
   try {
     return valueType.parse(content);
   } catch (Exception e) {
     if (e instanceof TypeConversionException) {
       throw (TypeConversionException) e;
     } else {
       throw new TypeConversionException(
           element.getElement().getLocation(), e, "Could not parse string value " + content);
     }
   }
 }
예제 #12
0
 /**
  * Adds each element of {@code elements} to the {@code ImmutableMultiset}.
  *
  * @param elements the {@code Iterable} to add to the {@code ImmutableMultiset}
  * @return this {@code Builder} object
  * @throws NullPointerException if {@code elements} is null or contains a null element
  */
 @Override
 public Builder<E> addAll(Iterable<? extends E> elements) {
   if (elements instanceof Multiset) {
     Multiset<? extends E> multiset = Multisets.cast(elements);
     for (Entry<? extends E> entry : multiset.entrySet()) {
       addCopies(entry.getElement(), entry.getCount());
     }
   } else {
     super.addAll(elements);
   }
   return this;
 }
예제 #13
0
 @Override
 public boolean contains(Object o) {
   if (o instanceof Entry) {
     Entry<?> entry = (Entry<?>) o;
     if (entry.getCount() <= 0) {
       return false;
     }
     int count = multiset.count(entry.getElement());
     return count == entry.getCount();
   }
   return false;
 }
예제 #14
0
 @SuppressWarnings("unchecked")
 SerializedForm(SortedMultiset<E> multiset) {
   this.comparator = multiset.comparator();
   int n = multiset.entrySet().size();
   elements = (E[]) new Object[n];
   counts = new int[n];
   int i = 0;
   for (Entry<E> entry : multiset.entrySet()) {
     elements[i] = entry.getElement();
     counts[i] = entry.getCount();
     i++;
   }
 }
예제 #15
0
 public N next(Set<N> names) throws StaxNavException {
   if (names == null) {
     throw new NullPointerException();
   }
   Entry next = current.next(depth);
   if (next != null) {
     N name = naming.getName(next.getElement().getName());
     if (names.contains(name)) {
       current = next;
       return name;
     }
   }
   return null;
 }
예제 #16
0
 public String getAttribute(QName name)
     throws NullPointerException, IllegalStateException, StaxNavException {
   if (name == null) {
     throw new NullPointerException("No null attribute name expected");
   }
   if (XMLConstants.NULL_NS_URI.equals(name.getNamespaceURI())) {
     return getAttribute(name.getLocalPart());
   } else {
     Map<QName, String> qualifiedAttributes = current.getElement().getQualifiedAttributes();
     if (qualifiedAttributes.isEmpty()) {
       return null;
     } else {
       return qualifiedAttributes.get(name);
     }
   }
 }
예제 #17
0
 public Map<QName, String> getQualifiedAttributes()
     throws NullPointerException, IllegalStateException, StaxNavException {
   Map<QName, String> qualifiedAttributes = current.getElement().getQualifiedAttributes();
   Map<String, String> attributes = getAttributes();
   if (!attributes.isEmpty()) {
     if (qualifiedAttributes.isEmpty()) {
       qualifiedAttributes = new HashMap<QName, String>(qualifiedAttributes);
     }
     for (String key : attributes.keySet()) {
       qualifiedAttributes.put(new QName(key), attributes.get(key));
     }
   }
   if (qualifiedAttributes.isEmpty()) {
     return Collections.emptyMap();
   } else {
     return qualifiedAttributes;
   }
 }
예제 #18
0
 private Entry _following(Entry current, N name) throws StaxNavException {
   if (name == null) {
     throw new UnsupportedOperationException("todo");
   }
   if (current != null) {
     Entry entry = current.next();
     while (entry != null) {
       N findName = naming.getName(entry.getElement().getName());
       if (name.equals(findName)) {
         current = entry;
         return current;
       } else {
         entry = entry.next();
       }
     }
   }
   return null;
 }
예제 #19
0
  static <E> ImmutableMultiset<E> copyFromEntries(
      Collection<? extends Entry<? extends E>> entries) {
    long size = 0;
    ImmutableMap.Builder<E, Integer> builder = ImmutableMap.builder();
    for (Entry<? extends E> entry : entries) {
      int count = entry.getCount();
      if (count > 0) {
        // Since ImmutableMap.Builder throws an NPE if an element is null, no
        // other null checks are needed.
        builder.put(entry.getElement(), count);
        size += count;
      }
    }

    if (size == 0) {
      return of();
    }
    return new RegularImmutableMultiset<E>(builder.build(), Ints.saturatedCast(size));
  }
예제 #20
0
 private static <E> ImmutableSortedMultiset<E> copyOfSortedEntries(
     Comparator<? super E> comparator, Collection<Entry<E>> entries) {
   if (entries.isEmpty()) {
     return emptyMultiset(comparator);
   }
   ImmutableList.Builder<E> elementsBuilder = new ImmutableList.Builder<E>(entries.size());
   long[] cumulativeCounts = new long[entries.size() + 1];
   int i = 0;
   for (Entry<E> entry : entries) {
     elementsBuilder.add(entry.getElement());
     cumulativeCounts[i + 1] = cumulativeCounts[i] + entry.getCount();
     i++;
   }
   return new RegularImmutableSortedMultiset<E>(
       new RegularImmutableSortedSet<E>(elementsBuilder.build(), comparator),
       cumulativeCounts,
       0,
       entries.size());
 }
예제 #21
0
 @Override
 public boolean equals(@Nullable Object object) {
   if (object == this) {
     return true;
   }
   if (object instanceof Multiset) {
     Multiset<?> that = (Multiset<?>) object;
     if (this.size() != that.size()) {
       return false;
     }
     for (Entry<?> entry : that.entrySet()) {
       if (count(entry.getElement()) != entry.getCount()) {
         return false;
       }
     }
     return true;
   }
   return false;
 }
예제 #22
0
 public String getContent() throws StaxNavException {
   return current.getElement().getContent(trimContent);
 }
예제 #23
0
 public int getDepth() throws StaxNavException {
   return current.getElement().getDepth();
 }
예제 #24
0
 public Location getLocation() throws StaxNavException {
   return current.getElement().getLocation();
 }
예제 #25
0
 public QName getQName() throws StaxNavException {
   return current.getElement().getName();
 }
예제 #26
0
 public String getLocalName() throws StaxNavException {
   return current.getElement().getName().getLocalPart();
 }
예제 #27
0
 public N getName() throws StaxNavException {
   return current.getElement().getName(naming);
 }
예제 #28
0
 private StaxNavigatorImpl(Naming<N> naming, Entry current, boolean trimContent) {
   this.naming = naming;
   this.current = current;
   this.depth = current.getElement().getDepth();
   this.trimContent = trimContent;
 }
예제 #29
0
 public String getNamespaceByPrefix(String prefix) throws NullPointerException, StaxNavException {
   if (prefix == null) {
     throw new NullPointerException();
   }
   return current.getElement().getNamespaceByPrefix(prefix);
 }