List of usage examples for com.google.common.collect Ordering from
@GwtCompatible(serializable = true) @Deprecated public static <T> Ordering<T> from(Ordering<T> ordering)
From source file:org.learningu.scheduling.util.bst.GeneralRange.java
/** * Returns the same range relative to the reversed comparator. *//*w w w. j a v a 2 s.co m*/ public GeneralRange<T> reverse() { GeneralRange<T> result = reverse; if (result == null) { result = new GeneralRange<T>(Ordering.from(comparator).reverse(), hasUpperBound, upperEndpoint, upperBoundType, hasLowerBound, lowerEndpoint, lowerBoundType); result.reverse = this; return this.reverse = result; } return result; }
From source file:org.jpmml.evaluator.general_regression.GeneralRegressionModelEvaluator.java
private Map<FieldName, ? extends Double> evaluateCoxRegression(ModelEvaluationContext context) { GeneralRegressionModel generalRegressionModel = getModel(); BaseCumHazardTables baseCumHazardTables = generalRegressionModel.getBaseCumHazardTables(); if (baseCumHazardTables == null) { throw new InvalidFeatureException(generalRegressionModel); }/*from ww w . j a va 2s .c om*/ List<BaselineCell> baselineCells; Double maxTime; FieldName baselineStrataVariable = generalRegressionModel.getBaselineStrataVariable(); if (baselineStrataVariable != null) { FieldValue value = getVariable(baselineStrataVariable, context); BaselineStratum baselineStratum = getBaselineStratum(baseCumHazardTables, value); // "If the value does not have a corresponding BaselineStratum element, then the result is a missing value" if (baselineStratum == null) { return null; } baselineCells = baselineStratum.getBaselineCells(); maxTime = baselineStratum.getMaxTime(); } else { baselineCells = baseCumHazardTables.getBaselineCells(); maxTime = baseCumHazardTables.getMaxTime(); if (maxTime == null) { throw new InvalidFeatureException(baseCumHazardTables); } } Comparator<BaselineCell> comparator = new Comparator<BaselineCell>() { @Override public int compare(BaselineCell left, BaselineCell right) { return Double.compare(left.getTime(), right.getTime()); } }; Ordering<BaselineCell> ordering = Ordering.from(comparator); double baselineCumHazard; FieldName startTimeVariable = generalRegressionModel.getStartTimeVariable(); FieldName endTimeVariable = generalRegressionModel.getEndTimeVariable(); if (endTimeVariable != null) { BaselineCell minBaselineCell = ordering.min(baselineCells); Double minTime = minBaselineCell.getTime(); final FieldValue value = getVariable(endTimeVariable, context); FieldValue minTimeValue = FieldValueUtil.create(DataType.DOUBLE, OpType.CONTINUOUS, minTime); // "If the value is less than the minimum time, then cumulative hazard is 0 and predicted survival is 1" if (value.compareToValue(minTimeValue) < 0) { return Collections.singletonMap(getTargetFieldName(), Values.DOUBLE_ZERO); } FieldValue maxTimeValue = FieldValueUtil.create(DataType.DOUBLE, OpType.CONTINUOUS, maxTime); // "If the value is greater than the maximum time, then the result is a missing value" if (value.compareToValue(maxTimeValue) > 0) { return null; } Predicate<BaselineCell> predicate = new Predicate<BaselineCell>() { private double time = (value.asNumber()).doubleValue(); @Override public boolean apply(BaselineCell baselineCell) { return (baselineCell.getTime() <= this.time); } }; // "Select the BaselineCell element that has the largest time attribute value that is not greater than the value" BaselineCell baselineCell = ordering.max(Iterables.filter(baselineCells, predicate)); baselineCumHazard = baselineCell.getCumHazard(); } else { throw new InvalidFeatureException(generalRegressionModel); } Double r = computeDotProduct(context); Double s = computeReferencePoint(); if (r == null || s == null) { return null; } Double cumHazard = baselineCumHazard * Math.exp(r - s); return Collections.singletonMap(getTargetFieldName(), cumHazard); }
From source file:org.apache.tez.history.parser.datamodel.TaskInfo.java
/** * Get last task attempt to finish//w w w . j a v a 2s. c om * * @return TaskAttemptInfo */ public final TaskAttemptInfo getLastTaskAttemptToFinish() { List<TaskAttemptInfo> attemptsList = getTaskAttempts(); if (attemptsList.isEmpty()) { return null; } return Ordering.from(new Comparator<TaskAttemptInfo>() { @Override public int compare(TaskAttemptInfo o1, TaskAttemptInfo o2) { return (o1.getFinishTimeInterval() < o2.getFinishTimeInterval()) ? -1 : ((o1.getFinishTimeInterval() == o2.getFinishTimeInterval()) ? 0 : 1); } }).max(attemptsList); }
From source file:net.lldp.checksims.submission.Submission.java
/** * Turn a list of files and a name into a Submission. * * The contents of a submission are built deterministically by reading in files in alphabetical order and appending * their contents./* w w w.j ava 2 s . c om*/ * * @param name Name of the new submission * @param files List of files to include in submission * @param splitter Tokenizer for files in the submission * @return A new submission formed from the contents of all given files, appended and tokenized * @throws IOException Thrown on error reading from file * @throws NoMatchingFilesException Thrown if no files are given */ static Submission submissionFromFiles(String name, Set<File> files) throws IOException, NoMatchingFilesException { checkNotNull(name); checkArgument(!name.isEmpty(), "Submission name cannot be empty"); checkNotNull(files); Logger logs = LoggerFactory.getLogger(Submission.class); if (files.size() == 0) { throw new NoMatchingFilesException( "No matching files found, cannot create submission named \"" + name + "\""); } // To ensure submission generation is deterministic, sort files by name, and read them in that order List<File> orderedFiles = Ordering .from((File file1, File file2) -> file1.getName().compareTo(file2.getName())) .immutableSortedCopy(files); StringBuilder fileContent = new StringBuilder(); // Could do this with a .stream().forEach(...) but we'd have to handle the IOException inside for (File f : orderedFiles) { String content = FileUtils.readFileToString(f, StandardCharsets.UTF_8); fileContent.append(content); if (!content.endsWith("\n") && !content.isEmpty()) { fileContent.append("\n"); } } String contentString = fileContent.toString(); if (contentString.length() > 7500 * 4) { // large number of tokens * average token length logs.warn( "Warning: Submission " + name + " has very large source size (" + contentString.length() + ")"); } return new ConcreteSubmission(name, contentString); }
From source file:com.eucalyptus.portal.PortalService.java
public ViewBillingResponseType viewBilling(final ViewBillingType request) throws PortalServiceException { final Context context = checkAuthorized(); final ViewBillingResponseType response = request.getReply(); try {//from www . j a va 2s.c om response.getResult().setBillingSettings(billingInfos.lookupByAccount(context.getAccountNumber(), context.getAccount(), TypeMappers.lookupF(BillingInfo.class, BillingSettings.class))); } catch (PortalMetadataNotFoundException e) { response.getResult() .setBillingSettings(TypeMappers.transform(billingInfos.defaults(), BillingSettings.class)); } catch (Exception e) { throw handleException(e); } try { final Set<String> inactiveTagKeys = Sets.newTreeSet(); inactiveTagKeys .addAll(tagClient.getTagKeys(new GetTagKeysType().markPrivileged()).getResult().getKeys()); inactiveTagKeys.removeAll(response.getResult().getBillingSettings().getActiveCostAllocationTags()); response.getResult().getBillingMetadata().setInactiveCostAllocationTags( Lists.newArrayList(Ordering.from(String.CASE_INSENSITIVE_ORDER).sortedCopy(inactiveTagKeys))); } catch (Exception e) { logger.error("Error loading tag keys", e); } return response; }
From source file:com.netxforge.netxstudio.common.math.NativeFunctions.java
public Value minValue(List<Value> range) { List<Value> sortedCopy = Ordering.from(StudioUtils.valueValueCompare()).sortedCopy(range); return sortedCopy.get(0); }
From source file:org.glowroot.central.v09support.TraceDaoWithV09Support.java
private Result<TracePoint> splitResultIfNeeded(String agentRollupId, TraceQuery query, int limit, DelegateResultAction action) throws Exception { TraceQueryPlan plan = getPlan(agentRollupId, query); TraceQuery queryV09 = plan.queryV09(); TraceQuery queryPostV09 = plan.queryPostV09(); if (queryV09 == null) { checkNotNull(queryPostV09);/*from w w w . ja v a 2 s . c o m*/ return action.result(agentRollupId, queryPostV09); } else if (queryPostV09 == null) { checkNotNull(queryV09); return convertFromV09(action.result(V09Support.convertToV09(agentRollupId), queryV09)); } else { Result<TracePoint> resultV09 = convertFromV09( action.result(V09Support.convertToV09(agentRollupId), queryV09)); Result<TracePoint> resultPostV09 = action.result(agentRollupId, queryPostV09); List<TracePoint> tracePoints = new ArrayList<>(); tracePoints.addAll(resultV09.records()); tracePoints.addAll(resultPostV09.records()); if (tracePoints.size() > limit) { tracePoints = TraceDaoImpl.applyLimitByDurationNanosAndThenSortByCaptureTime(tracePoints, limit); return new Result<>(tracePoints, true); } else { tracePoints = Ordering.from(Comparator.comparingLong(TracePoint::captureTime)) .sortedCopy(tracePoints); return new Result<>(tracePoints, resultV09.moreAvailable() || resultPostV09.moreAvailable()); } } }
From source file:org.sosy_lab.cpachecker.util.templates.TemplatePrecision.java
/** * Get templates associated with the given node. *///from w w w . j av a 2s. co m public Collection<Template> getTemplatesForNode(final CFANode node) { if (cache.containsKey(node)) { return cache.get(node); } Builder<Template> out = ImmutableSet.builder(); out.addAll(extractTemplatesForNode(node)::iterator); out.addAll(extraTemplates); out.addAll(extractedFromAssertTemplates); out.addAll(generateTemplates(node)); Set<Template> outBuild = out.build(); if (varFiltering == VarFilteringStrategy.ONE_LIVE) { // Filter templates to make sure at least one is alive. outBuild = Sets.filter(outBuild, input -> shouldUseTemplate(input, node)); } // Sort. List<Template> sortedTemplates = Ordering .from(Comparator.<Template>comparingInt((template) -> template.getLinearExpression().size()) .thenComparingInt(t -> t.toString().trim().startsWith("-") ? 1 : 0) .thenComparing(Template::toString)) .immutableSortedCopy(outBuild); cache.putAll(node, sortedTemplates); return cache.get(node); }
From source file:org.bonitasoft.web.designer.controller.asset.AssetService.java
/** * Uses to change assset order in the component *//*from www.jav a 2 s .c o m*/ public Asset changeAssetOrderInComponent(T component, String assetId, OrderType ordering) { checkArgument(isNotEmpty(assetId), ASSET_ID_IS_REQUIRED); //In need an ordered list List<Asset> assets = Ordering.from(Asset.getComparatorByOrder()).sortedCopy(component.getAssets()); Asset previous = null; Asset actual = null; int i = 0; int size = assets.size(); for (Asset a : assets) { if (actual != null) { //We have to break the loop if (OrderType.INCREMENT.equals(ordering)) { a.setOrder(a.getOrder() - 1); } break; } if (assetId.equals(a.getId())) { //If asset is found we change order actual = a; //If elt is the first we can't decremented it. This is the same if we want to increment the last one if ((OrderType.DECREMENT.equals(ordering) && previous == null) || (OrderType.INCREMENT.equals(ordering) && i == size - 1)) { //If elt is the first or the last it can't be decremented or incremented break; } a.setOrder(OrderType.DECREMENT.equals(ordering) ? a.getOrder() - 1 : a.getOrder() + 1); //If current asset is placed before we change the previous asset if (previous != null && OrderType.DECREMENT.equals(ordering)) { previous.setOrder(previous.getOrder() + 1); } } else { previous = a; } i++; } repository.updateLastUpdateAndSave(component); return actual; }
From source file:com.netxforge.netxstudio.common.math.NativeFunctions.java
public Value maxValue(List<Value> range) { if (range.size() == 1) { return range.get(0); } else if (range.size() > 1) { List<Value> sortedCopy = Ordering.from(StudioUtils.valueValueCompare()).sortedCopy(range); return sortedCopy.get(sortedCopy.size() - 1); }//from w w w . j ava 2 s . c om return null; }