Java Code Examples for java.util.TreeSet#higher()

The following examples show how to use java.util.TreeSet#higher() . 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: TreeSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testHigher() {
    TreeSet q = set5();
    Object e1 = q.higher(three);
    assertEquals(four, e1);

    Object e2 = q.higher(zero);
    assertEquals(one, e2);

    Object e3 = q.higher(five);
    assertNull(e3);

    Object e4 = q.higher(six);
    assertNull(e4);
}
 
Example 2
Source File: CirculinearCurves2D.java    From javaGeom with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns either the next value, or the first value of the tree if the
 * given value is the last one of the tree.
 */
private static double nextValue(TreeSet<Double> tree, double value) {
	if (tree.higher(value) == null)
		return tree.first();
	else
		return tree.higher(value);
}
 
Example 3
Source File: RegExExecutor.java    From succinct with Apache License 2.0 5 votes vote down vote up
/**
 * Computes the regular expression wildcard using the results from two regex sub-expressions.
 *
 * @param left     A set of (offset, length) pairs (END_SORTED).
 * @param right    A set of (offset, length) pairs (FRONT_SORTED).
 * @param sortType Sorting type for the returned set.
 * @return A set of (offset, length) pairs.
 */
protected TreeSet<RegExMatch> regexWildcard(TreeSet<RegExMatch> left, TreeSet<RegExMatch> right,
  SortType sortType) {

  TreeSet<RegExMatch> wildcardRes = allocateSet(sortType);

  Iterator<RegExMatch> leftIterator = left.iterator();
  RegExMatch lowerBoundEntry = new RegExMatch(0, 0);
  while (leftIterator.hasNext()) {
    RegExMatch leftEntry = leftIterator.next();
    lowerBoundEntry.setOffset(leftEntry.end());
    RegExMatch rightEntry = right.ceiling(lowerBoundEntry);

    if (rightEntry == null)
      break;

    // Greedy match
    RegExMatch lastMatch = null;
    while (rightEntry != null && succinctFile
      .sameRecord(leftEntry.getOffset(), rightEntry.getOffset())) {
      lastMatch = rightEntry;
      rightEntry = right.higher(rightEntry);
    }

    if (lastMatch != null) {
      long distance = lastMatch.getOffset() - leftEntry.getOffset();
      wildcardRes
        .add(new RegExMatch(leftEntry.getOffset(), (int) distance + lastMatch.getLength()));
      while (leftIterator.hasNext() && leftEntry.getOffset() < lastMatch.getOffset()) {
        leftEntry = leftIterator.next();
      }
    }
  }

  return wildcardRes;
}
 
Example 4
Source File: TreeSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testHigher() {
    TreeSet q = set5();
    Object e1 = q.higher(three);
    assertEquals(four, e1);

    Object e2 = q.higher(zero);
    assertEquals(one, e2);

    Object e3 = q.higher(five);
    assertNull(e3);

    Object e4 = q.higher(six);
    assertNull(e4);
}
 
Example 5
Source File: ConfigSampler.java    From bestconf with Apache License 2.0 4 votes vote down vote up
private static ArrayList<Attribute> scaleDownNeighbordists(Instances previousSet, Instance center){
	ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
	int attNum = center.numAttributes();
	
	int pos = -1;
	if(previousSet.attribute(PerformanceAttName)!=null)
		pos = previousSet.attribute(PerformanceAttName).index();
	
	//traverse each dimension
	Enumeration<Instance> enu;
	double[] minDists = new double[2];
	double val;
	for(int i=0;i<attNum;i++){
		if(i==pos)
			continue;
		
		enu = previousSet.enumerateInstances();
		minDists[0] = 1-Double.MAX_VALUE;
		minDists[1] = Double.MAX_VALUE;
		
		while(enu.hasMoreElements()){
			Instance ins = enu.nextElement();
			if(!ins.equals(center)){
				val = ins.value(i)-center.value(i);
				if(val<0)
					minDists[0] = Math.max((double)((int)((ins.value(i)-center.value(i))*1000))/1000.0, minDists[0]);
				else
					minDists[1] = Math.min((double)((int)((ins.value(i)-center.value(i))*1000))/1000.0, minDists[1]);
			}
		}
		
		//now we set the range
		Properties p1 = new Properties();
		double upper = center.value(i)+minDists[1], lower=center.value(i)+minDists[0];
		
		TreeSet<Double> detourSet = new TreeSet<Double>();
		detourSet.add(upper);
		detourSet.add(lower);
		detourSet.add(previousSet.attribute(i).getUpperNumericBound());
		detourSet.add(previousSet.attribute(i).getLowerNumericBound());
		switch(detourSet.size()){
		case 1:
			upper=lower=detourSet.first();
			break;
		case 2:
			upper = detourSet.last();
			lower = detourSet.first();
			break;
		case 3:
			upper=lower=detourSet.higher(detourSet.first());
			break;
		default://case 4:
			upper=detourSet.lower(detourSet.last());
			lower=detourSet.higher(detourSet.first());
			break;
		}
		
		p1.setProperty("range", "["+String.valueOf(lower)+","+String.valueOf(upper)+"]");
		ProtectedProperties prop1 = new ProtectedProperties(p1);
		
		localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1));
	}
	
	return localAtts;
}
 
