Java Code Examples for java.util.PrimitiveIterator.OfInt#hasNext()
The following examples show how to use
java.util.PrimitiveIterator.OfInt#hasNext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomIndexStreamTest.java From jenetics with Apache License 2.0 | 6 votes |
@Test public void reference() { final int size = 5000; final double p = 0.5; final Random random1 = new Random(0); final Random random2 = new Random(0); for (int j = 0; j < 1; ++j) { final OfInt it = indexes(random1, size, p).iterator(); final IndexStream stream2 = ReferenceRandomStream( size, p, random2 ); while (it.hasNext()) { Assert.assertEquals(it.nextInt(), stream2.next()); } Assert.assertFalse(it.hasNext()); Assert.assertEquals(stream2.next(), -1); } }
Example 2
Source File: StringStyleUtils.java From WeBASE-Codegen-Monkey with Apache License 2.0 | 5 votes |
/** * underline -> camel e.g. __a_bc_d__e_ -> _ABcD_E_ * * @param str * @return */ public static String underline2upper(String str) { StringBuilder sb = new StringBuilder(); boolean mode = false; IntStream intStream = str.chars(); OfInt iterator = intStream.iterator(); while (iterator.hasNext()) { int c = iterator.nextInt(); char cc = (char) c; if (mode) { if (cc >= 'a' && cc <= 'z') { sb.append(((char) (cc - 32))); mode = false; continue; } if (cc == '_') { sb.append('_'); continue; } sb.append((char) cc); mode = false; } else { if (cc == '_') { mode = true; } else { sb.append((char) cc); } } } if (mode) { sb.append('_'); } return sb.toString(); }
Example 3
Source File: SingleValidationTask.java From metanome-algorithms with Apache License 2.0 | 5 votes |
private Iterable<int[]> getRecords(IntCollection leftMatches) { int size = leftMatches.size(); Collection<int[]> left = new ArrayList<>(size); OfInt it = leftMatches.iterator(); while (it.hasNext()) { int leftId = it.nextInt(); int[] record = leftRecords.get(leftId); left.add(record); } return left; }
Example 4
Source File: GroupingRhsValidationTask.java From metanome-algorithms with Apache License 2.0 | 5 votes |
private Int2ObjectMultimap<int[]> groupByValue(IntIterable matching) { Int2ObjectMultimap<int[]> map = new Int2ObjectHashMultimap<>(); OfInt it = matching.iterator(); while (it.hasNext()) { int id = it.nextInt(); int[] right = getRightRecord(id); int rightValue = getRightValue(right); map.put(rightValue, right); } return map; }
Example 5
Source File: RhsValidationTaskImpl.java From metanome-algorithms with Apache License 2.0 | 5 votes |
@Override public double calculateMinSimilarity(IntIterable matching) { OfInt it = matching.iterator(); //does order have an impact on runtime? while (it.hasNext() && shouldUpdate(minSimilarity)) { int id = it.nextInt(); updateMinSimilarity(id); } return minSimilarity; }
Example 6
Source File: RecordSelector.java From metanome-algorithms with Apache License 2.0 | 5 votes |
Iterable<int[]> getRecords(IntCollection ids) { int size = ids.size(); Collection<int[]> result = new ArrayList<>(size); OfInt it = ids.iterator(); while (it.hasNext()) { int id = it.nextInt(); int[] record = records.get(id); result.add(record); } return result; }
Example 7
Source File: IntIterators.java From bifurcan with MIT License | 5 votes |
public static boolean equals(OfInt a, OfInt b) { while (a.hasNext()) { if (a.nextInt() != b.nextInt()) { return false; } } return true; }
Example 8
Source File: IntIterators.java From bifurcan with MIT License | 5 votes |
/** * @param it an iterator * @param f a predicate * @return an iterator which only yields values that satisfy the predicate */ public static OfInt filter(OfInt it, IntPredicate f) { return new OfInt() { private int next = 0; private boolean primed = false; private boolean done = false; private void prime() { if (!primed && !done) { while (it.hasNext()) { next = it.nextInt(); if (f.test(next)) { primed = true; return; } } done = true; } } @Override public boolean hasNext() { prime(); return !done; } @Override public int nextInt() { prime(); if (!primed) { throw new NoSuchElementException(); } primed = false; return next; } }; }
Example 9
Source File: IntIterators.java From bifurcan with MIT License | 5 votes |
/** * @param it an iterator * @param f a function which transforms values * @return an iterator which yields the transformed values */ public static OfInt map(OfInt it, IntUnaryOperator f) { return new OfInt() { @Override public boolean hasNext() { return it.hasNext(); } @Override public int nextInt() { return f.applyAsInt(it.nextInt()); } }; }
Example 10
Source File: IntegerArrayList.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Version of forEach that doesn't box * @param action - */ public void forEach(IntConsumer action) { OfInt ii = iterator(); while (ii.hasNext()) { action.accept(ii.nextInt()); } }