java.util.TreeMap#navigableKeySet ( )源码实例Demo

下面列出了java.util.TreeMap#navigableKeySet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: TreeMapTest.java
/**
 * 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);
}
 
源代码2 项目: j2objc   文件: TreeMapTest.java
/**
 * 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);
}
 
源代码3 项目: constellation   文件: IconChooser.java
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<>();
}
 
源代码4 项目: incubator-pinot   文件: TimeSeriesUtils.java
/**
 * 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);
}
 
源代码5 项目: XPrivacy   文件: ActivityMain.java
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));
}
 
源代码6 项目: helix   文件: CardDealingAdjustmentAlgorithmV2.java
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;
    }
  }
}
 
源代码7 项目: gsn   文件: ModellingVirtualSensor.java
@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;
}