Java Code Examples for java.util.Iterator.next()

The following are Jave code examples for showing how to use next() of the java.util.Iterator class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: monarch   File: AmpoolSinkTaskTest.java   View Source Code Vote up 6 votes
private int getScanCount_2(MTable table, String locatorPort) {
    Scanner scanner = table.getScanner(new Scan());
    Iterator itr = scanner.iterator();
    int totalCount = 0;
    while (itr.hasNext()) {
      Row result = (Row) itr.next();

      List<Cell> selectedRow = result.getCells();

//      for (Cell cell : selectedRow) {
//        System.out.print("  [ColumnName: " + Bytes.toString(cell.getColumnName()) + " ColumnValue:"
//            + cell.getColumnValue() + "], ");
//
//      }
      totalCount++;
    }
//    System.out.println();
    return totalCount;
  }
 
Example 2
Project: Proyecto-DASI   File: ConstructorDescOrganizacion.java   View Source Code Vote up 6 votes
public void obtenerTablaComportamientosDefinidosRecursos()
	throws ExcepcionEnComponente {
                      DescRecursoAplicacion desc;
          Iterator<DescRecursoAplicacion> iter = this.descOrganizacion.getDescripcionComponentes()
                                                     .getDescRecursosAplicacion().getDescRecursoAplicacion().iterator();
while (iter.hasNext()) {
	desc = iter.next();
                      String identComportamiento = desc.getNombre();
                      // verificamos que el comportamiento no esta repetido
                      if (tablaComportamientosDefinidos.containsKey(identComportamiento) ){
                          throw new ExcepcionEnComponente(
		"El comportamiento de nombre "
				+ identComportamiento
				+ " esta duplicado : Comprobar la descripcion de la organizacion");
                          } else
                              tablaComportamientosDefinidos.put(identComportamiento, desc);
                  }
       }
 
Example 3
Project: s-store   File: TransactionProfilerStats.java   View Source Code Vote up 6 votes
@Override
protected Iterator<Object> getStatsRowKeyIterator(boolean interval) {
    final Iterator<Procedure> it = this.procStats.keySet().iterator();
    return new Iterator<Object>() {
        @Override
        public boolean hasNext() {
            return it.hasNext();
        }
        @Override
        public Object next() {
            return it.next();
        }
        @Override
        public void remove() {
            it.remove();
        }
    };
}
 
Example 4
Project: s-store   File: Multisets.java   View Source Code Vote up 6 votes
/**
 * Delegate implementation which cares about the element type.
 */
private static <E> boolean retainOccurrencesImpl(
    Multiset<E> multisetToModify, Multiset<?> occurrencesToRetain) {
  checkNotNull(multisetToModify);
  checkNotNull(occurrencesToRetain);
  // Avoiding ConcurrentModificationExceptions is tricky.
  Iterator<Entry<E>> entryIterator = multisetToModify.entrySet().iterator();
  boolean changed = false;
  while (entryIterator.hasNext()) {
    Entry<E> entry = entryIterator.next();
    int retainCount = occurrencesToRetain.count(entry.getElement());
    if (retainCount == 0) {
      entryIterator.remove();
      changed = true;
    } else if (retainCount < entry.getCount()) {
      multisetToModify.setCount(entry.getElement(), retainCount);
      changed = true;
    }
  }
  return changed;
}
 
Example 5
Project: ZooKeeper   File: MultiTransactionRecord.java   View Source Code Vote up 6 votes
@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof MultiTransactionRecord)) return false;

    MultiTransactionRecord that = (MultiTransactionRecord) o;

    if (ops != null) {
        Iterator<Op> other = that.ops.iterator();
        for (Op op : ops) {
            boolean hasMoreData = other.hasNext();
            if (!hasMoreData) {
                return false;
            }
            Op otherOp = other.next();
            if (!op.equals(otherOp)) {
                return false;
            }
        }
        return !other.hasNext();
    } else {
        return that.ops == null;
    }

}
 
Example 6
Project: tuxguitar   File: MidiPlayer.java   View Source Code Vote up 6 votes
public List<MidiOutputPort> listOutputPorts() {
	try {
		this.lock();
		
		List<MidiOutputPort> ports = new ArrayList<MidiOutputPort>();
		Iterator<MidiOutputPortProvider> it = this.outputPortProviders.iterator();
		while(it.hasNext()){
			try{
				MidiOutputPortProvider provider = (MidiOutputPortProvider)it.next();
				ports.addAll(provider.listPorts());
			}catch(Throwable throwable){
				throwable.printStackTrace();
			}
		}
		return ports;
	} finally {
		this.unlock();
	}
}
 
