Java Code Examples for java.util.TreeMap#navigableKeySet()

The following examples show how to use java.util.TreeMap#navigableKeySet() . These examples are extracted from open source projects. 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
/**
 * descending iterator of key set is inverse ordered
 */
public void testKeySetDescendingIteratorOrder() {
    TreeMap map = map5();
    NavigableSet s = map.navigableKeySet();
    Iterator i = s.descendingIterator();
    Integer last = (Integer)i.next();
    assertEquals(last, five);
    int count = 1;
    while (i.hasNext()) {
        Integer k = (Integer)i.next();
        assertTrue(last.compareTo(k) > 0);
        last = k;
        ++count;
    }
    assertEquals(5, count);
}
 
Example 2
Source Project: j2objc   File: TreeMapTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * descending iterator of key set is inverse ordered
 */
public void testKeySetDescendingIteratorOrder() {
    TreeMap map = map5();
    NavigableSet s = map.navigableKeySet();
    Iterator i = s.descendingIterator();
    Integer last = (Integer)i.next();
    assertEquals(last, five);
    int count = 1;
    while (i.hasNext()) {
        Integer k = (Integer)i.next();
        assertTrue(last.compareTo(k) > 0);
        last = k;
        ++count;
    }
    assertEquals(5, count);
}
 
Example 3
Source Project: constellation   File: IconChooser.java    License: Apache License 2.0 5 votes vote down vote up
public IconListModel(final TreeMap<String, ConstellationIcon> icons) {
    names = new ArrayList<>(icons.size());
    iconValue = new ArrayList<>(icons.size());
    for (String part : icons.navigableKeySet()) {
        names.add(part);
        iconValue.add(icons.get(part));
    }

    listeners = new ArrayList<>();
}
 
Example 4
Source Project: incubator-pinot   File: TimeSeriesUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convert the given anomaly time lines view to a tuple of TimeSeries, the first one is observed, the second one is expected
 * @param anomalyTimelinesView
 * @return
 */
public static Tuple2<TimeSeries, TimeSeries> toTimeSeries(AnomalyTimelinesView anomalyTimelinesView) {
  TimeSeries observed = new TimeSeries();
  TimeSeries expected = new TimeSeries();

  List<TimeBucket> timeBuckets = anomalyTimelinesView.getTimeBuckets();
  List<Double> observedValues = anomalyTimelinesView.getCurrentValues();
  List<Double> expectedValues = anomalyTimelinesView.getBaselineValues();
  TreeMap<TimeBucket, Tuple2<Double, Double>> sortedView = new TreeMap<>(new Comparator<TimeBucket>() {
    @Override
    public int compare(TimeBucket o1, TimeBucket o2) {
      return Long.compare(o1.getCurrentStart(), o2.getCurrentStart());
    }
  });
  for (int i = 0; i < timeBuckets.size(); i++) {
    sortedView.put(timeBuckets.get(i), new Tuple2<>(observedValues.get(i), expectedValues.get(i)));
  }

  timeBuckets = new ArrayList<>(sortedView.navigableKeySet());

  for (TimeBucket timeBucket : timeBuckets) {
    Tuple2<Double, Double> values = sortedView.get(timeBucket);
    observed.set(timeBucket.getCurrentStart(), values._1);
    expected.set(timeBucket.getCurrentStart(), values._2);
  }
  observed.setTimeSeriesInterval(
      new Interval(timeBuckets.get(0).getCurrentStart(), timeBuckets.get(timeBuckets.size()- 1).getCurrentEnd()));
  expected.setTimeSeriesInterval(
      new Interval(timeBuckets.get(0).getCurrentStart(), timeBuckets.get(timeBuckets.size()- 1).getCurrentEnd()));
  return new Tuple2<>(observed, expected);
}
 
Example 5
public TemplateListAdapter(Context context, View view, int resource) {
	mView = view;
	mSpinner = (Spinner) view.findViewById(R.id.spTemplate);

	// Get restriction categories
	TreeMap<String, String> tmRestriction = PrivacyManager.getRestrictions(context);
	listRestrictionName = new ArrayList<String>(tmRestriction.values());
	listLocalizedTitle = new ArrayList<String>(tmRestriction.navigableKeySet());

	int userId = Util.getUserId(Process.myUid());
	ondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true);
	version = new Version(Util.getSelfVersionName(context));
}
 
