List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair
public ImmutablePair(final L left, final R right)
From source file:com.nextdoor.bender.operation.conditional.ConditionalOperationTest.java
@Test public void testSingleConditionMatch() { /*//w w w . j a va 2 s .c om * Setup the pipeline of operation processors */ List<Pair<FilterOperation, List<OperationProcessor>>> conditions = new ArrayList<Pair<FilterOperation, List<OperationProcessor>>>(); List<OperationProcessor> case1Ops = new ArrayList<OperationProcessor>(); DummyAppendOperationFactory pos = new DummyAppendOperationFactory(); DummyAppendOperationConfig posConf = new DummyAppendOperationConfig(); posConf.setAppendStr("+"); pos.setConf(posConf); case1Ops.add(new OperationProcessor(pos)); FilterOperation filter = new BasicFilterOperation(true); conditions.add(new ImmutablePair<FilterOperation, List<OperationProcessor>>(filter, case1Ops)); ConditionalOperation op = new ConditionalOperation(conditions, false); /* * Create thread that supplies input events */ Queue<InternalEvent> inputQueue = new Queue<InternalEvent>(); supply(2, inputQueue); /* * Process */ Stream<InternalEvent> input = inputQueue.stream(); Stream<InternalEvent> output = op.getOutputStream(input); List<String> actual = output.map(m -> { return m.getEventObj().getPayload().toString(); }).collect(Collectors.toList()); List<String> expected = Arrays.asList("0+", "1+"); assertEquals(2, actual.size()); assertTrue(expected.containsAll(actual)); }
From source file:it.polimi.diceH2020.SPACE4CloudWS.services.PerformanceSolverProxy.java
@Cacheable(value = it.polimi.diceH2020.SPACE4CloudWS.main.Configurator.CACHE_NAME, keyGenerator = it.polimi.diceH2020.SPACE4CloudWS.main.Configurator.SPJ_KEYGENERATOR) public Pair<Optional<Double>, Long> evaluate(@NonNull SolutionPerJob solPerJob) { Instant first = Instant.now(); logger.info("Cache missing. Evaluation with " + performanceSolver.getClass().getSimpleName() + "."); Optional<Double> optionalResult = performanceSolver.evaluate(solPerJob); Instant after = Instant.now(); return new ImmutablePair<>(optionalResult, Duration.between(first, after).toMillis()); }
From source file:com.pinterest.terrapin.server.ResourcePartitionMap.java
public Reader removeReader(String resource, String partition) throws UnsupportedOperationException { Pair<String, String> readerMapKey = new ImmutablePair(resource, partition); synchronized (this) { Reader r = this.readerMap.get(readerMapKey); if (r != null) { readerMap.remove(readerMapKey); decrementPartitionCount(resource); return r; } else {// w ww.j a v a2 s .co m throw new UnsupportedOperationException( "Partition " + partition + " not found for Resource " + resource); } } }
From source file:com.ottogroup.bi.streaming.operator.json.insert.JsonStaticContentInsertionTest.java
/** * Test case for {@link JsonStaticContentInsertion#JsonStaticContentInsertion(java.util.List)} being provided a * configuration which holds an element that shows an empty path (null) *///ww w .java 2s.c o m @Test(expected = IllegalArgumentException.class) public void testConstructor_withElementHoldingNullContentPath() throws Exception { List<Pair<JsonContentReference, Serializable>> values = new ArrayList<>(); values.add(new ImmutablePair<JsonContentReference, Serializable>( new JsonContentReference(null, JsonContentType.STRING), "test")); new JsonStaticContentInsertion(values); }
From source file:com.acmutv.ontoqa.core.parser.ParserState.java
/** * Adds a waiting adjunction, found immediately after {@code prevLexicalEntry}. * @param candidate the SLTAG to adjunct. * @param prevIdx the previous lexical entry index. *///from ww w . ja va 2 s . c om public void addSubstitution(Sltag candidate, Integer prevIdx) { this.substitutions.add(new ImmutablePair<>(candidate, prevIdx)); }
From source file:com.microsoft.tooling.msservices.serviceexplorer.azure.vm.VMServiceModule.java
@Override protected void refresh(@NotNull EventStateHandle eventState) throws AzureCmdException { // remove all child nodes removeAllChildNodes();/* w w w . j a v a 2s. c o m*/ AzureManager azureManager = AzureManagerImpl.getManager(getProject()); // load all VMs List<Subscription> subscriptionList = azureManager.getSubscriptionList(); List<Pair<String, String>> failedSubscriptions = new ArrayList<>(); for (Subscription subscription : subscriptionList) { try { List<VirtualMachine> virtualMachines = azureManager.getVirtualMachines(subscription.getId()); for (VirtualMachine vm : virtualMachines) { addChildNode(new VMNode(this, vm)); } if (eventState.isEventTriggered()) { return; } } catch (Exception ex) { failedSubscriptions.add(new ImmutablePair<>(subscription.getName(), ex.getMessage())); continue; } } if (!failedSubscriptions.isEmpty()) { StringBuilder errorMessage = new StringBuilder( "An error occurred when trying to load VMs for the subscriptions:\n\n"); for (Pair error : failedSubscriptions) { errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n"); } DefaultLoader.getUIHelper() .logError("An error occurred when trying to load VMs\n\n" + errorMessage.toString(), null); } }
From source file:eu.stratosphere.pact.runtime.cache.FileCache.java
/** * Leave a 5 seconds delay to clear the local file. *///from w w w . java 2 s . c o m public void deleteTmpFile(String name, JobID jobID) { DeleteProcess dp = new DeleteProcess(name, jobID, count.get(new ImmutablePair(jobID, name))); executorService.schedule(dp, 5000L, TimeUnit.MILLISECONDS); }
From source file:com.quancheng.plugin.common.Proto2ServicePojo.java
private Pair<String, String> packageClassName(FileOptions options) { String packageName = null;//from w w w .j ava2s . c o m 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; }
From source file:com.microsoft.tooling.msservices.serviceexplorer.azure.vmarm.VMArmModule.java
@Override protected void refreshItems() throws AzureCmdException { List<Pair<String, String>> failedSubscriptions = new ArrayList<>(); try {/* w ww. java 2 s . c o m*/ AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager(); // not signed in if (azureManager == null) { return; } SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager(); Set<String> sidList = subscriptionManager.getAccountSidList(); for (String sid : sidList) { try { Azure azure = azureManager.getAzure(sid); List<VirtualMachine> virtualMachines = azure.virtualMachines().list(); for (VirtualMachine vm : virtualMachines) { addChildNode(new VMNode(this, sid, vm)); } } catch (Exception ex) { failedSubscriptions.add(new ImmutablePair<>(sid, ex.getMessage())); continue; } } } catch (Exception ex) { DefaultLoader.getUIHelper() .logError("An error occurred when trying to load Virtual Machines\n\n" + ex.getMessage(), ex); } if (!failedSubscriptions.isEmpty()) { StringBuilder errorMessage = new StringBuilder( "An error occurred when trying to load Storage Accounts for the subscriptions:\n\n"); for (Pair error : failedSubscriptions) { errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n"); } DefaultLoader.getUIHelper().logError( "An error occurred when trying to load Storage Accounts\n\n" + errorMessage.toString(), null); } }
From source file:com.linkedin.pinot.routing.builder.GeneratorBasedRoutingTableBuilder.java
/** * Generates a routing table, decorated with a metric. * * @param routingTableGenerator The routing table generator to use to generate routing tables. * @return A pair of a routing table and its associated metric. */// w w w . j a va2 s.c o m private Pair<Map<String, Set<String>>, Float> generateRoutingTableWithMetric( RoutingTableGenerator routingTableGenerator) { Map<String, Set<String>> routingTable = routingTableGenerator.generateRoutingTable(); int segmentCount = 0; int serverCount = 0; // Compute the number of segments and servers (for the average part of the variance) for (Set<String> segmentsForServer : routingTable.values()) { int segmentCountForServer = segmentsForServer.size(); segmentCount += segmentCountForServer; serverCount++; } // Compute the variance of the number of segments allocated per server float averageSegmentCount = ((float) segmentCount) / serverCount; float variance = 0.0f; for (Set<String> segmentsForServer : routingTable.values()) { int segmentCountForServer = segmentsForServer.size(); float difference = segmentCountForServer - averageSegmentCount; variance += difference * difference; } return new ImmutablePair<>(routingTable, variance); }