Example 7
Project: openjdk-jdk10   File: ConcurrentSkipListSubSetTest.java   View Source Code Vote up 5 votes
/**
 * subSet returns set with keys in requested range
 */
public void testDescendingSubSetContents() {
    NavigableSet set = dset5();
    SortedSet sm = set.subSet(m2, m4);
    assertEquals(m2, sm.first());
    assertEquals(m3, sm.last());
    assertEquals(2, sm.size());
    assertFalse(sm.contains(m1));
    assertTrue(sm.contains(m2));
    assertTrue(sm.contains(m3));
    assertFalse(sm.contains(m4));
    assertFalse(sm.contains(m5));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(m2, k);
    k = (Integer)(i.next());
    assertEquals(m3, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(m2));
    assertEquals(4, set.size());
    assertEquals(1, sm.size());
    assertEquals(m3, sm.first());
    assertEquals(m3, sm.last());
    assertTrue(sm.remove(m3));
    assertTrue(sm.isEmpty());
    assertEquals(3, set.size());
}
 
Example 8
Project: Random-Music-Generator   File: TrackFactory.java   View Source Code Vote up 5 votes
/**
 * Iterates through a Song and adds every Part on a new channel of the given track
 * @param song
 * @param track
 * @param counter
 */
private void SongIteration(Song song, Track track, long counter){
	Iterator<Part> partsIterator = song.iterator();
	byte channel = 1;
	while(partsIterator.hasNext()){
		Part part = partsIterator.next();
		eventMaking(counter, track, part, channel);
		channel++;
	}
}
 
Example 9
Project: parabuild-ci   File: AbstractUsageCheck.java   View Source Code Vote up 5 votes
/**
 * Applies this check to a set of nodes.
 * @param aNodes the nodes to check.
 */
public void applyTo(Set aNodes)
{
    final Iterator it = aNodes.iterator();
    while (it.hasNext()) {
        final DetailAST nameAST = (DetailAST) it.next();
        if (getReferenceCount(nameAST) == 1) {
            log(
                nameAST.getLineNo(),
                nameAST.getColumnNo(),
                getErrorKey(),
                nameAST.getText());
        }
    }
}
 
Example 10
Project: lams   File: JsonTreeReader.java   View Source Code Vote up 5 votes
@Override public String nextName() throws IOException {
  expect(JsonToken.NAME);
  Iterator<?> i = (Iterator<?>) peekStack();
  Map.Entry<?, ?> entry = (Map.Entry<?, ?>) i.next();
  stack.add(entry.getValue());
  return (String) entry.getKey();
}
 
Example 11
Project: Tarski   File: mxHierarchicalLayout.java   View Source Code Vote up 5 votes
/**
 *
 * @param cell
 * @return
 */
public Object[] getEdges(final Object cell) {
  final mxIGraphModel model = this.graph.getModel();
  final boolean isCollapsed = this.graph.isCellCollapsed(cell);
  final List<Object> edges = new ArrayList<Object>();
  final int childCount = model.getChildCount(cell);

  for (int i = 0; i < childCount; i++) {
    final Object child = model.getChildAt(cell, i);

    if (isCollapsed || !this.graph.isCellVisible(child)) {
      edges.addAll(Arrays.asList(mxGraphModel.getEdges(model, child, true, true, false)));
    }
  }

  edges.addAll(Arrays.asList(mxGraphModel.getEdges(model, cell, true, true, false)));
  final List<Object> result = new ArrayList<Object>(edges.size());
  final Iterator<Object> it = edges.iterator();

  while (it.hasNext()) {
    final Object edge = it.next();
    final mxCellState state = this.graph.getView().getState(edge);
    final Object source = state != null ? state.getVisibleTerminal(true)
        : this.graph.getView().getVisibleTerminal(edge, true);
    final Object target = state != null ? state.getVisibleTerminal(false)
        : this.graph.getView().getVisibleTerminal(edge, false);

    if (source != target && (target == cell
        && (this.parent == null
            || this.graph.isValidAncestor(source, this.parent, this.traverseAncestors))
        || source == cell && (this.parent == null
            || this.graph.isValidAncestor(target, this.parent, this.traverseAncestors)))) {
      result.add(edge);
    }
  }

  return result.toArray();
}
 
