List of usage examples for org.apache.commons.lang3.tuple ImmutablePair of
public static <L, R> ImmutablePair<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:io.github.carlomicieli.footballdb.starter.pages.TableTests.java
@Test public void shouldBuildNewTablesWithMultipleHeaderRows() { Table table1x4WithHeaders = Table.builder().headers(cells(cell("FIRST"), multiple("SECOND", 3))) .headers("one", "two", "three", "four").row("one", "two", "three", "four").toTable(); assertThat(table1x4WithHeaders.size()).isEqualTo(ImmutablePair.of(1, 4)); assertThat(table1x4WithHeaders.header()).contains("FIRST.one", "SECOND.two", "SECOND.three", "SECOND.four"); }
From source file:forge.deck.io.OldDeckParser.java
private void convertConstructedAndSealed() { boolean allowDeleteUnsupportedConstructed = false; final Map<String, Pair<DeckGroup, MutablePair<File, File>>> sealedDecks = new TreeMap<String, Pair<DeckGroup, MutablePair<File, File>>>( String.CASE_INSENSITIVE_ORDER); for (final File f : this.deckDir.listFiles(DeckStorage.DCK_FILE_FILTER)) { boolean importedOk = false; final List<String> fileLines = FileUtil.readFile(f); final Map<String, List<String>> sections = FileSection.parseSections(fileLines); final DeckFileHeader dh = DeckSerializer.readDeckMetadata(sections); String name = dh.getName(); if (dh.isCustomPool()) { try { this.cube.add(DeckSerializer.fromSections(sections)); importedOk = true;//from www . ja v a2 s . c o m } catch (final NoSuchElementException ex) { if (!allowDeleteUnsupportedConstructed) { final String msg = String.format( "Can not convert deck '%s' for some unsupported cards it contains. %n%s%n%nMay Forge delete all such decks?", name, ex.getMessage()); allowDeleteUnsupportedConstructed = SOptionPane.showConfirmDialog(msg, "Problem converting decks"); } } if (importedOk || allowDeleteUnsupportedConstructed) { f.delete(); } continue; } switch (dh.getDeckType()) { case Constructed: try { this.constructed.add(DeckSerializer.fromSections(sections)); importedOk = true; } catch (final NoSuchElementException ex) { if (!allowDeleteUnsupportedConstructed) { final String msg = String.format( "Can not convert deck '%s' for some unsupported cards it contains. %n%s%n%nMay Forge delete all such decks?", name, ex.getMessage()); allowDeleteUnsupportedConstructed = SOptionPane.showConfirmDialog(msg, "Problem converting decks"); } } if (importedOk || allowDeleteUnsupportedConstructed) { f.delete(); } break; case Limited: name = name.startsWith("AI_") ? name.replace("AI_", "") : name; Pair<DeckGroup, MutablePair<File, File>> stored = sealedDecks.get(name); if (null == stored) { stored = ImmutablePair.of(new DeckGroup(name), MutablePair.of((File) null, (File) null)); } final Deck deck = DeckSerializer.fromSections(sections); if (dh.isIntendedForAi()) { stored.getLeft().addAiDeck(deck); stored.getRight().setRight(f); } else { stored.getLeft().setHumanDeck(deck); stored.getRight().setLeft(f); } if ((stored.getLeft().getHumanDeck() != null) && !stored.getLeft().getAiDecks().isEmpty()) { // have both parts of sealed deck, may convert this.sealed.add(stored.getLeft()); stored.getRight().getLeft().delete(); stored.getRight().getRight().delete(); // there stay only orphans sealedDecks.remove(name); } else { sealedDecks.put(name, stored); } break; default: break; } } // advise to kill orphaned decks if (!sealedDecks.isEmpty()) { final StringBuilder sb = new StringBuilder(); for (final Pair<DeckGroup, MutablePair<File, File>> s : sealedDecks.values()) { final String missingPart = s.getRight().getLeft() == null ? "human" : "computer"; sb.append(String.format("Sealed deck '%s' has no matching '%s' deck.%n", s.getKey().getName(), missingPart)); } sb.append(System.getProperty("line.separator")); sb.append("May Forge delete these decks?"); if (SOptionPane.showConfirmDialog(sb.toString(), "Some of your sealed decks are orphaned")) { for (final Pair<DeckGroup, MutablePair<File, File>> s : sealedDecks.values()) { if (s.getRight().getLeft() != null) { s.getRight().getLeft().delete(); } if (s.getRight().getRight() != null) { s.getRight().getRight().delete(); } } } } }
From source file:com.wrmsr.wava.basic.Basics.java
public static SetMultimap<Name, Name> getBasicInputs(Stream<Basic> basics) { return basics.flatMap(b -> b.getAllTargets().stream().map(t -> ImmutablePair.of(t, b.getName()))) .collect(toHashMultimap());// w w w .ja va 2 s . c om }
From source file:io.cloudslang.content.vmware.services.DeployOvfTemplateService.java
protected ImmutablePair<ManagedObjectReference, OvfCreateImportSpecResult> createLeaseSetup( final ConnectionResources connectionResources, final VmInputs vmInputs, final String templatePath, final Map<String, String> ovfNetworkMap, final Map<String, String> ovfPropertyMap) throws Exception { final ManagedObjectReference ovfManager = getOvfManager(connectionResources); final VmUtils vmUtils = new VmUtils(); final ManagedObjectReference resourcePool; if (StringUtilities.isBlank(vmInputs.getClusterName())) { resourcePool = vmUtils.getMorResourcePool(vmInputs.getResourcePool(), connectionResources); } else {//ww w . ja v a 2 s. co m ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName()); resourcePool = vmUtils.getMorResourcePoolFromCluster(connectionResources, clusterMor, vmInputs.getResourcePool()); } final ManagedObjectReference hostMor = vmUtils.getMorHost(vmInputs.getHostname(), connectionResources, null); final ManagedObjectReference datastoreMor = vmUtils.getMorDataStore(vmInputs.getDataStore(), connectionResources, null, vmInputs); final ManagedObjectReference folderMor = vmUtils.getMorFolder(vmInputs.getFolderName(), connectionResources); final List<OvfNetworkMapping> ovfNetworkMappings = getOvfNetworkMappings(ovfNetworkMap, connectionResources); final List<KeyValue> ovfPropertyMappings = getOvfPropertyMappings(ovfPropertyMap); final OvfCreateImportSpecResult importSpecResult = connectionResources.getVimPortType().createImportSpec( ovfManager, getOvfTemplateAsString(templatePath), resourcePool, datastoreMor, getOvfCreateImportSpecParams(vmInputs, hostMor, ovfNetworkMappings, ovfPropertyMappings)); checkImportSpecResultForErrors(importSpecResult); final ManagedObjectReference httpNfcLease = OvfUtils.getHttpNfcLease(connectionResources, importSpecResult.getImportSpec(), resourcePool, hostMor, folderMor); return ImmutablePair.of(httpNfcLease, importSpecResult); }
From source file:com.wrmsr.wava.analyze.ValueTypeAnalysis.java
public static ValueTypeAnalysis analyze(Node root, boolean isRootUsed) { Map<Node, Entry> analyses = newIdentityHashMap(); Entry rootAnalysis = root.accept(new Visitor<Context, Entry>() { private Entry analyzeChild(Node child, Context context) { Entry analysis = child.accept(this, context); analyses.put(child, analysis); return analysis; }/*from w ww.j a v a 2 s . c o m*/ @Override protected Entry visitNode(Node node, Context context) { throw new IllegalStateException(); } @Override public Entry visitBinary(Binary node, Context context) { Entry left = analyzeChild(node.getLeft(), new Context(true)); Entry right = analyzeChild(node.getRight(), new Context(true)); checkState(left.getType() == right.getType()); checkState(left.getType().isConcrete()); Type resultType = requireNonNull( node.getOp().getTypeMap().get(ImmutablePair.of(left.getType(), right.getType()))); checkState(node.getType() == resultType); return new Entry(node.getType(), mergeValueInitializations(left.getInitialization(), right.getInitialization()), mergeValueOwnerships(left.getOwnership(), right.getOwnership()), mergeBreakValueTypes(left.getBreakValueTypes(), right.getBreakValueTypes()), context); } @Override public Entry visitBlock(Block node, Context context) { List<Node> children = node.getChildren(); List<Entry> init = listInit(children).map(c -> analyzeChild(c, new Context(false))) .collect(toImmutableList()); Entry last = analyzeChild(listLast(children), new Context(context.isUsed)); ImMap<Name, Set<Type>> breakValueTypes = Stream.concat(init.stream(), Stream.of(last)) .map(Entry::getBreakValueTypes) .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes); return new Entry(last.getType(), init.isEmpty() && last.getInitialization() == Initialization.INLINE ? Initialization.INLINE : !last.getType().isConcrete() ? Initialization.VOID : Initialization.SETUP, last.getOwnership(), breakValueTypes, context); } @Override public Entry visitBreak(Break node, Context context) { // checkState(!context.isUsed); Entry value = analyzeChild(node.getValue(), new Context(true)); return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, updateBreakValueTypes( value.getBreakValueTypes(), ImmutableList.of(node.getTarget()), value.getType()), context); } @Override public Entry visitBreakTable(BreakTable node, Context context) { // checkState(!context.isUsed); Entry condition = analyzeChild(node.getCondition(), new Context(true)); return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, updateBreakValueTypes(condition.getBreakValueTypes(), ImmutableList.<Name>builder() .addAll(node.getTargets()).add(node.getDefaultTarget()).build(), Type.NONE), context); } @Override public Entry visitCall(Call node, Context context) { // TODO: check operands? Call.Target target = node.getTarget(); Type type = node.getSignature().getResult(); requireNonNull(type); List<Entry> operands = node.getOperands().stream().map(o -> analyzeChild(o, new Context(true))) .collect(toImmutableList()); checkState(operands.stream().allMatch(o -> o.getType().isConcrete())); return new Entry(type, mergeValueInitializations(operands.stream().map(Entry::getInitialization) .collect(toImmutableList()).toArray(new Initialization[] {})), Ownership.FREE, operands.stream().map(Entry::getBreakValueTypes) .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes), context); } @Override public Entry visitCallIndirect(CallIndirect node, Context context) { Entry target = analyzeChild(node.getTarget(), new Context(true)); checkState(target.getType().isConcrete()); List<Entry> operands = node.getOperands().stream().map(o -> analyzeChild(o, new Context(true))) .collect(toImmutableList()); checkState(operands.stream().allMatch(o -> o.getType().isConcrete())); return new Entry(node.getSignature().getResult(), mergeValueInitializations( Stream.concat(Stream.of(target), operands.stream()).map(Entry::getInitialization) .collect(toImmutableList()).toArray(new Initialization[] {})), Ownership.FREE, Stream.concat(Stream.of(target), operands.stream()).map(Entry::getBreakValueTypes) .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes), context); } @Override public Entry visitConst(Const node, Context context) { return new Entry(node.getLiteral().getType(), Initialization.INLINE, Ownership.FREE, EMPTY_BREAK_VALUE_TYPES, context); } @Override public Entry visitGetLocal(GetLocal node, Context context) { return new Entry(node.getType(), Initialization.INLINE, Ownership.FREE, EMPTY_BREAK_VALUE_TYPES, context); } @Override public Entry visitIf(If node, Context context) { Entry condition = analyzeChild(node.getCondition(), new Context(true)); Entry ifTrue = analyzeChild(node.getIfTrue(), new Context(context.isUsed)); Entry ifFalse = analyzeChild(node.getIfFalse(), new Context(context.isUsed)); checkState(condition.getType().isConcrete()); ImMap<Name, Set<Type>> breakValueTypes = Stream.of(condition, ifTrue, ifFalse) .map(Entry::getBreakValueTypes) .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes); if (context.isUsed) { checkState(ifTrue.getType() == ifFalse.getType()); checkState(ifTrue.getType().isConcrete()); return new Entry(ifTrue.getType(), mergeValueInitializations(condition.getInitialization(), ifTrue.getInitialization(), ifFalse.getInitialization()), mergeValueOwnerships(ifTrue.getOwnership(), ifFalse.getOwnership()), breakValueTypes, context); } else { return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, breakValueTypes, context); } } @Override public Entry visitLabel(Label node, Context context) { // FIXME CFA -> ignore unreachable tails? or expect removed? Entry body = analyzeChild(node.getBody(), new Context(context.isUsed)); ImMap<Name, Set<Type>> breakValueTypes = body.getBreakValueTypes(); Type type = body.getType(); Initialization initialization = body.getInitialization(); Ownership ownership = body.getOwnership(); if (breakValueTypes.containsKey(node.getName())) { Type breakType = Iterables.getOnlyElement(breakValueTypes.get(node.getName())); if (breakType.isConcrete()) { checkState(type == breakType || type == Type.NONE); type = breakType; initialization = Initialization.SETUP; ownership = Ownership.TEMP; } else { if (context.isUsed) { checkState(type == Type.NONE); } else { type = Type.NONE; initialization = Initialization.VOID; ownership = Ownership.VOID; } } breakValueTypes = breakValueTypes.without(node.getName()); } return new Entry(type, initialization, ownership, breakValueTypes, context); } @Override public Entry visitLoad(Load node, Context context) { Entry ptr = analyzeChild(node.getPtr(), new Context(true)); checkState(ptr.getType() == Type.I32); return new Entry(node.getType(), ptr.getInitialization(), Ownership.FREE, ptr.getBreakValueTypes(), context); } @Override public Entry visitLoop(Loop node, Context context) { Entry body = analyzeChild(node.getBody(), new Context(context.isUsed)); ImMap<Name, Set<Type>> breakValueTypes = body.getBreakValueTypes(); if (breakValueTypes.containsKey(node.getName())) { checkState(breakValueTypes.get(node.getName()).equals(EnumSet.of(Type.NONE))); breakValueTypes = breakValueTypes.without(node.getName()); } return new Entry(body.getType(), body.getInitialization(), body.getOwnership(), breakValueTypes, context); } @Override public Entry visitNop(Nop node, Context context) { return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, EMPTY_BREAK_VALUE_TYPES, context); } @Override public Entry visitReturn(Return node, Context context) { checkState(!context.isUsed); Entry value = analyzeChild(node.getValue(), new Context(true)); return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, value.getBreakValueTypes(), context); } @Override public Entry visitSelect(Select node, Context context) { Entry ifTrue = analyzeChild(node.getIfTrue(), new Context(true)); Entry ifFalse = analyzeChild(node.getIfFalse(), new Context(true)); Entry condition = analyzeChild(node.getCondition(), new Context(true)); checkState(ifTrue.getType() == ifFalse.getType()); checkState(ifTrue.getType().isConcrete()); checkState(condition.getType() == Type.I32); return new Entry(ifTrue.getType(), Initialization.SETUP, // FIXME? used check? Ownership.TEMP, mergeBreakValueTypes(ImmutableList.of(ifTrue.getBreakValueTypes(), ifFalse.getBreakValueTypes(), condition.getBreakValueTypes())), context); } @Override public Entry visitSetLocal(SetLocal node, Context context) { Entry value = analyzeChild(node.getValue(), new Context(true)); checkState(value.getType().isConcrete()); checkState(value.getType() == node.getType()); return new Entry(value.getType(), value.getInitialization(), value.getOwnership(), value.getBreakValueTypes(), context); } @Override public Entry visitStore(Store node, Context context) { Entry ptr = analyzeChild(node.getPtr(), new Context(true)); Entry value = analyzeChild(node.getValue(), new Context(true)); checkState(ptr.getType() == Type.I32); checkState(value.getType() == node.getType()); return new Entry(node.getType(), mergeValueInitializations(ptr.getInitialization(), value.getInitialization()), value.getOwnership(), mergeBreakValueTypes(ptr.getBreakValueTypes(), value.getBreakValueTypes()), context); } @Override public Entry visitSwitch(Switch node, Context context) { List<Entry> cases = node.getEntries().stream().map(Switch.Entry::getBody) .map(child -> analyzeChild(child, new Context(false))).collect(toImmutableList()); Entry condition = analyzeChild(node.getCondition(), new Context(true)); checkState(condition.getType().isConcrete() && !condition.getType().isFloat()); return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, mergeBreakValueTypes(Stream.concat(Stream.of(condition.getBreakValueTypes()), cases.stream().map(Entry::getBreakValueTypes)).iterator()), context); } @Override public Entry visitUnary(Unary node, Context context) { Entry value = analyzeChild(node.getValue(), new Context(true)); checkState(value.getType().isConcrete()); Set<Type> resultTypes = requireNonNull(node.getOp().getTypeMap().get(value.getType())); checkState(resultTypes.contains(node.getType())); return new Entry(node.getType(), value.getInitialization(), value.getOwnership(), value.getBreakValueTypes(), context); } @Override public Entry visitUnreachable(Unreachable node, Context context) { return new Entry(Type.UNREACHABLE, Initialization.VOID, Ownership.VOID, EMPTY_BREAK_VALUE_TYPES, context); } }, new Context(isRootUsed)); checkState(rootAnalysis.getBreakValueTypes().isEmpty()); analyses.put(root, rootAnalysis); return new ValueTypeAnalysis(analyses); }
From source file:com.offbynull.portmapper.upnpigd.UpnpIgdController.java
/** * Get mapping detail for some exposed port. * @param externalPort external port/* www . ja v a 2s . c o m*/ * @param portType port type * @return port mapping information for that external port * @throws NullPointerException if portType is {@code null} * @throws IllegalArgumentException if {@code externalPort} isn't between {@code 0} to {@code 65535}, or if the {@code externalPort} * isn't between the external port range specified by the service (if one was specified) * @throws ResponseException if the router responds with an error */ public PortMappingInfo getMappingDetails(int externalPort, PortType portType) { // CHECKSTYLE:ON Validate.inclusiveBetween(0, 65535, externalPort); // 0 = wildcard, any unassigned port? may not be supported according to docs Validate.notNull(portType); if (externalPortRange != null) { Validate.inclusiveBetween((long) externalPortRange.getMinimum(), (long) externalPortRange.getMaximum(), (long) externalPort); } Map<String, String> respParams = performRequest("GetSpecificPortMappingEntry", ImmutablePair.of("NewRemoteHost", ""), ImmutablePair.of("NewExternalPort", "" + externalPort), ImmutablePair.of("NewProtocol", portType.name())); try { int internalPort = NumberUtils.createInteger(respParams.get("NewInternalPort")); InetAddress internalClient = InetAddress.getByName(respParams.get("NewInternalClient")); long remainingDuration = NumberUtils.createInteger(respParams.get("NewLeaseDuration")); return new PortMappingInfo(internalPort, externalPort, portType, internalClient, remainingDuration); } catch (UnknownHostException | NumberFormatException | NullPointerException e) { throw new ResponseException(e); } }
From source file:com.netflix.imfutility.mediainfo.MediaInfoContextBuilder.java
private VirtualTrackInfo doBuild(ContextInfo contextInfo, VirtualTrackInfo prevVirtualTrack) throws IOException, XmlParsingException, MediaInfoException { // 1. get the corresponding essence String essence = contextProvider.getResourceContext().getParameterValue(ResourceContextParameters.ESSENCE, contextInfo);/*from ww w.j a va 2 s. c o m*/ String trackFileId = contextProvider.getResourceContext() .getParameterValue(ResourceContextParameters.TRACK_FILE_ID, contextInfo); // 2. check if we already have media info loaded for this track. If no - load it by executing an external program. ImmutablePair<SequenceType, String> key = ImmutablePair.of(contextInfo.getSequenceType(), trackFileId); VirtualTrackInfo processedInfo = processedMediaInfo.get(key); if (processedInfo == null) { File outputFile = getMediaInfo(contextInfo.getSequenceType(), essence); processedInfo = getTrackInfo(outputFile, contextInfo, essence); processedMediaInfo.put(key, processedInfo); } // 3. we assume that some parameters within a sequence must be equal (for example, channels number). validateSequenceHomogeneous(prevVirtualTrack, processedInfo); // 4. add to resource context buildResourceContext(processedInfo, contextInfo); return processedInfo; }
From source file:io.lavagna.service.BulkOperationService.java
private ImmutablePair<List<Integer>, List<Integer>> addLabelOrUpdate(String projectShortName, List<Integer> cardIds, LabelValue value, User user, String labelName, LabelDomain labelDomain) { List<Integer> filteredCardIds = keepCardIdsInProject(cardIds, projectShortName); int labelId = findBy(projectShortName, labelName, labelDomain).getId(); Map<Integer, List<LabelAndValue>> cardsWithDueDate = keepCardWithMatching(filteredCardIds, new FilterByLabelId(labelId)); List<Integer> updatedCardIds = new ArrayList<>(); // to update only if the label value has changed for (LabelAndValue lv : flatten(cardsWithDueDate.values())) { if (!lv.labelValue().getValue().equals(value)) { labelService.updateLabelValue(lv.labelValue().newValue(lv.getLabelType(), value), user, new Date()); updatedCardIds.add(lv.getLabelValueCardId()); }/*from ww w. ja v a 2 s . c om*/ } // to add filteredCardIds.removeAll(cardsWithDueDate.keySet()); labelService.addLabelValueToCards(labelId, filteredCardIds, value, user, new Date()); return ImmutablePair.of(updatedCardIds, filteredCardIds); }
From source file:com.joyent.manta.http.ApacheHttpGetResponseEntityContentContinuatorTest.java
/** * There are a lot of combinations for ValidatesInitialExchange and validateResponse sorry to cram them all in one * method./*from ww w. ja va 2 s. c o m*/ */ public void validateResponseExpectsNonNullHintsAndResponseFingerprint() throws Exception { STUB_CONTINUATOR.validateResponseWithMarker(ImmutablePair.of(STUB_ETAG, STUB_CONTENT_RANGE)); }
From source file:cc.kave.commons.pointsto.evaluation.events.MRREvaluation.java
private void increaseNumberOfQueries(ICoReTypeName type, String analysis) { Pair<ICoReTypeName, String> key = ImmutablePair.of(type, analysis); Integer currentNumber = numQueries.getOrDefault(key, 0); numQueries.put(key, currentNumber + 1); }