本文整理汇总了Java中org.apache.commons.lang3.tuple.Pair.getLeft方法的典型用法代码示例。如果您正苦于以下问题:Java Pair.getLeft方法的具体用法?Java Pair.getLeft怎么用?Java Pair.getLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.tuple.Pair
的用法示例。
在下文中一共展示了Pair.getLeft方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkAndPut
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
@Override
public boolean checkAndPut(K key, V oldValue, V newValue) {
try {
Pair<Boolean, Long> response = client.checkAndPut(storeId,
ByteString.copyFrom(keySerializer.serialize(key)),
oldValue == null? null : ByteString.copyFrom(valueSerializer.serialize(oldValue)),
ByteString.copyFrom(valueSerializer.serialize(newValue)));
if (versionExtractor != null) {
versionExtractor.setVersion(newValue, response.getRight());
}
return response.getLeft();
} catch (RpcException e) {
throw new DatastoreException(format("Failed to checkAndPut in store id: %s, config: %s", getStoreId(), getConfig().toString()), e);
}
}
示例2: loadAndSetBounds
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
/**
* Fix Track's bounds to real start/end of features in required FeatureFile for specified Chromosome
* @param track Track to fix bounds
* @param geneFile a FeatureFile, from which to load fixed bounds
* @param chromosome a Chromosome, from which to load fixed bounds
* @return true if bounds were set successfully. False, if no required Chromosome is found in bounds map or if
* track bounds don't match real file feature bounds - the are no features in track
* @throws IOException
*/
public boolean loadAndSetBounds(final Track track, final FeatureFile geneFile, final Chromosome chromosome) throws
IOException {
final Pair<Integer, Integer> bounds = loadBounds(geneFile, chromosome);
if (bounds == null) {
track.setBlocks(Collections.emptyList());
return false;
}
// If we are out of variation bounds, return an empty track
if (track.getStartIndex() > bounds.getRight() || track.getEndIndex() < bounds.getLeft()) {
track.setBlocks(Collections.emptyList());
return false;
}
setBounds(track, bounds);
return true;
}
示例3: onBlockActivated
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
if (worldIn.getTileEntity(pos) != null && worldIn.getTileEntity(pos).hasCapability(ExPCropCapability.cropCap, null))
{
IExPCrop crop = IExPCrop.of(worldIn.getTileEntity(pos));
Pair<EnumActionResult, NonNullList<ItemStack>> ret = crop.onHarvest(playerIn, worldIn, pos, state, hand, playerIn.getHeldItem(hand), true);
if (ret.getLeft() == EnumActionResult.SUCCESS)
{
for (ItemStack is : ret.getRight())
{
EntityItem drop = new EntityItem(worldIn, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, is.copy());
worldIn.spawnEntity(drop);
}
}
}
return false;
}
示例4: checkoutAndPull
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
public static void checkoutAndPull(@NonNull String projectRootDir,
@NonNull String branchOrCommit) {
Pair<Boolean, Path> fileExist = isFileExist(projectRootDir);
if (!fileExist.getLeft()) {
return;
}
File file = fileExist.getRight().toFile();
try (Git git = Git.open(file)) {
CmdExecResult result = CommandExecUtil.execCmd(
Constants.TOMCAT_PATH
+ "/webapps"
+ Config.getContextPath()
+ "/shell/gitCheckoutAndPull.sh "
+ file.getAbsolutePath()
+ " "
+ branchOrCommit, true);
if (result == null || !result.isSuccess()) {
logger.error("checkout failed, {}", result);
}
} catch (IOException e) {
logger.error("error occurred, {}", e);
}
}
示例5: moveItemsIntoChest
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
private void moveItemsIntoChest(ItemStack stack, IInventory chest)
{
if (!stack.hasTagCompound()) return;
NBTTagCompound nbtTag = getTagCompound(stack);
NonNullList<Pair<Integer, ItemStack>> items = Util.readItemsFromNBT(nbtTag);
for (Pair<Integer, ItemStack> pair : items)
{
if (pair.getLeft() < chest.getSizeInventory())
{
chest.setInventorySlotContents(pair.getLeft(), pair.getRight());
}
}
nbtTag.removeTag("Items");
}
示例6: testPy4JJavaServer
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
@Test
public void testPy4JJavaServer() throws Exception {
String rootDir = "examples/py4j/java_server";
Engine engine = DefaultEngine.builder().config(rootDir + "/py4j_java_server_sponge_hello_world.xml").build();
engine.startup();
try {
Pair<Process, String> scriptResult = startCPython(engine, rootDir + "/py4j_java_server_python_hello_world.py", true);
Process process = scriptResult.getLeft();
String outputText = scriptResult.getRight();
process.waitFor(60, TimeUnit.SECONDS);
await().atMost(60, TimeUnit.SECONDS)
.until(() -> engine.getOperations().getVariable(Number.class, "eventCounter").intValue() > 0);
assertEquals(String.format("Connected to %s\nTriggers count: %d, first: %s", engine.getDescription(),
engine.getTriggers().size(), engine.getTriggers().get(0).getName()), outputText);
assertEquals(1, engine.getOperations().getVariable(Number.class, "eventCounter").intValue());
assertFalse(engine.isError());
} finally {
engine.shutdown();
}
}
示例7: getEndWithBounds
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
private int getEndWithBounds(VcfFile vcfFile, Chromosome chromosome, boolean forward)
throws IOException {
Map<String, Pair<Integer, Integer>> metaMap = fileManager.loadIndexMetadata(vcfFile);
Pair<Integer, Integer> bounds = metaMap.get(chromosome.getName());
if (bounds == null) {
bounds = metaMap.get(Utils.changeChromosomeName(chromosome.getName()));
}
Assert.notNull(bounds, MessageHelper.getMessage(MessageCode.NO_SUCH_CHROMOSOME));
return forward ? bounds.getRight() : bounds.getLeft();
}
示例8: assertUnchangedPacketDataAfterProcessing
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
@Test
public void assertUnchangedPacketDataAfterProcessing() throws IOException {
final String folder = _fileName.endsWith("pcap") ? "/pcaps" : "/pcapngs";
final File preFile = new File(Settings.getTestBasePath() + folder, _fileName);
final File postFile = _tempFolder.newFile();
final Pair<ParseGraph, ParseGraph> values = CLToolTestUtil.getPacketValues(preFile, postFile, CLToolTestUtil.PEF_COMMAND);
final ParseGraph preValues = values.getLeft();
final ParseGraph postValues = values.getRight();
assertEq(preValues, postValues);
}
示例9: shouldSell
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
/**
* Based an earlier trade and current price and configuration, decides whether bot should sell
*
* @return true if bot should sell at current rate
*/
private boolean shouldSell(TradeEntity trade, BigDecimal currentRate, LocalDateTime currentTime) {
BigDecimal currentProfit = currentRate.subtract(trade.getOpenRate()).divide(trade.getOpenRate());
if (Objects.nonNull(properties.getStopLoss()) && currentProfit.compareTo(properties.getStopLoss()) < 0) {
LOGGER.debug("Stop loss hit.");
return true;
}
Set<Map.Entry<Long, BigDecimal>> minimalRois = properties.getMinimalRoi().entrySet();
List<Pair<Long, BigDecimal>> sortedMinimalRois = minimalRois.stream()
.map(e -> Pair.of(e.getKey(), e.getValue()))
.sorted(Comparator.comparing(Pair::getLeft))
.collect(Collectors.toList());
for (Pair<Long, BigDecimal> minimalRoi : sortedMinimalRois) {
Long duration = minimalRoi.getLeft();
BigDecimal threshold = minimalRoi.getRight();
// Check if time matches and current rate is above threshold
Long timeDiff = trade.getOpenDate().until(currentTime, ChronoUnit.SECONDS);
if (timeDiff > duration && currentProfit.compareTo(threshold) > 0) {
return true;
}
}
LOGGER.debug("Threshold not reached. (cur_profit: {}%)", currentProfit.multiply(BigDecimal.valueOf(100)));
return false;
}
示例10: getStoreShardFromToken
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
/**
* Helper function to obtain a store shard object from given recovery token.
*
* @param operationName
* Operation name.
* @param token
* Token from DetectMappingDifferences.
* @param ssmLocal
* Reference to store shard map corresponding to the token.
* @return Store shard object corresponding to given token, or null if shard map is default shard map.
*/
private StoreShard getStoreShardFromToken(String operationName,
RecoveryToken token,
ReferenceObjectHelper<StoreShardMap> ssmLocal) {
Pair<StoreShardMap, StoreShard> shardInfoLocal;
if (this.getStoreShardMaps().containsKey(token)) {
shardInfoLocal = this.getStoreShardMaps().get(token);
}
else {
throw new IllegalArgumentException(StringUtilsLocal.formatInvariant(Errors._Recovery_InvalidRecoveryToken, token),
new Throwable("token"));
}
ssmLocal.argValue = shardInfoLocal.getLeft();
StoreShard ssLocal = shardInfoLocal.getRight();
ShardLocation location = this.getShardLocation(token);
try (IStoreOperationLocal op = this.getShardMapManager().getStoreOperationFactory().createCheckShardLocalOperation(operationName,
this.getShardMapManager(), location)) {
op.doLocal();
}
catch (IOException e) {
e.printStackTrace();
throw (ShardManagementException) e.getCause();
}
return new StoreShard(ssLocal.getId(), ssLocal.getVersion(), ssLocal.getShardMapId(), ssLocal.getLocation(), ssLocal.getStatus());
}
示例11: loadExonsInViewPort
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
/**
* Loads exon features in the requested viewport
*
* @param geneFileId an ID of GeneFile to load exons from
* @param chromosomeId an ID of chromosome to load exons from
* @param centerPosition a position of center of the screen
* @param viewPortSize a size of the screen
* @return a List of exon intervals. Overlapping exons are joined together
* @throws IOException
*/
public List<Block> loadExonsInViewPort(long geneFileId, long chromosomeId, int centerPosition, int viewPortSize,
int intronLength)
throws IOException {
double time1 = Utils.getSystemTimeMilliseconds();
final GeneFile geneFile = geneFileManager.loadGeneFile(geneFileId);
final Chromosome chromosome = referenceGenomeManager.loadChromosome(chromosomeId);
Assert.notNull(chromosome, getMessage(MessagesConstants.ERROR_CHROMOSOME_ID_NOT_FOUND));
final Map<String, Pair<Integer, Integer>> metaMap = fileManager.loadIndexMetadata(geneFile);
Pair<Integer, Integer> bounds = metaMap.get(chromosome.getName());
if (bounds == null) {
bounds = metaMap.get(Utils.changeChromosomeName(chromosome.getName()));
}
Assert.notNull(bounds, getMessage(MessageCode.NO_SUCH_CHROMOSOME));
int end = bounds.getRight();
int start = bounds.getLeft();
IntervalTree<Block> intervalTree = new IntervalTree<>();
try (AbstractFeatureReader<GeneFeature, LineIterator> featureReader =
fileManager.makeGeneReader(geneFile, GeneFileType.ORIGINAL)) {
loadExonsForward(centerPosition, viewPortSize, chromosome, intronLength, end, intervalTree,
featureReader);
loadExonsBackwards(centerPosition, viewPortSize, chromosome, intronLength, start, intervalTree,
featureReader);
}
List<Block> exons = new ArrayList<>();
for (IntervalTree.Node<Block> node : intervalTree) {
exons.add(node.getValue());
}
double time2 = Utils.getSystemTimeMilliseconds();
LOGGER.info(getMessage(MessagesConstants.DEBUG_GENE_EXONS_LOAD, time2 - time1));
return exons;
}
示例12: validate
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
@Override
public ValidationResult validate(BlockHeader header) {
List<Pair<Long, BlockHeaderValidator>> validators = blockchainConfig.getConfigForBlock(header.getNumber()).headerValidators();
for (Pair<Long, BlockHeaderValidator> pair : validators) {
if (header.getNumber() == pair.getLeft()) {
ValidationResult result = pair.getRight().validate(header);
if (!result.success) {
return fault("Block " + header.getNumber() + " header constraint violated. " + result.error);
}
}
}
return Success;
}
示例13: testUDPDNS1
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
@Test
public void testUDPDNS1() throws IOException {
final Pair<ParseGraph, ParseGraph> values = CLToolTestUtil.getPacketValues(new File(_basePath + "/1udpdns.pcap"), _tempFolder.newFile(), CLToolTestUtil.PEF_COMMAND);
final ParseGraph preValues = values.getLeft();
final ParseGraph postValues = values.getRight();
assertAddressesDiffer(preValues, postValues);
assertEq(TestUtil.valueAtDepth(preValues, "headerchecksum", 0), new byte[]{(byte) 0xAC, (byte) 0x82});
assertEq(TestUtil.valueAtDepth(postValues, "headerchecksum", 0), new byte[]{0x6D, (byte) 0xD5});
assertEq(TestUtil.valueAtDepth(preValues, "udpchecksum", 0), new byte[]{0x7C, 0x15});
assertEq(TestUtil.valueAtDepth(postValues, "udpchecksum", 0), new byte[]{0x3D, 0x68});
}
示例14: generateMethod
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
public static Method generateMethod(byte[] content, int start, ClassFile classFile) {
ConstantPool pool = classFile.getConstantPool();
int accessFlag = (int) byte2UnsignedInt(Arrays.copyOfRange(content, start, start + 2));
List<MethodAccessFlag> methodAccessFlags = _parseMethodAccessFlag(accessFlag);
int nameIndex = (int) byte2UnsignedInt(Arrays.copyOfRange(content, start + 2, start + 4));
String name = pool.getUTF8String(nameIndex);
int descriptorIndex = (int) byte2UnsignedInt(Arrays.copyOfRange(content, start + 4, start + 6));
String descriptor = pool.getUTF8String(descriptorIndex);
int attributesCount = (int) byte2UnsignedInt(Arrays.copyOfRange(content, start + 6, start + 8));
Pair<List<AbstractAttribute>, Integer> pair = _parseMethodAttribute(content, start + 8, attributesCount, classFile);
return new Method(accessFlag, methodAccessFlags, nameIndex, name, descriptorIndex, descriptor, attributesCount, pair.getLeft(), pool, start, pair.getRight());
}
示例15: fromString
import org.apache.commons.lang3.tuple.Pair; //导入方法依赖的package包/类
private WrappedFluidStack fromString(JsonElement json, JsonDeserializationContext context)
{
JsonPrimitive primitive = json.getAsJsonPrimitive();
if (primitive.isString())
{
Pair<String, Integer> pair = parseFluidPart(primitive.getAsString());
return new WrappedFluidStackImpl(pair.getLeft(), pair.getRight());
} else
{
throw new JsonParseException("Invalid element for stack.");
}
}