Example 12
Project: guava-mock   File: ImmutableList.java   View Source Code Vote up 5 votes
/**
 * Returns an immutable list containing the given elements, in order.
 *
 * @throws NullPointerException if any of {@code elements} is null
 */
public static <E> ImmutableList<E> copyOf(Iterator<? extends E> elements) {
  // We special-case for 0 or 1 elements, but going further is madness.
  if (!elements.hasNext()) {
    return of();
  }
  E first = elements.next();
  if (!elements.hasNext()) {
    return of(first);
  } else {
    return new ImmutableList.Builder<E>().add(first).addAll(elements).build();
  }
}
 
Example 13
Project: sstore-soft   File: Iterators.java   View Source Code Vote up 5 votes
/**
 * Combines multiple iterators into a single iterator. The returned iterator
 * iterates across the elements of each iterator in {@code inputs}. The input
 * iterators are not polled until necessary.
 *
 * <p>The returned iterator supports {@code remove()} when the corresponding
 * input iterator supports it. The methods of the returned iterator may throw
 * {@code NullPointerException} if any of the input iterators is null.
 *
 * <p><b>Note:</b> the current implementation is not suitable for nested
 * concatenated iterators, i.e. the following should be avoided when in a loop:
 * {@code iterator = Iterators.concat(iterator, suffix);}, since iteration over the
 * resulting iterator has a cubic complexity to the depth of the nesting.
 */
public static <T> Iterator<T> concat(
    final Iterator<? extends Iterator<? extends T>> inputs) {
  checkNotNull(inputs);
  return new Iterator<T>() {
    Iterator<? extends T> current = emptyIterator();
    Iterator<? extends T> removeFrom;

    @Override
    public boolean hasNext() {
      // http://code.google.com/p/google-collections/issues/detail?id=151
      // current.hasNext() might be relatively expensive, worth minimizing.
      boolean currentHasNext;
      // checkNotNull eager for GWT
      // note: it must be here & not where 'current' is assigned,
      // because otherwise we'll have called inputs.next() before throwing
      // the first NPE, and the next time around we'll call inputs.next()
      // again, incorrectly moving beyond the error.
      while (!(currentHasNext = checkNotNull(current).hasNext())
          && inputs.hasNext()) {
        current = inputs.next();
      }
      return currentHasNext;
    }
    @Override
    public T next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      removeFrom = current;
      return current.next();
    }
    @Override
    public void remove() {
      checkRemove(removeFrom != null);
      removeFrom.remove();
      removeFrom = null;
    }
  };
}
 
Example 14
Project: parabuild-ci   File: AccurevChangeLogParser.java   View Source Code Vote up 5 votes
public List parseChangeLog(final File logFile) throws MalformedURLException, DocumentException {
    final List result = new ArrayList(11);
    final SAXReader saxReader = new SAXReader();
    final Document document = saxReader.read(logFile);
    final Element rootElement = document.getRootElement();
//    if (LOG.isDebugEnabled()) {
//      LOG.debug("rootElement: " + rootElement);
//    }
    // Iterate transactions
    int changeListCounter = 0;
    final Iterator iter = rootElement.elementIterator();
    while (iter.hasNext() && changeListCounter++ < maxChangeLists) {
      final Element transactionElement = (Element) iter.next();
      if (!transactionElement.getName().equals("transaction")) {
        continue;
      }
//      if (LOG.isDebugEnabled()) {
//        LOG.debug("transactionElement: " + transactionElement);
//      }
      // Create change list
      final String type = transactionElement.attributeValue("type");
      final byte changeType = toChangeType(type);
      if (changeType == Change.TYPE_UNKNOWN) {
        continue;
      }
      final String id = transactionElement.attributeValue("id");
      final String time = transactionElement.attributeValue("time");
      final String user = transactionElement.attributeValue("user");
      final Element elementComment = transactionElement.element("comment");
      final String comment = elementComment.getText();
      final ChangeList changeList = new ChangeList();
      changeList.setCreatedAt(new Date(Long.parseLong(time) * 1000L));
      changeList.setDescription(comment);
      changeList.setNumber(id);
      changeList.setUser(user);
      // Iterate versions
      int changeCounter = 0;
      final Set changes = new HashSet(11);
      final Iterator versionIter = transactionElement.elementIterator("version");
      while (versionIter.hasNext() && changeCounter++ < maxChangeListSize) {
        final Element versionElement = (Element) versionIter.next();
        final String path = versionElement.attributeValue("path");
        final String version = versionElement.attributeValue("virtualNamedVersion");
        final Change change = new Change(path, version, changeType);
        changes.add(change);
      }
      changeList.setChanges(changes);
      // Add to result
      result.add(changeList);
    }
    return result;
  }
 
