本文整理汇总了Java中org.apache.commons.lang3.tuple.ImmutablePair类的典型用法代码示例。如果您正苦于以下问题:Java ImmutablePair类的具体用法?Java ImmutablePair怎么用?Java ImmutablePair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImmutablePair类属于org.apache.commons.lang3.tuple包,在下文中一共展示了ImmutablePair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getQueryBuilder
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
/**
* Getter for the QueryBuilder for the parsed creator string
* @param creator the creator string formated as '<code>queryBuilder/{queryBuilder#getName()}/{config#getName()}</code>'
* where '<code>{queryBuilder#getName()}</code>' is the same as '<code>{config#getType()}</code>'
* @return the {@link QueryBuilder} or <code>null</code> if not present
*/
public <C extends ComponentConfiguration> Entry<QueryBuilder<C>,C> getQueryBuilder(String creator, Configuration conf) {
String[] creatorParts = StringUtils.split(creator, ':');
if(creatorParts.length >= 2){
QueryBuilder<C> queryBuilder = (QueryBuilder<C>)builders.get(creatorParts[1]);
if(queryBuilder == null){
return null;
}
if(creatorParts.length >= 3){
Optional<C> config = conf.getConfiguration(queryBuilder,creatorParts[2]);
if(config.isPresent()){
return new ImmutablePair<>(queryBuilder, config.get());
} else { //the referenced config was not found
return null;
}
} else { //no configuration in the creator string ... so a null configuration is OK
return new ImmutablePair<>(queryBuilder, null);
}
} else {
return null;
}
}
示例2: getConnectedPneumatics
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
/**
* Retrieves a list of all the connecting pneumatics. It takes sides in account.
*
* @return a list of face->air-handler pairs
*/
@Override
public List<Pair<EnumFacing, IAirHandler>> getConnectedPneumatics() {
List<Pair<EnumFacing, IAirHandler>> teList = new ArrayList<>();
for (IAirHandler specialConnection : specialConnectedHandlers) {
teList.add(new ImmutablePair<>(null, specialConnection));
}
for (EnumFacing direction : EnumFacing.VALUES) {
TileEntity te = getTileCache()[direction.ordinal()].getTileEntity();
IPneumaticMachine machine = ModInteractionUtils.getInstance().getMachine(te);
if (machine != null && parentPneumatic.getAirHandler(direction) == this && machine.getAirHandler(direction.getOpposite()) != null) {
teList.add(new ImmutablePair<>(direction, machine.getAirHandler(direction.getOpposite())));
}
}
if (airListener != null) airListener.addConnectedPneumatics(teList);
return teList;
}
示例3: findNodeByPodIP
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
String findNodeByPodIP(String podIP) {
for (ImmutablePair<Netmask, ImmutableMap<NetworkAddress, String>> entry : podSubnetToNode) {
Netmask netmask = entry.getLeft();
ImmutableMap<NetworkAddress, String> networkToNode = entry.getRight();
// Computes the subnet that results from the netmask applied to the pod IP.
SubnetInfo podSubnetToCheck;
try {
podSubnetToCheck = new SubnetUtils(podIP, netmask.getValue()).getInfo();
} catch (IllegalArgumentException e) {
log.warn(e);
continue;
}
String networkAddress = podSubnetToCheck.getNetworkAddress();
String nodeName = networkToNode.get(new NetworkAddress(networkAddress));
if (nodeName != null) { // The cluster node is in charge of this pod IP subnet.
return nodeName;
}
}
return "";
}
示例4: getContent
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
public String getContent() {
TableBuilder builder = new TableBuilder(OPERATOR_COLUMNS);
for (ImmutablePair<OperatorProfile, Integer> ip : ops) {
int minor = ip.getRight();
OperatorProfile op = ip.getLeft();
String path = new OperatorPathBuilder().setMajor(major).setMinor(minor).setOperator(op).build();
builder.appendCell(path, null);
builder.appendNanos(op.getSetupNanos());
builder.appendNanos(op.getProcessNanos());
builder.appendNanos(op.getWaitNanos());
long maxBatches = Long.MIN_VALUE;
long maxRecords = Long.MIN_VALUE;
for (StreamProfile sp : op.getInputProfileList()) {
maxBatches = Math.max(sp.getBatches(), maxBatches);
maxRecords = Math.max(sp.getRecords(), maxRecords);
}
builder.appendFormattedInteger(maxBatches, null);
builder.appendFormattedInteger(maxRecords, null);
builder.appendBytes(op.getPeakLocalMemoryAllocated(), null);
}
return builder.build();
}
示例5: buildCityWall
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
/**
* Builds a city wall around city at given coordinatepair
*
* @precondition the coordinatepair wallPosition has a city of given player color on it
*/
public boolean buildCityWall(PlayerColor owner, CoordinatePair wallPosition, boolean fromPeer) {
Player currentP = aSessionManager.getPlayerFromColor(owner);
aGameBoardManager.buildCityWall(currentP, wallPosition);
// update gui
aSessionScreen.putCityWall(wallPosition, owner);
if (!fromPeer) {
// send message to network about change
CityWallChange request = CityWallChange.newInstance(true, new ImmutablePair<Integer, Integer>(wallPosition.getLeft(), wallPosition.getRight()), owner, localPlayer.getUsername());
CatanGame.client.sendTCP(request);
// remove resources it cost to build the city wall
aTransactionManager.payPlayerToBank(currentP, GameRules.getGameRulesInstance().getCityWallCost(aSessionManager.getCurrentlyExecutingProgressCard()));
aSessionScreen.updateResourceBar(localPlayer.getResources());
}
return true;
}
示例6: moveRobber
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
/**
* Requests the GameBoardManager to move the robber to given location. If fromPeer is false, the SessionController sends message to network notifying
* other peers about board change
*/
public boolean moveRobber(Hex newPosition, boolean fromPeer) {
if (newPosition == null) {
newPosition = Hex.newInstance(CoordinatePair.of(-30, -30, HarbourKind.NONE), TerrainKind.SEA, 0);
aGameBoardManager.setRobberPosition(null);
aSessionScreen.placeRobber(-30, -30);
} else {
aGameBoardManager.setRobberPosition(newPosition);
aSessionScreen.placeRobber(newPosition.getLeftCoordinate(), newPosition.getRightCoordinate());
}
if (!fromPeer) {
MoveRobberRequest request;
if (newPosition == null) {
request = MoveRobberRequest.newInstance(new ImmutablePair<Integer, Integer>(newPosition.getLeftCoordinate(), newPosition.getRightCoordinate()), localPlayer.getUsername(), true);
} else {
request = MoveRobberRequest.newInstance(new ImmutablePair<Integer, Integer>(newPosition.getLeftCoordinate(), newPosition.getRightCoordinate()), localPlayer.getUsername(), false);
}
CatanGame.client.sendTCP(request);
}
return true;
}
示例7: movePirate
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
public boolean movePirate(Hex newPosition, boolean fromPeer) { // TODO finish changes
if (newPosition == null) {
newPosition = Hex.newInstance(CoordinatePair.of(-30, -30, HarbourKind.NONE), TerrainKind.SEA, 0);
aGameBoardManager.setPiratePosition(null);
aSessionScreen.placePirate(-30, -30);
} else {
aGameBoardManager.setPiratePosition(newPosition);
aSessionScreen.placePirate(newPosition.getLeftCoordinate(), newPosition.getRightCoordinate());
}
if (!fromPeer) {
MovePirateRequest request;
if(newPosition == null) {
request = MovePirateRequest.newInstance(new ImmutablePair<Integer, Integer>(newPosition.getLeftCoordinate(), newPosition.getRightCoordinate()), localPlayer.getUsername(), true);
} else {
request = MovePirateRequest.newInstance(new ImmutablePair<Integer, Integer>(newPosition.getLeftCoordinate(), newPosition.getRightCoordinate()), localPlayer.getUsername(), false);
}
CatanGame.client.sendTCP(request);
}
return true;
}
示例8: moveMerchant
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
/**
* Requests the GameBoardManager to move the merchant to given position. If fromPeer is false, SessionController sends a message to the network notifying
* other peers of board change.
*
* @param newPosition new merchant position
* @param newOwner player who now owns the merchant
* @param fromPeer indicates whether method was called from localPlayer or peer
*/
public boolean moveMerchant(Hex newPosition, PlayerColor newOwner, boolean fromPeer) {
Player owner = aSessionManager.getPlayerFromColor(newOwner);
aGameBoardManager.setMerchantOwner(owner);
aGameBoardManager.setMerchantPosition(newPosition);
aSessionScreen.placeMerchant(newPosition.getLeftCoordinate(), newPosition.getRightCoordinate());
if (!fromPeer) {
MoveMerchantRequest request = MoveMerchantRequest.newInstance(new ImmutablePair<Integer, Integer>(newPosition.getLeftCoordinate(), newPosition.getRightCoordinate()), newOwner, localPlayer.getUsername());
CatanGame.client.sendTCP(request);
}
CatanGame.client.sendTCP(UpdateVP.newInstance(localPlayer.getUsername()));
return true;
}
示例9: parse
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
/**
* Parses all document present in the referenced file path
*
* @param stringsQueue to parse
* @return list with all documents with it's content in untokenized/unstemmed raw keywords
*/
public List<Document> parse(ConcurrentLinkedQueue<String> stringsQueue) {
//compile our corpus regex so we can apply it on our parsing process
Pattern id_content = Pattern.compile(CORPUS_REGEX_DOCUMENT);
//parsing process
return stringsQueue.parallelStream()
.filter(line -> !line.isEmpty()) // line is not empty
.map(id_content::matcher)// regex it
.filter(Matcher::find) // did we regex anything? if so create document
.map(match ->
{
//get the corpusID for this new file that we processing
int corpusID = corpusCount.getAndIncrement();
//map the corpusID to its corresponding filepath
corpusIDToPath.computeIfAbsent(corpusID, v -> new ImmutablePair<>(match.group(4), Integer.parseInt(match.group(1))));
return new Document(
corpusID, //first match is doc id and used to create our own doc id
Arrays.asList(match.group(5).split(" ")).parallelStream() // split document content in words
.collect(Collectors.toList())); // and put them in a list
})
.collect(Collectors.toList()); //collect all parsed lines
}
示例10: processEvent
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
/**
* Processes an event. Adds a decomposed entry (trigger adapter or event set processor group adapter, event) to the decomposed queue.
*
* @param event an event.
*
* @return {@code true} if the event hasn't been processed by any adapters and should be put into the Output Queue.
* @throws java.lang.InterruptedException if interrupted.
*/
public boolean processEvent(Event event) throws InterruptedException {
if (event instanceof ControlEvent) {
if (event instanceof ProcessorControlEvent) {
ProcessorAdapter<?> processorAdapter = ((ProcessorControlEvent) event).getProcessorAdapter();
if (processorAdapter instanceof EventProcessorAdapter && supportsControlEventForProcessor(processorAdapter)) {
putIntoDecomposedQueue(new ImmutablePair<>((EventProcessorAdapter<?>) processorAdapter, event));
}
}
return false;
} else {
getEngine().getStatisticsManager().startTimeMeasurementIfNotStartedYet();
Set<AtomicReference<EventProcessorAdapter<?>>> adapterRs = getEventProcessors(event.getName());
for (AtomicReference<EventProcessorAdapter<?>> adapterR : adapterRs) {
putIntoDecomposedQueue(new ImmutablePair<>(adapterR.get(), event));
}
getEngine().getStatisticsManager().incrementTimeMeasurementEventCount();
return adapterRs.isEmpty();
}
}
示例11: createXmlConfiguration
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
protected Pair<XMLConfiguration, URL> createXmlConfiguration(String fileName) {
List<Lookup> lookups = Arrays.asList(new SystemPropertiesLookup(), new HomeLookup(), new ConfigLookup());
Parameters params = new Parameters();
FallbackBasePathLocationStrategy locationStrategy =
new FallbackBasePathLocationStrategy(FileLocatorUtils.DEFAULT_LOCATION_STRATEGY, home);
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
.configure(params.xml().setDefaultLookups(lookups).setLocationStrategy(locationStrategy).setFileName(fileName)
.setSchemaValidation(true).setEntityResolver(new ResourceSchemaResolver()));
try {
XMLConfiguration xmlConfiguration = builder.getConfiguration();
return new ImmutablePair<>(xmlConfiguration, locationStrategy.getLocatedUrl());
} catch (ConfigurationException e) {
throw new ConfigException(e);
}
}
示例12: getCustomRuleEventSpec
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
/**
* Resolves event specification "<name> <alias> : <mode>". Uses default value when one not provided.
*
* @param eventSpecString event specification.
* @return rule event specification, i.e. a triple of (name, alias, mode).
*/
protected RuleEventSpec getCustomRuleEventSpec(String eventSpecString) {
if (eventSpecString == null) {
throw new SpongeException("Event specification is null");
}
List<String> mainList =
Arrays.stream(eventSpecString.split(":")).map(s -> s.trim()).filter(s -> !s.isEmpty()).collect(Collectors.toList());
if (mainList.isEmpty()) {
throw new SpongeException("Event specification is empty");
} else if (mainList.size() > 2) {
throw new SpongeException("Event specification has too many elements separated by ':'");
}
ImmutablePair<String, String> nameAlias = resolveEventNameAndAlias(mainList.get(0));
EventMode eventMode = RuleAdapter.DEFAULT_MODE;
if (mainList.size() == 2) {
try {
eventMode = EventMode.valueOf(mainList.get(1).toUpperCase());
} catch (Exception e) {
throw new SpongeException("Event mode is incorrect: " + mainList.get(1));
}
}
return new GenericRuleEventSpec(nameAlias.getLeft(), nameAlias.getRight(), eventMode);
}
示例13: resolveEventNameAndAlias
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
protected ImmutablePair<String, String> resolveEventNameAndAlias(String eventSpecString) {
if (eventSpecString == null) {
throw new SpongeException("Event specification is null");
}
if (eventSpecString.trim().length() < 1) {
throw new SpongeException("Event specification is empty");
}
StringTokenizer st = new StringTokenizer(eventSpecString, " \t\n\r\f", false);
String eventName = st.nextToken();
String eventAlias = st.hasMoreTokens() ? st.nextToken() : eventName;
return new ImmutablePair<>(eventName, eventAlias);
}
示例14: doSubscribe
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
@Override
protected synchronized void doSubscribe(GrpcURL url,
NotifyListener.NotifyServiceListener listener) {
Pair<GrpcURL, Set<NotifyListener.NotifyServiceListener>> listenersPair =
notifyServiceListeners.get(url.getServiceKey());
if (listenersPair == null) {
Set<NotifyListener.NotifyServiceListener> listeners = Sets.newConcurrentHashSet();
listeners.add(listener);
listenersPair =
new ImmutablePair<GrpcURL, Set<NotifyListener.NotifyServiceListener>>(url, listeners);
} else {
listenersPair.getValue().add(listener);
}
notifyServiceListeners.putIfAbsent(url.getServiceKey(), listenersPair);
if (!serviceGroupLookUped.contains(url.getGroup())) {
serviceGroupLookUped.add(url.getGroup());
ServiceLookUper serviceLookUper = new ServiceLookUper(url.getGroup());
serviceLookUper.setDaemon(true);
serviceLookUper.start();
ConsulEphemralNode ephemralNode = this.buildEphemralNode(url, ThrallRoleType.CONSUMER);
client.registerEphemralNode(ephemralNode);
} else {
notifyListener(url, listener);
}
}
示例15: packageClassName
import org.apache.commons.lang3.tuple.ImmutablePair; //导入依赖的package包/类
private Pair<String, String> packageClassName(FileOptions options) {
String packageName = null;
String className = null;
for (Map.Entry<FieldDescriptor, Object> entry : options.getAllFields().entrySet()) {
if (entry.getKey().getName().equals("java_package")) {
packageName = entry.getValue().toString();
}
if (entry.getKey().getName().equals("java_outer_classname")) {
className = entry.getValue().toString();
}
}
if (packageName != null && className != null) {
return new ImmutablePair<String, String>(packageName, className);
}
return null;
}