List of usage examples for org.apache.commons.lang3.tuple Pair getLeft
public abstract L getLeft();
Gets the left element from this pair.
When treated as a key-value pair, this is the key.
From source file:com.ottogroup.bi.streaming.operator.json.insert.JsonStaticContentInsertion.java
public JsonStaticContentInsertion(final List<Pair<JsonContentReference, Serializable>> values) throws IllegalArgumentException { /////////////////////////////////////////////////////// // validate input if (values == null) // empty input "configures" the operator to work as simple "pass-through" operator throw new IllegalArgumentException("Missing required input"); /////////////////////////////////////////////////////// for (final Pair<JsonContentReference, Serializable> v : values) { if (v == null) throw new IllegalArgumentException("Empty list elements are not permitted"); if (v.getLeft() == null || v.getKey().getPath() == null || v.getKey().getPath().length < 1) throw new IllegalArgumentException("Empty content referenced are not permitted"); if (v.getRight() == null) throw new IllegalArgumentException("Null is not permitted as insertion value"); this.values.add(v); }//from w ww . j a v a 2 s . co m }
From source file:de.hasait.clap.impl.AbstractCLAPDecision.java
@Override public final void printUsage(final Map<CLAPUsageCategoryImpl, StringBuilder> pCategories, final CLAPUsageCategoryImpl pCurrentCategory, final StringBuilder pResult) { final Pair<CLAPUsageCategoryImpl, StringBuilder> pair = handleUsageCategory(pCategories, pCurrentCategory, pResult);// w ww . ja v a2s. com if (pair != null) { final CLAPUsageCategoryImpl currentCategory = pair.getLeft(); final StringBuilder result = pair.getRight(); if (list().size() > 1) { result.append("{ "); //$NON-NLS-1$ } internalPrintUsage(pCategories, currentCategory, result, " | "); //$NON-NLS-1$ if (list().size() > 1) { result.append(" }"); //$NON-NLS-1$ } } }
From source file:fr.lirmm.graphik.graal.forward_chaining.ChaseWithGRDAndUnfiers.java
@Override public void next() throws ChaseException { Rule rule, unifiedRule;/*from w w w . j av a 2 s . c o m*/ Substitution unificator; try { Pair<Rule, Substitution> pair = queue.poll(); if (pair != null) { unificator = pair.getRight(); rule = pair.getLeft(); unifiedRule = Unifier.computeInitialAtomSetTermsSubstitution(rule.getBody()).createImageOf(rule); unifiedRule = unificator.createImageOf(unifiedRule); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Execute rule: " + rule + " with unificator " + unificator); } if (this.getRuleApplier().apply(unifiedRule, this.atomSet)) { for (Integer e : this.grd.getOutgoingEdgesOf(rule)) { Rule triggeredRule = this.grd.getEdgeTarget(e); for (Substitution u : this.grd.getUnifiers(e)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("-- -- Dependency: " + triggeredRule + " with " + u); LOGGER.debug("-- -- Unificator: " + u); } if (u != null) { this.queue.add(new ImmutablePair<Rule, Substitution>(triggeredRule, u)); } } } } } } catch (Exception e) { throw new ChaseException("An error occur pending saturation step.", e); } }
From source file:mase.app.playground.Playground.java
protected void placeObstacles() { // Add closed polygons of random size. The addition of objects next must ensure no overlaps int nObstacles = par.minObstacles + (par.maxObstacles > par.minObstacles ? random.nextInt(par.maxObstacles - par.minObstacles) : 0); obstacles = new ArrayList<>(nObstacles); while (obstacles.size() < nObstacles) { MultilineObject obs = createObstacle(); Pair<Double2D, Double2D> bb = obs.getPolygon().boundingBox; double w = bb.getRight().x - bb.getLeft().x; double h = bb.getRight().y - bb.getLeft().y; Double2D candidate = new Double2D(random.nextDouble() * (par.arenaSize - w), random.nextDouble() * (par.arenaSize - h)); obs.setLocation(candidate);/*from w ww. j a v a2s. com*/ // overlap with the agent boolean valid = !obs.isInside(agent.getLocation()) && obs.distanceTo(agent.getLocation()) > agent.getRadius(); if (valid) { // overlap with other obstacles for (MultilineObject other : obstacles) { if (obs.getPolygon().boundingBoxOverlap(other.getPolygon())) { valid = false; break; } } } if (valid) { obstacles.add(obs); } else { field.remove(obs); } } }
From source file:name.martingeisse.phunky.runtime.code.expression.array.ArrayConstructionExpression.java
@Override public void dump(CodeDumper dumper) { dumper.print("array("); boolean first = true; for (Pair<Expression, Expression> element : elements) { if (first) { first = false;/* ww w.jav a 2s .c om*/ } else { dumper.print(", "); } if (element.getLeft() != null) { element.getLeft().dump(dumper); dumper.print(" => "); } element.getRight().dump(dumper); } dumper.print(')'); }
From source file:com.github.steveash.jg2p.align.AlignerTrainer.java
private double minAllowedCount() { double min = Double.POSITIVE_INFINITY; for (Pair<String, String> xy : allowed) { double p = counts.prob(xy.getLeft(), xy.getRight()); if (p > 0 && p < min) { min = p;//ww w . j a va2 s. co m } } return min; }
From source file:com.snaplogic.snaps.lunex.RequestBuilder.java
private String resolveUrl(final Document document) { try {//from www . jav a 2 s . co m String resourceSpecificUri = null; switch (snapType) { case Create: resourceSpecificUri = ServiceURIInfo.CR_URI_LIST.get(resource); break; case Read: resourceSpecificUri = ServiceURIInfo.RR_URI_LIST.get(resource); break; case Delete: resourceSpecificUri = ServiceURIInfo.DR_URI_LIST.get(resource); break; case Update: resourceSpecificUri = ServiceURIInfo.UR_URI_LIST.get(resource); break; } if (queryParams != null) { CharSequence source, target; for (Pair<String, ExpressionProperty> paramPair : queryParams) { source = new StringBuilder().append(OPENTAG).append(paramPair.getLeft()).append(CLOSETAG) .toString(); target = paramPair.getRight().eval(document).toString(); if (target == null) { target = StringUtils.EMPTY; } resourceSpecificUri = resourceSpecificUri.replace(source, target); } } return new StringBuilder().append(HTTP).append(COLON).append(DOUBLE_SLASH).append(IPAddress) .append(resourceSpecificUri).toString(); } catch (Exception e) { String msg = String.format(INVALID_URI, new StringBuilder().append(HTTP).append(COLON) .append(DOUBLE_SLASH).append(IPAddress).toString()); throw new ExecutionException(e, msg).withReason(msg).withResolution(INVALID_URI_RESOLUTION); } }
From source file:com.github.steveash.jg2p.align.AlignerTrainer.java
private void smoothCounts() { if (allowed == null) return;/*from w w w .ja v a 2 s . c om*/ // do some kind of discounted smoothing where we add 0.5 * c / k * smallest entry) to every entry in the counts // where c is the count of good transitions and k is the total count of transitions. And we're just going to // take half of that (arbitrarily) double c = allowed.size(); double k = blocked.size(); double discount = 0.5d * c / k; double toAdd = minAllowedCount() * discount; for (Pair<String, String> xy : allowed) { counts.addProb(xy.getLeft(), xy.getRight(), toAdd); } for (Pair<String, String> xy : blocked) { // we're forcing the blocked ones to be this small mass, whereas we're just adding the extra to the good xy counts.setProb(xy.getLeft(), xy.getRight(), toAdd); } }
From source file:com.streamsets.pipeline.lib.salesforce.ChangeDataCaptureRecordCreator.java
@Override @SuppressWarnings("unchecked") public Record createRecord(String sourceId, Object source) throws StageException { Pair<PartnerConnection, Map<String, Object>> pair = (Pair<PartnerConnection, Map<String, Object>>) source; PartnerConnection partnerConnection = pair.getLeft(); Map<String, Object> data = pair.getRight(); Map<String, Object> payload = (Map<String, Object>) data.get("payload"); Record rec = context.createRecord(sourceId); // Process ChangeEventHeader since we need the object type String objectType = null;//from w w w. j a v a 2 s . co m Record.Header recordHeader = rec.getHeader(); Map<String, Object> headers = (Map<String, Object>) payload.get(CHANGE_EVENT_HEADER); if (headers == null) { throw new StageException(Errors.FORCE_40); } // event data becomes header attributes // of the form salesforce.cdc.createdDate, // salesforce.cdc.type for (Map.Entry<String, Object> header : headers.entrySet()) { if ("recordIds".equals(header.getKey())) { // Turn list of record IDs into a comma-separated list recordHeader.setAttribute(HEADER_ATTRIBUTE_PREFIX + header.getKey(), String.join(",", (List<String>) header.getValue())); } else { recordHeader.setAttribute(HEADER_ATTRIBUTE_PREFIX + header.getKey(), header.getValue().toString()); if ("changeType".equals(header.getKey())) { int operationCode = SFDC_TO_SDC_OPERATION.get(header.getValue().toString()); recordHeader.setAttribute(OperationType.SDC_OPERATION_TYPE, String.valueOf(operationCode)); } else if ("entityName".equals(header.getKey())) { objectType = header.getValue().toString(); recordHeader.setAttribute(SOBJECT_TYPE_ATTRIBUTE, objectType); } } } payload.remove(CHANGE_EVENT_HEADER); // payload data becomes fields LinkedHashMap<String, Field> map = new LinkedHashMap<>(); for (Map.Entry<String, Object> entry : payload.entrySet()) { String key = entry.getKey(); Object val = entry.getValue(); if (!objectTypeIsCached(objectType)) { try { addObjectTypeToCache(partnerConnection, objectType); } catch (ConnectionException e) { throw new StageException(Errors.FORCE_21, objectType, e); } } com.sforce.soap.partner.Field sfdcField = getFieldMetadata(objectType, key); Field field = createField(val, sfdcField); if (conf.createSalesforceNsHeaders) { setHeadersOnField(field, getFieldMetadata(objectType, key)); } map.put(key, field); } rec.set(Field.createListMap(map)); return rec; }
From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouper.java
@Override public boolean hasNext() { if (_retVal != null) { return true; }/*from w ww . j a va 2 s . c om*/ while (_iterator.hasNext() && _retVal == null) { Pair<String, UrlTrieNode> nextPair = _iterator.next(); UrlTrieNode nextNode = nextPair.getRight(); if (nextNode.getSize() <= _groupSize) { _retVal = Triple.of(nextPair.getLeft(), GoogleWebmasterFilter.FilterOperator.CONTAINS, nextNode); return true; } else if (nextNode.isExist()) { _retVal = Triple.of(nextPair.getLeft(), GoogleWebmasterFilter.FilterOperator.EQUALS, nextNode); return true; } } return false; }