List of usage examples for java.lang Integer compare
public static int compare(int x, int y)
From source file:com.squid.kraken.v4.api.core.analytics.AnalyticsServiceBaseImpl.java
/** * @param content/* w ww .j a v a 2s .c om*/ */ private void sortNavigationContent(List<NavigationItem> content) { Collections.sort(content, new Comparator<NavigationItem>() { @Override public int compare(NavigationItem o1, NavigationItem o2) { if (o1.getParentRef() == ROOT_FOLDER.getSelfRef() && o2.getParentRef() == ROOT_FOLDER.getSelfRef()) { // special rule for top level return Integer.compare(topLevelOrder.indexOf(o1.getSelfRef()), topLevelOrder.indexOf(o2.getSelfRef())); } else if (o1.getParentRef().equals(o2.getParentRef())) { if (o1.getType().equals(o2.getType())) { // sort by name return o1.getName().compareTo(o2.getName()); } else { // sort by type return Integer.compare(typeOrder.indexOf(o1.getType()), typeOrder.indexOf(o2.getType())); } } else { // sort by parent return o1.getParentRef().compareTo(o2.getParentRef()); } } }); }
From source file:org.diorite.cfg.system.ConfigField.java
@Override public int compareTo(final ConfigField o) { final int weight = Integer.compare(this.priority, o.priority); if (weight != 0) { return weight; }/*from w w w .ja va2 s . c o m*/ return AlphanumComparator.compareStatic(this.name, o.name); }
From source file:com.github.veqryn.net.Cidr4.java
/** * Given a cidr range, sort from lowest to highest starting IP, * then from widest (highest) to narrowest (lowest) ending IP. * This format is important to be able to generate subsets and submaps * from a NavigableSet or NavigableMap./*from w w w.j a v a 2 s.c o m*/ */ @Override public final int compareTo(final Cidr4 other) { final int lowDiff = Integer.compare(this.low, other.low); if (lowDiff != 0) { return lowDiff; } final int highDiff = Integer.compare(this.high, other.high); if (highDiff != 0) { return -highDiff; // negative = widest first } return 0; }
From source file:com.opendoorlogistics.core.scripts.formulae.FmLookupNearest.java
public static Iterable<FunctionDefinition> createDefinitions( final IndexedDatastores<? extends ODLTableReadOnly> datastores, final int defaultDatastoreIndex, final ExecutionReport result) { ArrayList<FunctionDefinition> dfns = new ArrayList<>(); for (final LCType type : LCType.values()) { final FunctionDefinition dfn = new FunctionDefinition("lookupnearest" + type.name().toLowerCase()); dfn.setGroup("lookupNearest"); dfn.setDescription("Find the nearest object to the input value in the other table."); if (type != LCType.LL) { dfn.addArg("ESPG_SRID", ArgumentType.STRING_CONSTANT, "Spatial Reference System Identifier (SRID) from the ESPG SRID database " + "to use for performing the distance calculations. The reference system " + "must be a grid-based one allowing Pythagoras distance calculations (i.e. " + "a spherical longitude-latitude coord system will not work)."); }/*www . j a v a2 s . c o m*/ // add FROM arguments switch (type) { case LG: case LL: dfn.addArg("longitude", "Longitude to compare to geographic objects in the other table."); dfn.addArg("latitude", "Latitude to compare to geographic objects in the other table."); break; case GG: case GL: dfn.addArg("geometry", "Geometry to compare to geographic objects in the other table."); break; } dfn.addArg("table_reference", ArgumentType.TABLE_REFERENCE_CONSTANT, "Reference to the table to search in."); // add OTHER arguments switch (type) { case GL: case LL: dfn.addArg(new FunctionArgument("longitude_field_name", ArgumentType.STRING_CONSTANT, "Field name of the longitude field in the other table.", false)); dfn.addArg(new FunctionArgument("latitude_field_name", ArgumentType.STRING_CONSTANT, "Field name of the latitude field in the other table.", false)); break; case LG: case GG: dfn.addArg(new FunctionArgument("geometry_field_name", ArgumentType.STRING_CONSTANT, "Field name of the geometry field in the other table.", false)); break; } dfn.addArg("return_field_name", "Name of the field from the other table to return the value of."); // only build the factory if we have actual datastore to build against if (datastores != null) { dfn.setFactory(new FunctionFactory() { @Override public Function createFunction(Function... children) { int i = 0; // get math transform to grid unless working completely in longitude-latitude String srid = null; MathTransform transform = null; if (type != LCType.LL) { srid = FunctionUtils.getConstantString(get(children, i++)); transform = Spatial.fromWGS84(srid); } // get function(s) to get the geometry FmLookupNearest ret = null; switch (type) { case LL: case LG: ret = new FmLookupNearest(type, srid, transform, get(children, i++), get(children, i++)); break; case GL: case GG: ret = new FmLookupNearest(type, srid, transform, get(children, i++)); break; } // get the table reference - to do process this ToProcessLookupReferences toProcess = new ToProcessLookupReferences(); toProcess.tableReferenceFunction = children[i++]; int nbFieldnames = (type == LCType.LL || type == LCType.GL) ? 3 : 2; toProcess.fieldnameFunctions = new Function[nbFieldnames]; for (int j = 0; j < nbFieldnames; j++) { toProcess.fieldnameFunctions[j] = get(children, i++); } // check no more fields left if (i != children.length) { throwWrongNbArgs(); } // process table references ret.refs = FunctionsBuilder.processLookupReferenceNames(dfn.getName(), datastores, defaultDatastoreIndex, toProcess, result); return ret; } private Function get(Function[] children, int i) { if (i >= children.length) { throwWrongNbArgs(); } return children[i]; } private void throwWrongNbArgs() { throw new RuntimeException( "Wrong number of arguments given for function: " + dfn.getName()); } }); } dfns.add(dfn); // } } // sort by number of arguments Collections.sort(dfns, new Comparator<FunctionDefinition>() { @Override public int compare(FunctionDefinition o1, FunctionDefinition o2) { return Integer.compare(o1.nbArgs(), o2.nbArgs()); } }); return dfns; }
From source file:gobblin.runtime.embedded.EmbeddedGobblin.java
@VisibleForTesting protected List<String> getPrioritizedDistributedJars() { List<Map.Entry<String, Integer>> jarsWithPriority = Lists.newArrayList(this.distributedJars.entrySet()); Collections.sort(jarsWithPriority, new Comparator<Map.Entry<String, Integer>>() { @Override// w ww . j a v a 2 s . com public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { return Integer.compare(o1.getValue(), o2.getValue()); } }); return Lists.transform(jarsWithPriority, new Function<Map.Entry<String, Integer>, String>() { @Override public String apply(Map.Entry<String, Integer> input) { return input.getKey(); } }); }
From source file:org.carbondata.scan.executor.util.QueryUtil.java
/** * Below method will be used to create a mapping of column group columns * this mapping will have column group id to all the dimension ordinal * present in the column group This mapping will be used during query * execution, to create a mask key for the column group dimension which will * be used in aggregation and filter query as column group dimension will be * stored in bit level/*w w w . jav a 2 s . c o m*/ */ private static Map<Integer, List<Integer>> getColumnGroupAndItsOrdinalMapping( List<QueryDimension> origdimensions) { List<QueryDimension> dimensions = new ArrayList<QueryDimension>(origdimensions.size()); dimensions.addAll(origdimensions); /** * sort based on column group id */ Collections.sort(dimensions, new Comparator<QueryDimension>() { @Override public int compare(QueryDimension o1, QueryDimension o2) { return Integer.compare(o1.getDimension().columnGroupId(), o2.getDimension().columnGroupId()); } }); // list of row groups this will store all the row group column Map<Integer, List<Integer>> columnGroupAndItsOrdinalsMapping = new HashMap<Integer, List<Integer>>(); // to store a column group List<Integer> currentColumnGroup = null; // current index int index = 0; // previous column group to check all the column of row id has bee // selected int prvColumnGroupId = -1; while (index < dimensions.size()) { // if dimension group id is not zero and it is same as the previous // column group id // then we need to add ordinal of that column as it belongs to same // column group if (!dimensions.get(index).getDimension().isColumnar() && dimensions.get(index).getDimension().columnGroupId() == prvColumnGroupId) { currentColumnGroup.add(dimensions.get(index).getDimension().getOrdinal()); } // if dimension is not a columnar then it is column group column else if (!dimensions.get(index).getDimension().isColumnar()) { currentColumnGroup = new ArrayList<Integer>(); columnGroupAndItsOrdinalsMapping.put(dimensions.get(index).getDimension().columnGroupId(), currentColumnGroup); currentColumnGroup.add(dimensions.get(index).getDimension().getOrdinal()); } // update the row id every time,this is required to group the // columns // of the same row group prvColumnGroupId = dimensions.get(index).getDimension().columnGroupId(); index++; } return columnGroupAndItsOrdinalsMapping; }
From source file:edu.cmu.tetrad.sem.LargeScaleSimulation.java
public IKnowledge getKnowledge(Graph graph) { // System.out.println("Entering getKnowledge ... "); int numLags; // need to fix this! List<Node> variables = graph.getNodes(); List<Integer> laglist = new ArrayList<>(); IKnowledge knowledge = new Knowledge2(); int lag;/*w w w. ja v a2 s . com*/ for (Node node : variables) { String varName = node.getName(); String tmp; if (varName.indexOf(':') == -1) { lag = 0; laglist.add(lag); } else { tmp = varName.substring(varName.indexOf(':') + 1, varName.length()); lag = Integer.parseInt(tmp); laglist.add(lag); } } numLags = Collections.max(laglist); // System.out.println("Variable list before the sort = " + variables); Collections.sort(variables, new Comparator<Node>() { @Override public int compare(Node o1, Node o2) { String name1 = getNameNoLag(o1); String name2 = getNameNoLag(o2); // System.out.println("name 1 = " + name1); // System.out.println("name 2 = " + name2); String prefix1 = getPrefix(name1); String prefix2 = getPrefix(name2); // System.out.println("prefix 1 = " + prefix1); // System.out.println("prefix 2 = " + prefix2); int index1 = getIndex(name1); int index2 = getIndex(name2); // System.out.println("index 1 = " + index1); // System.out.println("index 2 = " + index2); if (getLag(o1.getName()) == getLag(o2.getName())) { if (prefix1.compareTo(prefix2) == 0) { return Integer.compare(index1, index2); } else { return prefix1.compareTo(prefix2); } } else { return getLag(o1.getName()) - getLag(o2.getName()); } } }); // System.out.println("Variable list after the sort = " + variables); for (Node node : variables) { String varName = node.getName(); String tmp; if (varName.indexOf(':') == -1) { lag = 0; // laglist.add(lag); } else { tmp = varName.substring(varName.indexOf(':') + 1, varName.length()); lag = Integer.parseInt(tmp); // laglist.add(lag); } knowledge.addToTier(numLags - lag, node.getName()); } //System.out.println("Knowledge in graph = " + knowledge); return knowledge; }
From source file:org.apache.carbondata.core.scan.executor.util.QueryUtil.java
/** * Below method will be used to create a mapping of column group columns * this mapping will have column group id to all the dimension ordinal * present in the column group This mapping will be used during query * execution, to create a mask key for the column group dimension which will * be used in aggregation and filter query as column group dimension will be * stored in bit level/*from w w w . j a v a 2 s .c o m*/ */ private static Map<Integer, List<Integer>> getColumnGroupAndItsOrdinalMapping( List<QueryDimension> origdimensions) { List<QueryDimension> dimensions = new ArrayList<QueryDimension>(origdimensions.size()); dimensions.addAll(origdimensions); /* * sort based on column group id */ Collections.sort(dimensions, new Comparator<QueryDimension>() { @Override public int compare(QueryDimension o1, QueryDimension o2) { return Integer.compare(o1.getDimension().columnGroupId(), o2.getDimension().columnGroupId()); } }); // list of row groups this will store all the row group column Map<Integer, List<Integer>> columnGroupAndItsOrdinalsMapping = new HashMap<Integer, List<Integer>>(); // to store a column group List<Integer> currentColumnGroup = null; // current index int index = 0; // previous column group to check all the column of row id has bee // selected int prvColumnGroupId = -1; while (index < dimensions.size()) { // if dimension group id is not zero and it is same as the previous // column group id // then we need to add ordinal of that column as it belongs to same // column group if (dimensions.get(index).getDimension().hasEncoding(Encoding.IMPLICIT)) { index++; continue; } else if (!dimensions.get(index).getDimension().isColumnar() && dimensions.get(index).getDimension().columnGroupId() == prvColumnGroupId && null != currentColumnGroup) { currentColumnGroup.add(dimensions.get(index).getDimension().getOrdinal()); } // if dimension is not a columnar then it is column group column else if (!dimensions.get(index).getDimension().isColumnar()) { currentColumnGroup = new ArrayList<Integer>(); columnGroupAndItsOrdinalsMapping.put(dimensions.get(index).getDimension().columnGroupId(), currentColumnGroup); currentColumnGroup.add(dimensions.get(index).getDimension().getOrdinal()); } // update the row id every time,this is required to group the // columns // of the same row group prvColumnGroupId = dimensions.get(index).getDimension().columnGroupId(); index++; } return columnGroupAndItsOrdinalsMapping; }
From source file:delfos.rs.trustbased.WeightedGraph.java
@Override public int compareTo(WeightedGraph<Node> o) { List<Node> allNodes = this.allNodes().stream().sorted().collect(Collectors.toList()); List<Node> allNodesOther = o.allNodes().stream().sorted().collect(Collectors.toList()); int compareNatural = StringsOrderings.compareNatural(allNodes.toString(), allNodesOther.toString()); if (compareNatural != 0) { return compareNatural; } else {/* w w w. ja v a 2s. c om*/ return Integer.compare(this.hashCode(), o.hashCode()); } }
From source file:com.dgtlrepublic.anitomyj.ParserNumber.java
/** * Searches for equivalent number in a list of {@code tokens}. e.g 08(114) * * @param tokens the list of tokens/*w ww .j a v a 2s . c om*/ * @return true if an equivalent number was found */ public boolean searchForEquivalentNumbers(List<Result> tokens) { for (Result it : tokens) { // find number must be isolated if (parser.getParserHelper().isTokenIsolated(it.pos) || !isValidEpisodeNumber(it.token.getContent())) { continue; } // Find the first enclosed, non-delimiter token Result nextToken = Token.findNextToken(parser.getTokens(), it.pos, kFlagNotDelimiter); if (!ParserHelper.isTokenCategory(nextToken, kBracket)) continue; nextToken = Token.findNextToken(parser.getTokens(), nextToken, kFlagEnclosed, kFlagNotDelimiter); if (!ParserHelper.isTokenCategory(nextToken, kUnknown)) continue; // Check if it's an isolated number if (!parser.getParserHelper().isTokenIsolated(nextToken.pos) || !StringHelper.isNumericString(nextToken.token.getContent()) || !isValidEpisodeNumber(nextToken.token.getContent())) { continue; } List<Token> list = Arrays.asList(it.token, nextToken.token); list.sort((o1, o2) -> Integer.compare(StringHelper.stringToInt(o1.getContent()), StringHelper.stringToInt(o2.getContent()))); setEpisodeNumber(list.get(0).getContent(), list.get(0), false); setAlternativeEpisodeNumber(list.get(1).getContent(), list.get(1)); return true; } return false; }