List of usage examples for java.lang Integer compare
public static int compare(int x, int y)
From source file:org.apache.ranger.plugin.policyevaluator.RangerAbstractPolicyItemEvaluator.java
@Override public int compareTo(RangerPolicyItemEvaluator other) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerAbstractPolicyItemEvaluator.compareTo()"); }/*from ww w . j a va 2s . c o m*/ int result = Integer.compare(getEvalOrder(), other.getEvalOrder()); if (LOG.isDebugEnabled()) { LOG.debug("<== RangerAbstractPolicyItemEvaluator.compareTo(), result:" + result); } return result; }
From source file:com.mingo.query.QueryCase.java
/** * {@inheritDoc}//from w ww .j av a2 s .com */ @Override public int compareTo(QueryCase queryCase) { Validate.notNull(queryCase, "query case cannot be null."); return Integer.compare(queryCase.getPriority(), this.priority); }
From source file:org.y20k.transistor.CollectionAdapter.java
public CollectionAdapter(Activity activity, File folder) { // set main variables mActivity = activity;//from w w w . j a va2 s . c o m mFolder = folder; mStationIDSelected = 0; mStationList = new SortedList<Station>(Station.class, new SortedListAdapterCallback<Station>(this) { @Override public int compare(Station station1, Station station2) { // Compares two stations: returns "1" if name if this station is greater than name of given station int result = Integer.compare(station2.IS_FAVOURITE, station1.IS_FAVOURITE); if (result == 0) {//equal result = station1.CATEGORY.compareToIgnoreCase(station2.CATEGORY); if (result == 0) { result = station1.TITLE.compareToIgnoreCase(station2.TITLE); } } return result; } @Override public boolean areContentsTheSame(Station oldStation, Station newStation) { return oldStation.StreamURI.equals(newStation.StreamURI); } @Override public boolean areItemsTheSame(Station station1, Station station2) { // return station1.equals(station2); return areContentsTheSame(station1, station2); } }); // fill station list loadCollection(); }
From source file:org.apache.bookkeeper.stream.storage.impl.sc.DefaultStorageContainerControllerTest.java
@Test public void testServerAssignmentDataComparator() { ServerAssignmentDataComparator comparator = new ServerAssignmentDataComparator(); LinkedList<Long> serverList1 = new LinkedList<>(); serverList1.add(1L);/*w ww.j av a2 s. c o m*/ LinkedList<Long> serverList2 = new LinkedList<>(); serverList2.add(2L); serverList2.add(3L); BookieSocketAddress address1 = new BookieSocketAddress("127.0.0.1", 4181); BookieSocketAddress address2 = new BookieSocketAddress("127.0.0.1", 4182); Pair<BookieSocketAddress, LinkedList<Long>> pair1 = Pair.of(address1, serverList1); Pair<BookieSocketAddress, LinkedList<Long>> pair2 = Pair.of(address1, serverList2); Pair<BookieSocketAddress, LinkedList<Long>> pair3 = Pair.of(address2, serverList2); assertEquals(-1, comparator.compare(pair1, pair2)); assertEquals(-1, comparator.compare(pair1, pair2)); assertEquals(Integer.compare(address1.hashCode(), address2.hashCode()), comparator.compare(pair2, pair3)); }
From source file:cz.matfyz.oskopek.learnr.model.Question.java
/** * Compares two questions by <code>weight</code> in decreasing order, or in case of equality, by their <code>text</code>s. * <p/>/*from w ww . j a v a2s . com*/ * <b>WARNING</b>: Doesn't conform to the output of <code>equals</code> and <code>hashCode</code>! * * @param o the other question * @return -1, 0, or 1, in decreasing order by <code>weight</code>, or if <code>weight</code>s are equal, by <code>text</code> */ @Override public int compareTo(Question o) { int weightCompare = Integer.compare(getWeight(), o.getWeight()); // comparing by weight, for TreeSet comparing if (weightCompare != 0) return weightCompare; return new CompareToBuilder().append(text, o.text).toComparison(); }
From source file:com.wrmsr.wava.TestOutlining.java
@Test public void testOutlining() throws Throwable { Path outputFile = Paths.get("tmp/post.json"); Function function = Json.OBJECT_MAPPER_SUPPLIER.get().readValue(Files.readAllBytes(outputFile), Function.class); Node body = function.getBody(); LocalAnalysis loa = LocalAnalysis.analyze(body); ControlTransferAnalysis cfa = ControlTransferAnalysis.analyze(body); ValueTypeAnalysis vta = ValueTypeAnalysis.analyze(body, false); Map<Node, Optional<Node>> parentsByNode = Analyses.getParents(body); Map<Node, Integer> totalChildrenByNode = Analyses.getChildCounts(body); Map<Name, Node> nodesByName = Analyses.getNamedNodes(body); Node maxNode = body;/*from ww w . jav a 2 s .co m*/ int maxDiff = 0; Node cur = body; while (true) { System.out.println( String.format("%s -> %d (%d)", cur, totalChildrenByNode.get(cur), cur.getChildren().size())); Optional<Node> maxChild = cur.getChildren().stream() .max((l, r) -> Integer.compare(totalChildrenByNode.get(l), totalChildrenByNode.get(r))); if (!maxChild.isPresent()) { break; } int diff = totalChildrenByNode.get(cur) - totalChildrenByNode.get(maxChild.get()); if (diff > maxDiff) { maxNode = cur; maxDiff = diff; } cur = maxChild.get(); } System.out.println(); System.out.println(maxNode); System.out.println(); List<Node> alsdfj = new ArrayList<>(maxNode.getChildren()); Collections.sort(alsdfj, (l, r) -> -Integer.compare(totalChildrenByNode.get(l), totalChildrenByNode.get(r))); for (Node child : alsdfj) { System.out.println(String.format("%s -> %d", child, totalChildrenByNode.get(child))); } System.out.println(); Index externalRetControl = Index.of(function.getLocals().getList().size()); Index externalRetValue = Index.of(function.getLocals().getList().size() + 1); List<Local> localList = ImmutableList.<Local>builder().addAll(function.getLocals().getList()) .add(new Local(Name.of("_external$control"), externalRetControl, Type.I32)) .add(new Local(Name.of("_external$value"), externalRetValue, Type.I64)).build(); maxNode.accept(new Visitor<Void, Void>() { @Override protected Void visitNode(Node node, Void context) { Outlining.OutlinedFunction of = Outlining.outlineFunction(function, node, Name.of("outlined"), externalRetControl, externalRetValue, loa, cfa, vta, parentsByNode, nodesByName); try { compileFunction(of.getFunction()); } catch (Throwable e) { throw Throwables.propagate(e); } return null; } @Override public Void visitSwitch(Switch node, Void context) { Optional<Switch.Entry> maxEntry = node.getEntries().stream().max((l, r) -> Integer .compare(totalChildrenByNode.get(l.getBody()), totalChildrenByNode.get(r.getBody()))); Node maxNode = maxEntry.get().getBody(); Outlining.OutlinedFunction of = Outlining.outlineFunction(function, maxNode, Name.of("outlined"), externalRetControl, externalRetValue, loa, cfa, vta, parentsByNode, nodesByName); try { compileFunction(of.getFunction()); } catch (Throwable e) { throw Throwables.propagate(e); } Function newFunc = new Function(function.getName(), function.getResult(), function.getArgCount(), new Locals(localList), Transforms.replaceNode(function.getBody(), maxNode, of.getCallsite(), true)); System.out.println(); try { compileFunction(newFunc); } catch (Throwable e) { throw Throwables.propagate(e); } // Map<Index, Index> localTranslation // new Function( // Name.of("laksdjflkad"), // Type.I32, // // ) /* TODO: - FALLTHROUGH analysis - local index translation - spills in/out - breaks as return codes (!! with break values), and returns as return codes - I64 retval cell NEXT: - vta for non switch-cases, with inline value returns if no breaks - pre-alloc cells? would need to kid-glove return temp loading - sp based retvals (setjmp/exceptions gon fuck my day up?) - oh fuck. shadowstack? :/ - NO, no this is doable. pushed ONLY immediately before ret, popped ALWAYS immediately after ret, stack remains same during execution */ // TempManager tm = new TempManager( // new NameGenerator( // function.getLocals().getLocals().stream().map(Local::getName).collect(toImmutableSet()), // "_temp$"), // Index.of(function.getLocals().getLocals().size()), // false); // // Locals locals = new Locals(Stream.concat(function.getLocals().getLocals().stream(), tm.getTempList().stream().map(t -> new Local(t.getName(), t.getIndex(), t.getType()))).collect(toImmutableList())); // function = new Function( // NameMangler.DEFAULT.mangleName(function.getName()), // function.getResult(), // function.getArgCount(), // locals, // body); return null; } }, null); }
From source file:com.vmware.photon.controller.api.frontend.backends.utils.TaskUtils.java
/** * Converts task from back-end representation to front-end representation. * * This function is usually called by a front-end client. The client starts a back-end task, and back-end * returns a task object in back-end representation. Then the task object is converted to front-end * representation and returned to the end user. *//* w w w . ja v a 2 s . c o m*/ public static Task convertBackEndToFrontEnd(TaskService.State taskState) { Task task = new Task(); Task.Entity entity = new Task.Entity(); entity.setId(taskState.entityId); entity.setKind(taskState.entityKind); task.setEntity(entity); task.setId(ServiceUtils.getIDFromDocumentSelfLink(taskState.documentSelfLink)); task.setState(taskState.state.toString()); task.setOperation(taskState.operation); task.setQueuedTime(taskState.queuedTime); task.setStartedTime(taskState.startedTime); task.setEndTime(taskState.endTime); if (StringUtils.isNotBlank(taskState.resourceProperties)) { try { Object resourceProperties = objectMapper.readValue(taskState.resourceProperties, Object.class); task.setResourceProperties(resourceProperties); } catch (IOException e) { throw new IllegalArgumentException( String.format("Error deserializing resourceProperties %s, error %s", taskState.resourceProperties, e.getMessage())); } } if (taskState.steps != null && !taskState.steps.isEmpty()) { List<Step> steps = new ArrayList<>(); taskState.steps.stream() .sorted((taskStepState1, taskStepState2) -> Integer.compare(taskStepState1.sequence, taskStepState2.sequence)) .forEach(taskStepState -> steps.add(StepUtils.convertBackEndToFrontEnd(taskStepState))); task.setSteps(steps); } return task; }
From source file:org.jactr.core.utils.ChainedComparator.java
/** * Description of the Method//from w w w. ja v a2 s .c o m * * @param one * Description of the Parameter * @param two * Description of the Parameter * @return Description of the Return Value */ public int compare(T one, T two) { if (one == two) return 0; for (Comparator<T> comparator : _comparators) { int rtnValue = comparator.compare(one, two); if (rtnValue != 0) return rtnValue; } if (_permitEqualities) return 0; /* * this is strange. If we're in the situation where all the comparators say * the two are equal, it is likely that their hashCodes are consistent such * that some relationship between the two hashcodes will be constant. So, we * change it up with an instance specific mask */ int h1 = one.hashCode() & _comparatorSeed; int h2 = two.hashCode() & _comparatorSeed; int rtn = Integer.compare(h1, h2); if (rtn == 0) { // one last attempt h1 *= hashCode(); h2 *= hashCode(); rtn = Integer.compare(h1, h2); if (rtn == 0) LOGGER.error(String.format("functional equality %s.%d = %s.%d ", one, one.hashCode(), two, two.hashCode())); } return rtn; }
From source file:org.mitre.mpf.interop.JsonActionOutputObject.java
@Override public int compareTo(JsonActionOutputObject other) { int result = 0; if (other == null) { return 0; } else if ((result = ObjectUtils.compare(source, other.source, false)) != 0 || (result = Integer.compare(tracks.hashCode(), other.tracks.hashCode())) != 0) { return result; } else {/*from w w w . ja v a 2s. co m*/ return 0; } }
From source file:org.smigo.plants.PlantHandler.java
public List<Plant> addYear(AuthenticatedUser user, int theNewYear, Locale locale) { final List<Plant> currentPlants = getPlants(user); if (currentPlants.isEmpty() || currentPlants.stream().anyMatch(p -> p.getYear() == theNewYear)) { return Collections.emptyList(); }//from www .jav a2s. c o m int lastYear = theNewYear - 1; boolean containsLastYear = currentPlants.stream().anyMatch(p -> p.getYear() == lastYear); int copyFromYear = containsLastYear ? lastYear : currentPlants.stream().min((p1, p2) -> Integer.compare(p1.getYear(), p2.getYear())).get() .getYear(); List<Plant> newYearPlants = new ArrayList<>(); for (Plant p : currentPlants) { if (p.getYear() == copyFromYear && !speciesHandler.getSpecies(p.getSpeciesId()).isAnnual()) { Plant newPlant = new Plant(p); newPlant.setYear(theNewYear); newYearPlants.add(newPlant); } } messageHandler.addNewYearNewsMessage(Optional.ofNullable(user), theNewYear, currentPlants, locale); return addPlants(newYearPlants, user == null ? null : user.getId()); }