Example 15
Project: OpenJSharp   File: MimeMultipartParser.java   View Source Code Vote up 5 votes
@Override
public Iterator<MimeHeader> getMimeHeaders() {
    final Iterator<? extends Header> ih = part.getAllHeaders()
            .iterator();
    return new Iterator<MimeHeader>() {
        @Override
        public boolean hasNext() {
            return ih.hasNext();
        }

        @Override
        public MimeHeader next() {
            final Header hdr = ih.next();
            return new AttachmentEx.MimeHeader() {
                @Override
                public String getValue() {
                    return hdr.getValue();
                }
                @Override
                public String getName() {
                    return hdr.getName();
                }
            };
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example 16
Project: TechnicalAnalysisTool   File: ChartCanvasPane.java   View Source Code Vote up 5 votes
/**
 * Get {@link RSDCanvas} of this object
 * @return {@link RSDCanvas} or null if it is not found
 */
public RSDCanvas getRSDCanvas() {
    Iterator<ChartPane> it = chartPaneList.iterator();
    while (it.hasNext()) {
        ChartPane chartPane = it.next();
        if (chartPane.getBaseCanvas() instanceof RSDCanvas){
            return (RSDCanvas)chartPane.getBaseCanvas();
        }
    } 
    return null;        
}
 
Example 17
Project: crnk-framework   File: ExceptionMapperHelper.java   View Source Code Vote up 5 votes
public static String createErrorMessage(ErrorResponse errorResponse) {
	Iterator<ErrorData> errors = errorResponse.getErrors().iterator();
	String message = null;
	if (errors.hasNext()) {
		ErrorData data = errors.next();
		message = data.getCode();
	}
	return message;
}
 
Example 18
Project: monarch   File: CompiledJunction.java   View Source Code Vote up 4 votes
/** invariant: the operand is known to be evaluated by iteration */
SelectResults auxIterateEvaluate(CompiledValue operand, ExecutionContext context,
    SelectResults intermediateResults) throws FunctionDomainException, TypeMismatchException,
    NameResolutionException, QueryInvocationTargetException {
  // Asif: This can be a valid value if we have an AND condition like ID=1 AND
  // true = true. In such cases , if an index is not available on ID still we
  // have at least one expression which is independent of current scope. In
  // such cases a value of null means ignore the null ( because it means all
  // the results ) thus a the result-set of current auxIterate which will be
  // the subset of total result-set , will be the right data.

  // auxIterEvalaute can be called only from an AND junction.

  // This also implies that there will be at least one operand which will be
  // evaluated using auxFilterEvaluate.Thus the result-set given to this
  // function can be empty ( obtained using auxFilterEvaluate ,meaning no need
  // to do iterations below ) but it can never be null. As null itself
  // signifies that the junction cannot be evaluated as a filter.
  if (intermediateResults == null)
    throw new RuntimeException(
        LocalizedStrings.CompiledJunction_INTERMEDIATERESULTS_CAN_NOT_BE_NULL
            .toLocalizedString());
  if (intermediateResults.isEmpty()) // short circuit
    return intermediateResults;
  List currentIters = context.getCurrentIterators();
  RuntimeIterator rIters[] = new RuntimeIterator[currentIters.size()];
  currentIters.toArray(rIters);
  ObjectType elementType = intermediateResults.getCollectionType().getElementType();
  SelectResults resultSet;
  if (elementType.isStructType()) {
    resultSet = QueryUtils.createStructCollection(context, (StructTypeImpl) elementType);
  } else {
    resultSet = QueryUtils.createResultCollection(context, elementType);
  }


  QueryObserver observer = QueryObserverHolder.getInstance();
  try {
    observer.startIteration(intermediateResults, operand);
    Iterator iResultsIter = intermediateResults.iterator();
    while (iResultsIter.hasNext()) {
      Object tuple = iResultsIter.next();
      if (tuple instanceof Struct) {
        Object values[] = ((Struct) tuple).getFieldValues();
        for (int i = 0; i < values.length; i++) {
          rIters[i].setCurrent(values[i]);
        }
      } else {
        rIters[0].setCurrent(tuple);
      }
      Object result = null;
      try {
        result = operand.evaluate(context);
      } finally {
        observer.afterIterationEvaluation(result);
      }
      if (result instanceof Boolean) {
        if (((Boolean) result).booleanValue())
          resultSet.add(tuple);
      } else if (result != null && result != QueryService.UNDEFINED)
        throw new TypeMismatchException(
            LocalizedStrings.CompiledJunction_ANDOR_OPERANDS_MUST_BE_OF_TYPE_BOOLEAN_NOT_TYPE_0
                .toLocalizedString(result.getClass().getName()));
    }
  } finally {
    observer.endIteration(resultSet);
  }
  return resultSet;
}
 
Example 19
Project: sstore-soft   File: Maps.java   View Source Code Vote up 3 votes
/**
 * Returns an immutable map for which the {@link Map#values} are the given
 * elements in the given order, and each key is the product of invoking a
 * supplied function on its corresponding value.
 *
 * @param values the values to use when constructing the {@code Map}
 * @param keyFunction the function used to produce the key for each value
 * @return a map mapping the result of evaluating the function {@code
 *         keyFunction} on each value in the input collection to that value
 * @throws IllegalArgumentException if {@code keyFunction} produces the same
 *         key for more than one value in the input collection
 * @throws NullPointerException if any elements of {@code values} is null, or
 *         if {@code keyFunction} produces {@code null} for any value
 * @since 10.0
 */
public static <K, V> ImmutableMap<K, V> uniqueIndex(
    Iterator<V> values, Function<? super V, K> keyFunction) {
  checkNotNull(keyFunction);
  ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
  while (values.hasNext()) {
    V value = values.next();
    builder.put(keyFunction.apply(value), value);
  }
  return builder.build();
}
 
Example 20
Project: sstore-soft   File: Multimaps.java   View Source Code Vote up 3 votes
/**
 * Creates an index {@code ImmutableListMultimap} that contains the results of
 * applying a specified function to each item in an {@code Iterator} of
 * values. Each value will be stored as a value in the resulting multimap,
 * yielding a multimap with the same size as the input iterator. The key used
 * to store that value in the multimap will be the result of calling the
 * function on that value. The resulting multimap is created as an immutable
 * snapshot. In the returned multimap, keys appear in the order they are first
 * encountered, and the values corresponding to each key appear in the same
 * order as they are encountered.
 *
 * <p>For example, <pre>   {@code
 *
 *   List<String> badGuys =
 *       Arrays.asList("Inky", "Blinky", "Pinky", "Pinky", "Clyde");
 *   Function<String, Integer> stringLengthFunction = ...;
 *   Multimap<Integer, String> index =
 *       Multimaps.index(badGuys.iterator(), stringLengthFunction);
 *   System.out.println(index);}</pre>
 *
 * <p>prints <pre>   {@code
 *
 *   {4=[Inky], 6=[Blinky], 5=[Pinky, Pinky, Clyde]}}</pre>
 *
 * <p>The returned multimap is serializable if its keys and values are all
 * serializable.
 *
 * @param values the values to use when constructing the {@code
 *     ImmutableListMultimap}
 * @param keyFunction the function used to produce the key for each value
 * @return {@code ImmutableListMultimap} mapping the result of evaluating the
 *     function {@code keyFunction} on each value in the input collection to
 *     that value
 * @throws NullPointerException if any of the following cases is true:
 *     <ul>
 *     <li>{@code values} is null
 *     <li>{@code keyFunction} is null
 *     <li>An element in {@code values} is null
 *     <li>{@code keyFunction} returns {@code null} for any element of {@code
 *         values}
 *     </ul>
 * @since 10.0
 */
public static <K, V> ImmutableListMultimap<K, V> index(
    Iterator<V> values, Function<? super V, K> keyFunction) {
  checkNotNull(keyFunction);
  ImmutableListMultimap.Builder<K, V> builder
      = ImmutableListMultimap.builder();
  while (values.hasNext()) {
    V value = values.next();
    checkNotNull(value, values);
    builder.put(keyFunction.apply(value), value);
  }
  return builder.build();
}