List of usage examples for org.apache.commons.lang3.tuple Pair getLeft
public abstract L getLeft();
Gets the left element from this pair.
When treated as a key-value pair, this is the key.
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileObject.java
/** * Callback for handling delete on this File Object * @throws Exception /*from w w w. j a v a 2 s . c om*/ */ @Override protected void doDelete() throws Exception { Pair<String, String> path = getContainerAndPath(); // Purposely use the more restrictive delete() over deleteIfExists() fileSystem.getClient().deleteObject(path.getLeft(), path.getRight()); }
From source file:additionalpipes.pipes.PipeTransportPowerTeleport.java
@Override protected void sendInternalPower() { PipeLogicTeleport logic = ((PipePowerTeleport) container.pipe).getLogic(); List<Pair<PipeTransportPowerTeleport, Float>> powerQueryList = Lists.newLinkedList(); float totalPowerQuery = 0; for (PipePowerTeleport pipe : logic.<PipePowerTeleport>getConnectedPipes(true)) { PipeTransportPowerTeleport target = (PipeTransportPowerTeleport) pipe.transport; float totalQuery = APUtils.sum(target.powerQuery); if (totalQuery > 0) { powerQueryList.add(Pair.of(target, totalQuery)); totalPowerQuery += totalQuery; }/*from w w w . java 2s . c om*/ } for (int i = 0; i < 6; i++) { displayPower[i] += displayPower2[i]; displayPower2[i] = 0; float totalWatt = internalPower[i]; if (totalWatt > 0) { for (Pair<PipeTransportPowerTeleport, Float> query : powerQueryList) { float watts = totalWatt / totalPowerQuery * query.getRight(); int energy = MathHelper.ceiling_double_int(watts / AdditionalPipes.unitPower); if (logic.useEnergy(energy)) { PipeTransportPowerTeleport target = query.getLeft(); watts -= target.receiveTeleportedEnergy(watts); displayPower[i] += watts; internalPower[i] -= watts; } } } } super.sendInternalPower(); }
From source file:eu.openanalytics.rsb.component.AdminResource.java
@Path("/" + CATALOG_SUBPATH + "/{catalogName}/{fileName}") @PUT//www .j a v a 2s .co m @Consumes(Constants.TEXT_CONTENT_TYPE) public Response putCatalogFile(@PathParam("catalogName") final String catalogName, @PathParam("fileName") final String fileName, @HeaderParam(Constants.APPLICATION_NAME_HTTP_HEADER) final String applicationName, final InputStream in, @Context final HttpHeaders httpHeaders, @Context final UriInfo uriInfo) throws IOException, URISyntaxException { final CatalogSection catalogSection = CatalogSection.valueOf(catalogName); final Pair<PutCatalogFileResult, File> result = getCatalogManager().putCatalogFile(catalogSection, applicationName, fileName, in); if (result.getLeft() == PutCatalogFileResult.UPDATED) { return Response.noContent().build(); } final URI location = buildCatalogFileUri(catalogSection, result.getRight(), httpHeaders, uriInfo); return Response.created(location).build(); }
From source file:de.codecentric.batch.metrics.BatchMetricsImpl.java
@Override public void afterCompletion(int status) { if (LOG.isDebugEnabled()) { LOG.debug("Entered afterCompletion with status " + status + "."); }//from w w w .jav a2s . co m if (status == STATUS_COMMITTED) { MetricContainer currentMetricContainer = metricContainer.get(); for (Pair<String, ? extends Number> metric : currentMetricContainer.metrics) { if (metric.getRight() instanceof Long) { if (LOG.isDebugEnabled()) { LOG.debug("Increment " + metric + "."); } incrementNonTransactional(metric.getLeft(), (Long) metric.getRight()); } else if (metric.getRight() instanceof Double) { if (LOG.isDebugEnabled()) { LOG.debug("Gauge " + metric + "."); } set(metric.getLeft(), (Double) metric.getRight()); } else if (metric.getRight() == null) { if (LOG.isDebugEnabled()) { LOG.debug("Reset " + metric + "."); } remove(metric.getLeft()); } } } metricContainer.remove(); if (TransactionSynchronizationManager.hasResource(serviceKey)) { TransactionSynchronizationManager.unbindResource(serviceKey); } }
From source file:mase.spec.StochasticHybridExchanger.java
/***************** * MERGE PROCESS//from w w w. j av a 2 s. c om *****************/ /* Similar to bottom-up (agglomerative) hierarchical clustering */ @Override protected int mergeProcess(EvolutionState state) { distanceMatrix = computeMetapopDistances(state); Pair<MetaPopulation, MetaPopulation> nextMerge = findNextMerge(distanceMatrix, state); // Merge if they are similar if (nextMerge != null) { state.output.message("*** Merging " + nextMerge.getLeft() + " with " + nextMerge.getRight() + " ***"); MetaPopulation mpNew = mergePopulations(nextMerge.getLeft(), nextMerge.getRight(), state); mpNew.lockDown = calculateLockDown(mpNew, state); metaPops.remove(nextMerge.getLeft()); metaPops.remove(nextMerge.getRight()); metaPops.add(mpNew); return 1; } return 0; }
From source file:com.act.lcms.db.model.PregrowthWell.java
public List<PregrowthWell> insertFromPlateComposition(DB db, PlateCompositionParser parser, Plate p) throws SQLException, IOException { Map<String, String> plateAttributes = parser.getPlateProperties(); Map<Pair<String, String>, String> msids = parser.getCompositionTables().get("msid"); List<Pair<String, String>> sortedCoordinates = new ArrayList<>(msids.keySet()); Collections.sort(sortedCoordinates, new Comparator<Pair<String, String>>() { // TODO: parse the values of these pairs as we read them so we don't need this silly comparator. @Override/*from ww w . j a va 2 s .co m*/ public int compare(Pair<String, String> o1, Pair<String, String> o2) { if (o1.getKey().equals(o2.getKey())) { return Integer.valueOf(Integer.parseInt(o1.getValue())) .compareTo(Integer.parseInt(o2.getValue())); } return o1.getKey().compareTo(o2.getKey()); } }); List<PregrowthWell> results = new ArrayList<>(); for (Pair<String, String> coords : sortedCoordinates) { String msid = msids.get(coords); if (msid == null || msid.isEmpty()) { continue; } String sourcePlate = parser.getCompositionTables().get("source_plate").get(coords); String sourceWell = parser.getCompositionTables().get("source_well").get(coords); String composition = parser.getCompositionTables().get("composition").get(coords); String note = null; if (parser.getCompositionTables().get("note") != null) { note = parser.getCompositionTables().get("note").get(coords); } // TODO: ditch this when we start using floating point numbers for growth values. Integer growth = null; Map<Pair<String, String>, String> growthTable = parser.getCompositionTables().get("growth"); if (growthTable == null || growthTable.get(coords) == null) { String plateGrowth = plateAttributes.get("growth"); if (plateGrowth != null) { growth = Integer.parseInt(trimAndComplain(plateGrowth)); } } else { String growthStr = growthTable.get(coords); if (PLUS_MINUS_GROWTH_TO_INT.containsKey(growthStr)) { growth = PLUS_MINUS_GROWTH_TO_INT.get(growthStr); } else { growth = Integer.parseInt(growthStr); // If it's not using +/- format, it should be an integer from 1-5. } } Pair<Integer, Integer> index = parser.getCoordinatesToIndices().get(coords); PregrowthWell s = INSTANCE.insert(db, p.getId(), index.getLeft(), index.getRight(), sourcePlate, sourceWell, msid, composition, note, growth); results.add(s); } return results; }
From source file:ml.shifu.shifu.core.ModelRunner.java
/** * Run model to compute score for input NS Data map * // w w w. j a v a 2 s . c o m * @param rawDataNsMap * - the original input, but key is wrapped by NSColumn * @return CaseScoreResult - model score */ public CaseScoreResult computeNsData(final Map<NSColumn, String> rawDataNsMap) { if (MapUtils.isEmpty(rawDataNsMap)) { return null; } CaseScoreResult scoreResult = new CaseScoreResult(); if (this.scorer != null) { ScoreObject so = scorer.scoreNsData(rawDataNsMap); if (so == null) { return null; } scoreResult.setScores(so.getScores()); scoreResult.setMaxScore(so.getMaxScore()); scoreResult.setMinScore(so.getMinScore()); scoreResult.setAvgScore(so.getMeanScore()); scoreResult.setMedianScore(so.getMedianScore()); scoreResult.setHiddenLayerScores(so.getHiddenLayerScores()); } if (MapUtils.isNotEmpty(this.subScorers)) { if (this.isMultiThread && this.subScorers.size() > 1 && this.executorManager == null) { int threadPoolSize = Math.min(Runtime.getRuntime().availableProcessors(), this.subScorers.size()); this.executorManager = new ExecutorManager<Pair<String, ScoreObject>>(threadPoolSize); // add a shutdown hook as a safe guard if some one not call close Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { ModelRunner.this.executorManager.forceShutDown(); } })); log.info("MultiThread is enabled in ModelRunner, threadPoolSize = " + threadPoolSize); } List<Callable<Pair<String, ScoreObject>>> tasks = new ArrayList<Callable<Pair<String, ScoreObject>>>( this.subScorers.size()); Iterator<Map.Entry<String, Scorer>> iterator = this.subScorers.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<String, Scorer> entry = iterator.next(); Callable<Pair<String, ScoreObject>> callable = new Callable<Pair<String, ScoreObject>>() { @Override public Pair<String, ScoreObject> call() { String modelName = entry.getKey(); Scorer subScorer = entry.getValue(); ScoreObject so = subScorer.scoreNsData(rawDataNsMap); if (so != null) { return Pair.of(modelName, so); } else { return null; } } }; tasks.add(callable); } if (this.isMultiThread && this.subScorers.size() > 1) { List<Pair<String, ScoreObject>> results = this.executorManager.submitTasksAndWaitResults(tasks); for (Pair<String, ScoreObject> result : results) { if (result != null) { scoreResult.addSubModelScore(result.getLeft(), result.getRight()); } } } else { for (Callable<Pair<String, ScoreObject>> task : tasks) { Pair<String, ScoreObject> result = null; try { result = task.call(); } catch (Exception e) { // do nothing } if (result != null) { scoreResult.addSubModelScore(result.getLeft(), result.getRight()); } } } } return scoreResult; }
From source file:net.malisis.blocks.vanishingoption.VanishingOptionsGui.java
@Subscribe public void onConfigChanged(ComponentEvent.ValueChange event) { Pair<EnumFacing, DataType> data = (Pair<EnumFacing, DataType>) event.getComponent().getData(); int time = event.getComponent() instanceof UITextField ? NumberUtils.toInt((String) event.getNewValue()) : 0;/*from w w w. j av a 2 s. co m*/ boolean checked = event.getComponent() instanceof UICheckBox ? (boolean) event.getNewValue() : false; vanishingOptions.set(data.getLeft(), data.getRight(), time, checked); VanishingDiamondFrameMessage.sendConfiguration(tileEntity, data.getLeft(), data.getRight(), time, checked); updateGui(); }
From source file:com.act.lcms.MS2.java
List<YZ> spectrumToYZList(LCMSSpectrum spectrum) { List<YZ> yzList = new ArrayList<>(spectrum.getIntensities().size()); for (Pair<Double, Double> p : spectrum.getIntensities()) { yzList.add(new YZ(p.getLeft(), p.getRight())); }/*from w w w . j a v a2 s .co m*/ return yzList; }
From source file:com.mtbs3d.minecrift.control.GuiScreenNaviator.java
private float dist(Pair<Integer, Integer> a, Pair<Integer, Integer> b, float xScale, float yScale) { float x = xScale * (a.getLeft() - b.getLeft()); float y = yScale * (a.getRight() - b.getRight()); return (float) Math.sqrt(x * x + y * y); }