Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #3
0
 protected Entry next(int depth) throws StaxNavException {
   Entry next = next();
   if (next != null && next.getElement().getDepth() > depth) {
     return next;
   } else {
     return null;
   }
 }
Beispiel #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;
   }
 }
Beispiel #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);
   }
 }
Beispiel #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);
   }
 }
Beispiel #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;
 }
 @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;
 }
Beispiel #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++;
   }
 }
Beispiel #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;
 }
Beispiel #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);
     }
   }
 }
Beispiel #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;
 }
Beispiel #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;
 }
 @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++;
   }
 }
Beispiel #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;
 }
Beispiel #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);
     }
   }
 }
Beispiel #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;
   }
 }
Beispiel #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;
 }
Beispiel #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));
  }
 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());
 }
Beispiel #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;
 }
Beispiel #22
0
 public String getContent() throws StaxNavException {
   return current.getElement().getContent(trimContent);
 }
Beispiel #23
0
 public int getDepth() throws StaxNavException {
   return current.getElement().getDepth();
 }
Beispiel #24
0
 public Location getLocation() throws StaxNavException {
   return current.getElement().getLocation();
 }
Beispiel #25
0
 public QName getQName() throws StaxNavException {
   return current.getElement().getName();
 }
Beispiel #26
0
 public String getLocalName() throws StaxNavException {
   return current.getElement().getName().getLocalPart();
 }
Beispiel #27
0
 public N getName() throws StaxNavException {
   return current.getElement().getName(naming);
 }
Beispiel #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;
 }
Beispiel #29
0
 public String getNamespaceByPrefix(String prefix) throws NullPointerException, StaxNavException {
   if (prefix == null) {
     throw new NullPointerException();
   }
   return current.getElement().getNamespaceByPrefix(prefix);
 }