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:org.opendaylight.ovsdb.integrationtest.neutron.NeutronIT.java
@Test public void testGetTunnelEndpoint() throws Exception { Thread.sleep(5000);//w ww.jav a 2 s. c o m final String endpointAddress = "10.10.10.10"; Map<String, Row> ovsRows = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, OpenVSwitch.class)); OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, ovsRows.values().iterator().next()); Assert.assertEquals(null, netVirtConfigurationService.getTunnelEndPoint(node)); final UUID originalVersion = ovsRow.getVersion(); OpenVSwitch updateOvsRow = ovsdbConfigurationService.createTypedRow(node, OpenVSwitch.class); updateOvsRow.setOtherConfig( ImmutableMap.of(netVirtConfigurationService.getTunnelEndpointKey(), endpointAddress)); ovsdbConfigurationService.updateRow(node, ovsdbConfigurationService.getTableName(node, OpenVSwitch.class), null, ovsRow.getUuid().toString(), updateOvsRow.getRow()); // Remember original value so it can be restored on tearDown tearDownOpenVSwitchOtherConfig = ImmutablePair.of(ovsRow.getUuid(), ovsRow.getOtherConfigColumn().getData()); // Make sure tunnel end point was set Assert.assertEquals(InetAddress.getByName(endpointAddress), netVirtConfigurationService.getTunnelEndPoint(node)); // Fetch rows again, and compare tunnel end point values ovsRows = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, OpenVSwitch.class)); ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, ovsRows.values().iterator().next()); Assert.assertEquals(ovsRow.getOtherConfigColumn(), updateOvsRow.getOtherConfigColumn()); // expect version of row to be changed, due to the update Assert.assertNotEquals(ovsRow.getVersion(), originalVersion); }
From source file:org.ow2.proactive.workflow_catalog.rest.controller.WorkflowRevisionControllerQueryIntegrationTest.java
private ImmutablePair<WorkflowMetadata, ProActiveWorkflowParserResult> createWorkflow(BucketMetadata bucket, String projectName, String name, ImmutableMap<String, String> genericInformation, ImmutableMap<String, String> variable) { ProActiveWorkflowParserResult proActiveWorkflowParserResult = new ProActiveWorkflowParserResult(projectName, name, genericInformation, variable); WorkflowMetadata workflow = workflowService.createWorkflow(bucket.id, proActiveWorkflowParserResult, new byte[0]); return ImmutablePair.of(workflow, proActiveWorkflowParserResult); }
From source file:org.slc.sli.ingestion.tenant.TenantMongoDATest.java
private Entity createTenantEntity() { List<Pair<String, String>> ingestionServersAndPaths = new ArrayList<Pair<String, String>>(); ingestionServersAndPaths.add(ImmutablePair.of(ingestionServerName, lzPath1)); ingestionServersAndPaths.add(ImmutablePair.of(ingestionServerName, lzPath2)); return createEntityWithLzPaths(ingestionServersAndPaths); }
From source file:org.sleuthkit.autopsy.timeline.db.EventDB.java
/** * merge the events in the given list if they are within the same period * General algorithm is as follows:/*from w ww. j ava2s .co m*/ * * 1) sort them into a map from (type, description)-> List<aggevent> * 2) for each key in map, merge the events and accumulate them in a list to * return * * @param timeUnitLength * @param preMergedEvents * * @return */ static private List<EventStripe> mergeClustersToStripes(Period timeUnitLength, List<EventCluster> preMergedEvents) { //effectively map from type to (map from description to events) Map<EventType, SetMultimap<String, EventCluster>> typeMap = new HashMap<>(); for (EventCluster aggregateEvent : preMergedEvents) { typeMap.computeIfAbsent(aggregateEvent.getEventType(), eventType -> HashMultimap.create()) .put(aggregateEvent.getDescription(), aggregateEvent); } //result list to return ArrayList<EventCluster> aggEvents = new ArrayList<>(); //For each (type, description) key, merge agg events for (SetMultimap<String, EventCluster> descrMap : typeMap.values()) { //for each description ... for (String descr : descrMap.keySet()) { //run through the sorted events, merging together adjacent events Iterator<EventCluster> iterator = descrMap.get(descr).stream() .sorted(Comparator.comparing(event -> event.getSpan().getStartMillis())).iterator(); EventCluster current = iterator.next(); while (iterator.hasNext()) { EventCluster next = iterator.next(); Interval gap = current.getSpan().gap(next.getSpan()); //if they overlap or gap is less one quarter timeUnitLength //TODO: 1/4 factor is arbitrary. review! -jm if (gap == null || gap.toDuration() .getMillis() <= timeUnitLength.toDurationFrom(gap.getStart()).getMillis() / 4) { //merge them current = EventCluster.merge(current, next); } else { //done merging into current, set next as new current aggEvents.add(current); current = next; } } aggEvents.add(current); } } //merge clusters to stripes Map<ImmutablePair<EventType, String>, EventStripe> stripeDescMap = new HashMap<>(); for (EventCluster eventCluster : aggEvents) { stripeDescMap.merge(ImmutablePair.of(eventCluster.getEventType(), eventCluster.getDescription()), new EventStripe(eventCluster), EventStripe::merge); } return stripeDescMap.values().stream().sorted(Comparator.comparing(EventStripe::getStartMillis)) .collect(Collectors.toList()); }
From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventDetailsChart.java
@Override protected synchronized void dataItemAdded(Series<DateTime, EventCluster> series, int i, Data<DateTime, EventCluster> data) { final EventCluster eventCluster = data.getYValue(); bundles.add(eventCluster);/* w w w .j a v a2s. com*/ EventStripe eventStripe = stripeDescMap.merge( ImmutablePair.of(eventCluster.getEventType(), eventCluster.getDescription()), new EventStripe(eventCluster, null), (EventStripe u, EventStripe v) -> { EventStripeNode remove = stripeNodeMap.remove(u); nodeGroup.getChildren().remove(remove); remove = stripeNodeMap.remove(v); nodeGroup.getChildren().remove(remove); return EventStripe.merge(u, v); }); EventStripeNode stripeNode = new EventStripeNode(EventDetailsChart.this, eventStripe, null); stripeNodeMap.put(eventStripe, stripeNode); nodeGroup.getChildren().add(stripeNode); data.setNode(stripeNode); }
From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventDetailsChart.java
@Override protected synchronized void dataItemRemoved(Data<DateTime, EventCluster> data, Series<DateTime, EventCluster> series) { EventCluster eventCluster = data.getYValue(); bundles.removeAll(eventCluster);/*from ww w . j av a 2 s . co m*/ EventStripe removedStripe = stripeDescMap .remove(ImmutablePair.of(eventCluster.getEventType(), eventCluster.getDescription())); EventStripeNode removedNode = stripeNodeMap.remove(removedStripe); nodeGroup.getChildren().remove(removedNode); data.setNode(null); }
From source file:org.staticioc.parser.ParserHelper.java
/** * Extract the name and id attributes of a node a resolve it as an <id,alias> Pair * @param beanNode to parse//from w w w . j a va 2 s . c o m * @return an <id,alias> Pair */ public static Pair<String, String> extractBeanId(final Node beanNode) { final NamedNodeMap beanAttributes = beanNode.getAttributes(); // use Id if defined, name otherwise (if defined), auto-generated bean name otherwise. final Node idNode = beanAttributes.getNamedItem(ID); final Node bNameNode = beanAttributes.getNamedItem(NAME); String id = (idNode != null) ? idNode.getNodeValue() : (bNameNode != null) ? bNameNode.getNodeValue() : null; final String alias = (idNode != null && bNameNode != null) ? bNameNode.getNodeValue() : null; return ImmutablePair.of(id, alias); }
From source file:org.talend.dataquality.sampling.parallel.ReservoirSamplerWithBinaryHeap.java
public void onNext(T v) { if (done) {/*w w w. j ava 2 s . c o m*/ return; } // rand.nextDouble gets a pseudo random value between 0.0 and 1.0 double r = rand.nextDouble(); if (buffer.size() < nbSamples) { // for the first n elements. ImmutablePair<Double, T> pair = ImmutablePair.of(r, v); buffer.add(pair); if (r < minRandom) { minRandom = r; } return; } if (r > minRandom) { // do reservoir sampling. replaceCount++; ImmutablePair<Double, T> pair = ImmutablePair.of(r, v); buffer.add(pair); ImmutablePair<Double, T> nextPair = buffer.poll(); minRandom = nextPair.left; } }
From source file:org.talend.dataquality.semantic.RespectiveCategoryRecognizerTest.java
public void initEmailList() throws IOException { boolean startInvalid = false; InputStream dateStream = this.getClass().getResourceAsStream("emailList.txt"); //$NON-NLS-1$ BufferedReader br = new BufferedReader(new InputStreamReader(dateStream, "UTF-8"));// for Hindi language Double-byte type String line;/*w w w .j av a 2s .c o m*/ List<Pair<String, Boolean>> emailResultList = EXPECTED_MATCHING_RES_FOR_CATS .get(SemanticCategoryEnum.EMAIL.getId()); try { while ((line = br.readLine()) != null) { if (line.startsWith(commontChar)) { String contronKey = line.replace(commontChar, StringUtils.EMPTY); if (contronKey.equals(invalidChar)) { startInvalid = true; } else if (contronKey.equals(validChar)) { startInvalid = false; } continue; } if (startInvalid) { emailResultList.add(ImmutablePair.of(line, false)); } else { emailResultList.add(ImmutablePair.of(line, true)); } } } finally { br.close(); } }
From source file:org.tango.server.admin.AdminDevice.java
private Pair<PipeImpl, AttributeImpl> findSubscribers(final EventType eventType, final String deviceName, final String objName) throws DevFailed { DeviceImpl device = null;//from w w w. j a v a 2s . co m PipeImpl pipe = null; AttributeImpl attribute = null; for (final DeviceClassBuilder deviceClass : classList) { for (final DeviceImpl deviceImpl : deviceClass.getDeviceImplList()) { if (deviceImpl.getName().toLowerCase(Locale.ENGLISH).equals(deviceName)) { if (eventType.equals(EventType.INTERFACE_CHANGE_EVENT)) { // event for INTERFACE_CHANGE_EVENT does not have an attribute device = deviceImpl; } else if (eventType.equals(EventType.PIPE_EVENT)) { for (final PipeImpl pipeImpl : deviceImpl.getPipeList()) { if (pipeImpl.getName().toLowerCase(Locale.ENGLISH).equals(objName)) { // Found. Store objects device = deviceImpl; pipe = pipeImpl; } } } else { for (final AttributeImpl attributeImpl : deviceImpl.getAttributeList()) { if (attributeImpl.getName().toLowerCase(Locale.ENGLISH).equals(objName)) { if (attributeImpl.getBehavior() instanceof ForwardedAttribute) { // Found. Store objects device = deviceImpl; attribute = attributeImpl; } else if (attributeImpl.isPolled()) { // Check if event criteria are set. Otherwise a DevFailed is thrown EventManager.checkEventCriteria(attributeImpl, eventType); // Found. Store objects device = deviceImpl; attribute = attributeImpl; } else { // check if event is pushed from device boolean throwError = false; switch (eventType) { case ARCHIVE_EVENT: if (!attributeImpl.isPushArchiveEvent()) { throwError = true; } break; case CHANGE_EVENT: if (!attributeImpl.isPushChangeEvent()) { throwError = true; } break; case DATA_READY_EVENT: if (!attributeImpl.isPushDataReady()) { throwError = true; } break; case USER_EVENT: case ATT_CONF_EVENT: case INTERFACE_CHANGE_EVENT: break; case PERIODIC_EVENT: default: throwError = true; break; } if (throwError) { DevFailedUtils.throwDevFailed(ExceptionMessages.ATTR_NOT_POLLED, "The polling (necessary to send events) for the attribute " + objName + " is not started"); } else { device = deviceImpl; attribute = attributeImpl; } } } } // end for } // end if } // end if } // end for } // end for if (eventType.equals(EventType.PIPE_EVENT)) { if (pipe == null) { DevFailedUtils.throwDevFailed(ExceptionMessages.ATTR_NOT_FOUND, "Pipe " + objName + " not found"); } } else if (!eventType.equals(EventType.INTERFACE_CHANGE_EVENT) && attribute == null) { // Not // found DevFailedUtils.throwDevFailed(ExceptionMessages.ATTR_NOT_FOUND, "Attribute " + objName + " not found"); } if (device == null) { // Not found DevFailedUtils.throwDevFailed(ExceptionMessages.DEVICE_NOT_FOUND, "Device " + deviceName + " not found"); } return ImmutablePair.of(pipe, attribute); }