List of usage examples for com.google.common.collect TreeMultiset create
public static <E extends Comparable> TreeMultiset<E> create(Iterable<? extends E> elements)
From source file:com.hxj.websimplejava.tools.MavenUtils.java
public static void main(String[] args) { MavenUtils mavenUtils = new MavenUtils(); try {/*from w w w . j a va 2 s .com*/ // mavenUtils.createMavenDependencyTreeFile(); mavenUtils.readMavenFile(); mavenUtils.checkMavenConflict(); // for (MavenDependency mavenDependency : mavenUtils.mavenDependencySet) { // System.out.println(mavenDependency); // } Collator collator = Collator.getInstance(); TreeMultiset<String> tree = TreeMultiset.create(collator); tree.addAll(mavenUtils.lineSet); for (String string : tree) { System.out.println(string); } // for (String string : mavenUtils.conflictSet) { // System.out.println(string); // } // System.out.println(mavenUtils.mavenDependencySet.size()); } catch (IOException e) { e.printStackTrace(); } }
From source file:cc.kave.commons.model.groum.comparator.ExasVector.java
private static <T extends Comparable<T>> int compare(SortedMultiset<T> s1, SortedMultiset<T> s2) { int sizeCompare = Integer.compare(s1.size(), s2.size()); if (sizeCompare != 0) { return sizeCompare; }// w w w .j a va2 s . com Set<T> o1UniquePaths = s1.elementSet(); Set<T> o2UniquePaths = s2.elementSet(); int uniqueSizeCompare = Integer.compare(o1UniquePaths.size(), o2UniquePaths.size()); if (uniqueSizeCompare != 0) { return uniqueSizeCompare; } TreeMultiset<T> pqNodes2 = TreeMultiset.create(s1); TreeMultiset<T> otherPQNodes2 = TreeMultiset.create(s2); while (!pqNodes2.isEmpty()) { Entry<T> o1First = pqNodes2.pollFirstEntry(); Entry<T> o2First = otherPQNodes2.pollFirstEntry(); int entryCompare = compare(o1First, o2First); if (entryCompare != 0) { return entryCompare; } } return 0; }
From source file:com.totsp.tom.util.Statistics.java
public Statistics(Comparator<T> comparator) { inner = TreeMultiset.create(comparator); }
From source file:org.apache.eagle.alert.engine.sorter.impl.StreamSortedWindowOnHeap.java
/** * @param start start time./*from w w w .j a v a 2s . c o m*/ * @param end end time. * @param margin margin time. */ public StreamSortedWindowOnHeap(long start, long end, long margin, Comparator<PartitionedEvent> comparator) { super(start, end, margin); treeMultisetCache = TreeMultiset.create(comparator); }
From source file:edu.cmu.sv.modelinference.eventtool.classification.Clusterer1D.java
private static ClassificationResult buildResult(List<? extends Cluster<DataWrapper>> results) { LinkedList<EventClass> clusters = new LinkedList<>(); for (int i = 0; i < results.size(); i++) { TreeMultiset<Event> clusterDataPoints = TreeMultiset.create(new Comparator<Event>() { @Override//from ww w. j a v a 2 s. c o m public int compare(Event o1, Event o2) { return Double.compare(o1.getFeature().getData(), o2.getFeature().getData()); } }); for (DataWrapper dataWrapper : results.get(i).getPoints()) { clusterDataPoints.add(dataWrapper.getWrappedData()); } clusters.addLast(new EventClass(clusterDataPoints)); } return new ClassificationResult(clusters); }
From source file:ch.thn.datatree.core.GenericSetTreeNode.java
/** * Creates a new set tree node which uses the given comparator to sort the * nodes// w ww . j a va2 s . c o m * * @param comparator The comparator to use, or <code>null</code> to use an * internally created comparator which compares the toString result of two nodes. * @param value */ public GenericSetTreeNode(Comparator<? super N> comparator, V value) { super(null, value); if (comparator == null) { comparator = new Comparator<N>() { @Override public int compare(N o1, N o2) { return o1.toString().compareTo(o2.toString()); } }; } this.comparator = comparator; internalSetChildrenCollection(TreeMultiset.create(comparator)); }
From source file:gmjonker.util.BoundedTreeMultiset.java
public static <E1> TreeMultiset<E1> create(@Nullable Comparator<? super E1> comparator) { return TreeMultiset.create(comparator); }
From source file:cpw.mods.inventorysorter.SortingHandler.java
private void distributeInventory(Action.ActionContext context, Multiset<ItemStackHolder> itemcounts) { InventoryCrafting ic = (InventoryCrafting) context.slot.inventory; Multiset<ItemStackHolder> slotCounts = TreeMultiset.create(new InventoryHandler.ItemStackComparator()); for (int x = 0; x < ic.getWidth(); x++) { for (int y = 0; y < ic.getHeight(); y++) { ItemStack is = ic.getStackInRowAndColumn(x, y); if (is != null) { slotCounts.add(new ItemStackHolder(is)); }/*from w w w .ja v a 2s . c om*/ } } final ImmutableMultiset<ItemStackHolder> staticcounts = ImmutableMultiset.copyOf(itemcounts); for (int x = 0; x < ic.getWidth(); x++) { for (int y = 0; y < ic.getHeight(); y++) { ItemStack is = ic.getStackInRowAndColumn(x, y); if (is != null) { ItemStackHolder ish = new ItemStackHolder(is); int count = staticcounts.count(ish); int slotNum = slotCounts.count(ish); final int occurrences = count / slotNum; itemcounts.remove(ish, occurrences); is.stackSize = occurrences; } } } for (int x = 0; x < ic.getWidth(); x++) { for (int y = 0; y < ic.getHeight(); y++) { ItemStack is = ic.getStackInRowAndColumn(x, y); if (is != null) { ItemStackHolder ish = new ItemStackHolder(is); if (itemcounts.count(ish) > 0) { is.stackSize += itemcounts.setCount(ish, 0); } } } } for (int slot = context.slotMapping.begin; slot < context.slotMapping.end + 1; slot++) { context.player.openContainer.getSlot(slot).onSlotChanged(); } }
From source file:gmjonker.util.BoundedTreeMultiset.java
public static <E1 extends Comparable> TreeMultiset<E1> create(Iterable<? extends E1> elements) { return TreeMultiset.create(elements); }
From source file:org.apache.tez.analyzer.plugins.TaskConcurrencyAnalyzer.java
@Override public void analyze(DagInfo dagInfo) throws TezException { //For each vertex find the concurrent tasks running at any point for (VertexInfo vertexInfo : dagInfo.getVertices()) { List<TaskAttemptInfo> taskAttempts = Lists.newLinkedList(vertexInfo.getTaskAttempts(true, null)); String vertexName = vertexInfo.getVertexName(); /**//w w w.j a va 2s. c o m * - Get sorted multi-set of timestamps (S1, S2,...E1, E2..). Possible to have multiple * tasks starting/ending at same time. * - Walk through the set * - Increment concurrent tasks when start event is encountered * - Decrement concurrent tasks when start event is encountered */ TreeMultiset<TimeInfo> timeInfoSet = TreeMultiset.create(new Comparator<TimeInfo>() { @Override public int compare(TimeInfo o1, TimeInfo o2) { if (o1.timestamp < o2.timestamp) { return -1; } if (o1.timestamp > o2.timestamp) { return 1; } if (o1.timestamp == o2.timestamp) { //check event type if (o1.eventType.equals(o2.eventType)) { return 0; } if (o1.eventType.equals(EventType.START) && o2.eventType.equals(EventType.FINISH)) { return -1; } else { return 1; } } return 0; } }); for (TaskAttemptInfo attemptInfo : taskAttempts) { TimeInfo startTimeInfo = new TimeInfo(EventType.START, attemptInfo.getStartTime()); TimeInfo stopTimeInfo = new TimeInfo(EventType.FINISH, attemptInfo.getFinishTime()); timeInfoSet.add(startTimeInfo); timeInfoSet.add(stopTimeInfo); } //Compute concurrent tasks in the list now. int concurrentTasks = 0; for (TimeInfo timeInfo : timeInfoSet.elementSet()) { switch (timeInfo.eventType) { case START: concurrentTasks += timeInfoSet.count(timeInfo); break; case FINISH: concurrentTasks -= timeInfoSet.count(timeInfo); break; default: break; } timeInfo.concurrentTasks = concurrentTasks; addToResult(vertexName, timeInfo.timestamp, timeInfo.concurrentTasks); } } }