Example 6
private void partitionDealing(Collection<Node> instances,
    TreeMap<String, Integer> toBeReassigned, Map<Node, Set<String>> faultZonePartitionMap,
    Map<Node, Node> faultZoneMap, final Map<Node, List<String>> assignmentMap,
    final Map<Node, Float> targetPartitionCount, final int randomSeed, int targetAdjustment) {
  PriorityQueue<Node> instanceQueue =
      new PriorityQueue<>(instances.size(), new Comparator<Node>() {
        @Override
        public int compare(Node node1, Node node2) {
          int node1Load = assignmentMap.containsKey(node1) ? assignmentMap.get(node1).size() : 0;
          int node2Load = assignmentMap.containsKey(node2) ? assignmentMap.get(node2).size() : 0;
          if (node1Load == node2Load) {
            if (_mode.equals(Mode.EVENNESS)) {
              // Also consider node target load if mode is evenness
              Float node1Target = targetPartitionCount.get(node1);
              Float node2Target = targetPartitionCount.get(node2);
              if (node1Target != node2Target) {
                return node2Target.compareTo(node1Target);
              }
            }
            return new Integer((node1.getName() + randomSeed).hashCode())
                .compareTo((node2.getName() + randomSeed).hashCode());
          } else {
            return node1Load - node2Load;
          }
        }
      });
  instanceQueue.addAll(instances);

  while (!toBeReassigned.isEmpty()) {
    boolean anyPartitionAssigned = false;
    Iterator<Node> instanceIter = instanceQueue.iterator();
    while (instanceIter.hasNext()) {
      Node instance = instanceIter.next();
      // Temporary remove the node from queue.
      // If any partition assigned to the instance, add it back to reset priority.
      instanceIter.remove();
      boolean partitionAssignedToInstance = false;
      Node faultZone = faultZoneMap.get(instance);
      List<String> partitions = assignmentMap.containsKey(instance) ?
          assignmentMap.get(instance) :
          new ArrayList<String>();
      int space = instance.getWeight() <= 0 ? 0
          : (int) (Math.floor(targetPartitionCount.get(instance))) + targetAdjustment
              - partitions.size();
      if (space > 0) {
        // Find a pending partition to locate
        for (String pendingPartition : toBeReassigned.navigableKeySet()) {
          if (!faultZonePartitionMap.get(faultZone).contains(pendingPartition)) {
            if (!assignmentMap.containsKey(instance)) {
              assignmentMap.put(instance, partitions);
            }
            partitions.add(pendingPartition);
            faultZonePartitionMap.get(faultZone).add(pendingPartition);
            if (toBeReassigned.get(pendingPartition) == 1) {
              toBeReassigned.remove(pendingPartition);
            } else {
              toBeReassigned.put(pendingPartition, toBeReassigned.get(pendingPartition) - 1);
            }
            // if any assignment is made:
            // this instance can hold more partitions in the future
            partitionAssignedToInstance = true;
            break;
          }
        }
      }
      if (partitionAssignedToInstance) {
        // Reset priority in the queue
        instanceQueue.add(instance);
        anyPartitionAssigned = true;
        break;
      }
    }
    if (!anyPartitionAssigned) {
      // if no pending partition is assigned to any instances in this loop, new assignment is not possible
      break;
    }
  }
}
 
Example 7
@Override
public boolean initialize() {

       TreeMap<String, String> params = getVirtualSensorConfiguration().getMainClassInitialParams();

       //get all the models
       String model_str = params.get(PARAM_MODEL_CLASS);

       if (model_str == null) {
           logger.warn("Parameter \"" + PARAM_MODEL_CLASS + "\" not provided in Virtual Sensor file");
           return false;
       }
       
       model = model_str.trim().split(",");
       
       am = new AbstractModel[model.length];
       
       for(int i=0;i<model.length;i++){
		try {
			//instantiate the models, ...
			 Class<?>  fc = Class.forName(model[i]);
			am[i] = (AbstractModel) fc.newInstance();
			//output structure of the models is the same as the one of the VS
			am[i].setOutputFields(getVirtualSensorConfiguration().getOutputStructure());
			//...set their parameters...			
			for (String k: params.navigableKeySet())
			{
				String prefix = PARAM_MODEL_PREFIX+"."+i+".";
				if (k.startsWith(prefix)){
					am[i].setParam(k.substring(prefix.length()),params.get(k));
				}	
			}
			am[i].setVirtualSensor(this);
			//... and initialize them.
			if (! am[i].initialize()){
				return false;
			}
					
		} catch (Exception e) {
			logger.error( e.getMessage( ) , e );
			return false;
		}
       }
       return true;
}