Java Code Examples for java.util.PrimitiveIterator.OfInt#nextInt()

The following examples show how to use java.util.PrimitiveIterator.OfInt#nextInt() . 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: StringStyleUtils.java    From WeBASE-Codegen-Monkey with Apache License 2.0 5 votes vote down vote up
/**
 * 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 2
Source File: SingleValidationTask.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
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 3
Source File: GroupingRhsValidationTask.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
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 4
Source File: RhsValidationTaskImpl.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: RecordSelector.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
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 6
Source File: IntIterators.java    From bifurcan with MIT License 5 votes vote down vote up
public static boolean equals(OfInt a, OfInt b) {
  while (a.hasNext()) {
    if (a.nextInt() != b.nextInt()) {
      return false;
    }
  }
  return true;
}
 
Example 7
Source File: IntIterators.java    From bifurcan with MIT License 5 votes vote down vote up
/**
 * @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;
    }
  };
}