Example 6
Source File: ConfigSampler.java    From bestconf with Apache License 2.0 4 votes vote down vote up
private static ArrayList<Attribute> scaleDownMindists(Instances previousSet, Instance center){
	ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
	int attNum = center.numAttributes();
	
	int pos = previousSet.attribute(PerformanceAttName).index();
	
	//traverse each dimension
	Enumeration<Instance> enu;
	double minDis;
	for(int i=0;i<attNum;i++){
		if(i==pos)
			continue;
		
		enu = previousSet.enumerateInstances();
		minDis = Double.MAX_VALUE;
		
		while(enu.hasMoreElements()){
			Instance ins = enu.nextElement();
			if(!ins.equals(center))
				minDis = Math.min((double)((int)(Math.abs(ins.value(i)-center.value(i))*1000))/1000.0, minDis);
		}
		
		//now we set the range
		Properties p1 = new Properties();
		double upper = center.value(i)+minDis, lower=center.value(i)-minDis;
		
		TreeSet<Double> detourSet = new TreeSet<Double>();
		detourSet.add(upper);
		detourSet.add(lower);
		detourSet.add(previousSet.attribute(i).getUpperNumericBound());
		detourSet.add(previousSet.attribute(i).getLowerNumericBound());
		switch(detourSet.size()){
		case 1:
			upper=lower=detourSet.first();
			break;
		case 2:
			upper = detourSet.last();
			lower = detourSet.first();
			break;
		case 3:
			upper=lower=detourSet.higher(detourSet.first());
			break;
		default://case 4:
			upper=detourSet.lower(detourSet.last());
			lower=detourSet.higher(detourSet.first());
			break;
		}
		
		p1.setProperty("range", "["+String.valueOf(lower)+","+String.valueOf(upper)+"]");
		ProtectedProperties prop1 = new ProtectedProperties(p1);
		
		localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1));
	}
	
	return localAtts;
}
 
Example 7
Source File: BestConf.java    From bestconf with Apache License 2.0 4 votes vote down vote up
public static ArrayList<Attribute> scaleDownDetour(Instances previousSet, Instance center){
	ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
	int attNum = center.numAttributes();
	
	int pos = previousSet.attribute(PerformanceAttName).index();
	
	//traverse each dimension
	Enumeration<Instance> enu;
	double minDis;
	for(int i=0;i<attNum;i++){
		if(i==pos)
			continue;
		
		enu = previousSet.enumerateInstances();
		minDis = Double.MAX_VALUE;
		
		while(enu.hasMoreElements()){
			Instance ins = enu.nextElement();
			if(!ins.equals(center))
				minDis = Math.min((double)((int)(Math.abs(ins.value(i)-center.value(i))*100))/100.0, minDis);
		}
		
		//now we set the range
		Properties p1 = new Properties();
		double upper = center.value(i)+minDis, lower=center.value(i)-minDis;
		
		TreeSet<Double> detourSet = new TreeSet<Double>();
		detourSet.add(upper);
		detourSet.add(lower);
		detourSet.add(previousSet.attribute(i).getUpperNumericBound());
		detourSet.add(previousSet.attribute(i).getLowerNumericBound());
		switch(detourSet.size()){
		case 1:
			upper=lower=detourSet.first();
			break;
		case 2:
			upper = detourSet.last();
			lower = detourSet.first();
			break;
		case 3:
			upper=lower=detourSet.higher(detourSet.first());
			break;
		default://case 4:
			upper=detourSet.lower(detourSet.last());
			lower=detourSet.higher(detourSet.first());
			break;
		}
		
		p1.setProperty("range", "["+String.valueOf(lower)+","+String.valueOf(upper)+"]");
		ProtectedProperties prop1 = new ProtectedProperties(p1);
		
		localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1));
	}
	
	return localAtts;
}
 
Example 8
Source File: SyncService.java    From btrbck with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculate the next available snapshot after the given snapshot, or null
 * if none is available
 */
Integer calculateNextSnapshotNr(Snapshot snapshot,
        TreeSet<Integer> availableCloneSources) {
    return availableCloneSources.higher(snapshot.nr);
}