List of usage examples for org.apache.commons.lang3.tuple Pair of
public static <L, R> Pair<L, R> of(final L left, final R right)
Obtains an immutable pair of from two objects inferring the generic types.
This factory allows the pair to be created using inference to obtain the generic types.
From source file:com.hortonworks.streamline.storage.util.StorageUtils.java
public static List<Pair<Field, String>> getSearchableFieldValues(Storable storable) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { List<Pair<Field, String>> res = new ArrayList<>(); for (Field field : storable.getClass().getDeclaredFields()) { if (field.getAnnotation(SearchableField.class) != null) { Object val = ReflectionHelper.invokeGetter(field.getName(), storable); if (val != null) { res.add(Pair.of(field, val instanceof String ? (String) val : val.toString())); }// w w w .j ava 2 s . c o m } } return res; }
From source file:enumj.NanoTimer.java
public static <T, R1, R2> Pair<Long, Long>[] compareNanos(Function<T, R1> firstAction, Function<T, R2> secondAction, T... args) { final long[] firstResults = nanos(firstAction, arg -> "First: " + arg, args); final long[] secondResults = nanos(secondAction, arg -> "Second: " + arg, args); final Pair[] results = new Pair[args.length]; for (int i = 0; i < results.length; ++i) { results[i] = Pair.of(firstResults[i], secondResults[i]); }//from ww w . ja v a 2s.c o m return results; }
From source file:com.hortonworks.registries.storage.util.StorageUtils.java
public static List<Pair<Field, String>> getSearchableFieldValues(Storable storable) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { List<Pair<Field, String>> res = new ArrayList<>(); getAnnotatedFieldValues(storable, SearchableField.class).forEach(kv -> { res.add(Pair.of(kv.getKey(), kv.getValue() instanceof String ? (String) kv.getValue() : kv.getValue().toString())); });/* w w w . j av a 2 s . c o m*/ return res; }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.cache.SQLServerCTContextLoader.java
@Override public TableReadContext load(TableRuntimeContext tableRuntimeContext) throws Exception { TableContext tableContext = tableRuntimeContext.getSourceTableContext(); final Map<String, String> offset = OffsetQueryUtil .getColumnsToOffsetMapFromOffsetFormat(offsets.get(tableRuntimeContext.getOffsetKey())); String query = MSQueryUtil.buildQuery(offset, fetchSize, tableContext.getQualifiedName(), tableContext.getOffsetColumns(), tableContext.getOffsetColumnToStartOffset(), includeJoin, tableContext.getOffset());// ww w .j av a2s . c o m Pair<String, List<Pair<Integer, String>>> queryAndParamValToSet = Pair.of(query, new ArrayList<>()); Connection connection = connectionManager.getConnection(); TableReadContext tableReadContext = new TableReadContext(connection, queryAndParamValToSet.getLeft(), queryAndParamValToSet.getRight(), fetchSize); return tableReadContext; }
From source file:com.foudroyantfactotum.mod.fousarchive.command.CommandPianoRollID.java
@Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { try {/* w ww .j a va 2s .com*/ final List<Pair<SearchMatch, String>> pt = parse(getAsSingleString(args)); if (pt.size() > 10) throw new CommandException("Too many matches"); if (pt.size() == 0) pt.add(Pair.of(SearchMatch.Title, "")); final List<Predicate<MidiDetails>> func = new ArrayList<>(pt.size()); final List<SearchMatch> outfString = new LinkedList<>(); for (Pair<SearchMatch, String> p : pt) { func.add(p.getLeft().checkDetails(p.getRight())); outfString.add(p.getLeft()); } final ResourceLocation[] songList = LiveMidiDetails.INSTANCE.songDetails(); final List<Pair<ResourceLocation, MidiDetails>> validList = new LinkedList<>(); sender.addChatMessage(new TextComponentString("==========Searching==========")); song: for (int i = 0; i < songList.length; ++i) { final MidiDetails song = LiveMidiDetails.INSTANCE.getDetailsOnSong(songList[i]); for (Predicate<MidiDetails> p : func) if (!p.test(song)) continue song; validList.add(Pair.of(songList[i], song)); } int i = 0; for (Pair<ResourceLocation, MidiDetails> m : validList) sender.addChatMessage(new TextComponentString( "\u00A7l" + (++i) + ". \u00A7r\u00A7o" + toStringer(m.getRight(), outfString) + "\u00A7r")); sender.addChatMessage(new TextComponentString("=========End Search=========")); if (validList.size() == 1) { final BlockPos sp = sender.getPosition(); final ItemStack stack = new ItemStack(ModItems.pianoRoll, 1, Math.abs(validList.get(0).getLeft().toString().hashCode()) % ItemPianoRoll.iconNo); final NBTTagCompound nbt = new NBTTagCompound(); ItemPianoRoll.setPianoRollNBT(nbt, validList.get(0).getLeft().toString()); stack.setTagCompound(nbt); sender.getEntityWorld().spawnEntityInWorld( new EntityItem(sender.getEntityWorld(), sp.getX(), sp.getY(), sp.getZ(), stack)); } } catch (Exception e) { if (e instanceof CommandException) throw e; } }
From source file:com.teradata.tempto.internal.configuration.ConfigurationVariableResolver.java
private Pair<String, Object> resolveConfigurationEntry(Configuration configuration, String prefix, StrSubstitutor strSubstitutor) { Optional<Object> optionalValue = configuration.get(prefix); if (optionalValue.isPresent()) { Object value = optionalValue.get(); if (value instanceof String) { return Pair.of(prefix, strSubstitutor.replace(value)); } else {/*from w w w.j a v a 2s.c o m*/ return Pair.of(prefix, value); } } else { return Pair.of(prefix, resolveVariables(configuration.getSubconfiguration(prefix), strSubstitutor)); } }
From source file:com.quartercode.eventbridge.test.def.extra.extension.DefaultSendPredicateCheckExtensionTest.java
private static Pair<BridgeConnector, Class<?>[]> pair(BridgeConnector connector, Class<?>... events) { return Pair.of(connector, events); }
From source file:edu.uci.ics.hyracks.api.rewriter.OneToOneConnectedActivityCluster.java
/** * Set up the mapping of the cluster's output channel to an internal activity and its output channel * //w w w .j a va 2 s. c om * @param clusterOutputIndex * the output channel index for the cluster * @param activityId * the id of the internal activity which produces the corresponding output * @param activityOutputIndex * the output channel index of the internal activity which corresponds to the output channel of the cluster of activities */ public void setClusterOutputIndex(int clusterOutputIndex, ActivityId activityId, int activityOutputIndex) { clusterOutputIndexMap.put(clusterOutputIndex, Pair.of(activityId, activityOutputIndex)); invertedClusterOutputIndexMap.put(Pair.of(activityId, activityOutputIndex), clusterOutputIndex); }
From source file:io.knotx.mocks.knot.KnotContextKeys.java
Observable<Pair<String, Optional<Object>>> valueOrDefault(FileSystem fileSystem, JsonObject responseConfig, KnotContext context) {//w ww . j a v a 2 s.c o m return Observable.just(key).filter(responseConfig::containsKey) .flatMap(contextKey -> this.mockValue(fileSystem, responseConfig.getString(contextKey))) .map(value -> Pair.of(key, value)).defaultIfEmpty(Pair.of(key, this.defaultValue(context))); }
From source file:com.streamsets.pipeline.stage.origin.kinesis.StreamSetsRecordProcessor.java
/** * {@inheritDoc}//from w w w. j a va2 s . c o m */ @Override public void processRecords(ProcessRecordsInput processRecordsInput) { List<Record> records = processRecordsInput.getRecords(); IRecordProcessorCheckpointer checkpointer = processRecordsInput.getCheckpointer(); try { recordQueue.transfer(Pair.of(records, checkpointer)); lastRecordOffset = records.get(records.size() - 1).getSequenceNumber(); LOG.debug("Placed {} records into the queue.", records.size()); } catch (InterruptedException e) { LOG.error("Failed to place batch in queue for shardId {}", shardId); } }