List of usage examples for org.apache.commons.lang3.tuple Pair getValue
@Override
public R getValue()
Gets the value from this pair.
This method implements the Map.Entry interface returning the right element as the value.
From source file:org.forgerock.openidm.servlet.internal.ServletConnectionFactory.java
/** * Create a Filter from the filter configuration. * * @param config/*from w ww . j a v a2s .co m*/ * the configuration describing a single filter. * @return a Filter * @throws org.forgerock.json.JsonValueException * TODO. */ private Filter newFilter(JsonValue config) throws JsonValueException, ScriptException { FilterCondition filterCondition = null; final Pair<JsonPointer, ScriptEntry> condition = getScript(config.get("condition")); final Pair<JsonPointer, ScriptEntry> onRequest = getScript(config.get("onRequest")); final Pair<JsonPointer, ScriptEntry> onResponse = getScript(config.get("onResponse")); final Pair<JsonPointer, ScriptEntry> onFailure = getScript(config.get("onFailure")); // Require at least one of the following if (null == onRequest && null == onResponse && null == onFailure) { return null; } // Check for condition on pattern Pattern pattern = config.get("pattern").asPattern(); if (null != pattern) { filterCondition = Filters.matchResourcePath(pattern); } // Check for condition on type final EnumSet<RequestType> requestTypes = EnumSet.noneOf(RequestType.class); for (JsonValue method : config.get("methods").expect(List.class)) { requestTypes.add(method.asEnum(RequestType.class)); } if (!requestTypes.isEmpty()) { filterCondition = (null == filterCondition) ? Filters.matchRequestType(requestTypes) : Filters.and(filterCondition, Filters.matchRequestType(requestTypes)); } // Create the filter Filter filter = (null == filterCondition) ? new ScriptedFilter(onRequest, onResponse, onFailure) : Filters.conditionalFilter(filterCondition, new ScriptedFilter(onRequest, onResponse, onFailure)); // Check for a condition script if (null != condition) { FilterCondition conditionFilterCondition = new FilterCondition() { @Override public boolean matches(final Context context, final Request request) { try { final Script script = condition.getValue().getScript(context); script.put("request", request); script.put("context", context); return (Boolean) script.eval(); } catch (ScriptException e) { logger.warn("Failed to evaluate filter condition: ", e.getMessage(), e); } return false; } }; filter = Filters.conditionalFilter(conditionFilterCondition, filter); } return filter; }
From source file:org.grouplens.lenskit.cli.ScriptEnvironment.java
public ScriptEnvironment(Namespace ns) { properties = new Properties(); List<Pair<String, String>> props = ns.getList("properties"); if (props != null) { for (Pair<String, String> arg : props) { properties.setProperty(arg.getKey(), arg.getValue()); }//from w ww. j av a 2 s . com } List<URI> cp = ns.getList("classpath"); if (cp != null) { classpath = cp; } else { classpath = Collections.emptyList(); } }
From source file:org.gvnix.addon.jpa.addon.entitylistener.JpaOrmEntityListenerOperationsImpl.java
/** * Gets or creates a xml element (with tag-name <code>elementName</code>) on * <code>parent</code>./*from w w w.ja va2s. c o m*/ * <p/> * If <code>attributeValue</code> is provided will be used to search and * applied to the creation. * * @param document xml document instance * @param parent node to add the new xml element * @param elementName new xml tag name * @param attributeValue (optional) attribute name + attribute value * @return Element found; true if element is new */ private Pair<Element, Boolean> getOrCreateElement(Document document, Element parent, String elementName, Pair<String, String> attributeValue) { boolean changed = false; // prepare xpath expression to search for element StringBuilder sbXpath = new StringBuilder(); sbXpath.append(elementName); if (attributeValue != null) { sbXpath.append("[@"); sbXpath.append(attributeValue.getKey()); sbXpath.append("='"); sbXpath.append(attributeValue.getValue()); sbXpath.append("']"); } String xpath = sbXpath.toString(); // Search for element Element targetElement = XmlUtils.findFirstElement(xpath, parent); if (targetElement == null) { // Not found: create it targetElement = document.createElement(elementName); if (attributeValue != null) { targetElement.setAttribute(attributeValue.getKey(), attributeValue.getValue()); } parent.appendChild(targetElement); // search again targetElement = XmlUtils.findFirstElement(xpath, parent); if (targetElement == null) { // something went worng throw new IllegalStateException("Can't create ".concat(xpath).concat(" element")); } changed = true; } return ImmutablePair.of(targetElement, changed); }
From source file:org.janusgraph.diskstorage.lucene.LuceneIndex.java
private void mutateStores(Map.Entry<String, Map<String, IndexMutation>> stores, KeyInformation.IndexRetriever informations) throws IOException, BackendException { IndexReader reader = null;/* w w w .j a v a 2 s . com*/ try { String storename = stores.getKey(); IndexWriter writer = getWriter(storename); reader = DirectoryReader.open(writer, true); IndexSearcher searcher = new IndexSearcher(reader); for (Map.Entry<String, IndexMutation> entry : stores.getValue().entrySet()) { String docid = entry.getKey(); IndexMutation mutation = entry.getValue(); if (mutation.isDeleted()) { if (log.isTraceEnabled()) log.trace("Deleted entire document [{}]", docid); writer.deleteDocuments(new Term(DOCID, docid)); continue; } Pair<Document, Map<String, Shape>> docAndGeo = retrieveOrCreate(docid, searcher); Document doc = docAndGeo.getKey(); Map<String, Shape> geofields = docAndGeo.getValue(); Preconditions.checkNotNull(doc); for (IndexEntry del : mutation.getDeletions()) { Preconditions.checkArgument(!del.hasMetaData(), "Lucene index does not support indexing meta data: %s", del); String key = del.field; if (doc.getField(key) != null) { if (log.isTraceEnabled()) log.trace("Removing field [{}] on document [{}]", key, docid); doc.removeFields(key); geofields.remove(key); } } addToDocument(storename, docid, doc, mutation.getAdditions(), geofields, informations); //write the old document to the index with the modifications writer.updateDocument(new Term(DOCID, docid), doc); } writer.commit(); } finally { IOUtils.closeQuietly(reader); } }
From source file:org.janusgraph.diskstorage.lucene.LuceneIndex.java
@Override public void restore(Map<String, Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException { writerLock.lock();/* w w w. j av a 2 s . c om*/ try { for (Map.Entry<String, Map<String, List<IndexEntry>>> stores : documents.entrySet()) { String store = stores.getKey(); IndexWriter writer = getWriter(store); IndexReader reader = DirectoryReader.open(writer, true); IndexSearcher searcher = new IndexSearcher(reader); for (Map.Entry<String, List<IndexEntry>> entry : stores.getValue().entrySet()) { String docID = entry.getKey(); List<IndexEntry> content = entry.getValue(); if (content == null || content.isEmpty()) { if (log.isTraceEnabled()) log.trace("Deleting document [{}]", docID); writer.deleteDocuments(new Term(DOCID, docID)); continue; } Pair<Document, Map<String, Shape>> docAndGeo = retrieveOrCreate(docID, searcher); addToDocument(store, docID, docAndGeo.getKey(), content, docAndGeo.getValue(), informations); //write the old document to the index with the modifications writer.updateDocument(new Term(DOCID, docID), docAndGeo.getKey()); } writer.commit(); } tx.commit(); } catch (IOException e) { throw new TemporaryBackendException("Could not update Lucene index", e); } finally { writerLock.unlock(); } }
From source file:org.jsonman.finder.RecursiveVisitor.java
@Override public void visit(MapNode node) { for (Pair<String, Node> e : node.getChildrenWithName()) { paths.addLast(new MapReference(e.getKey())); e.getValue().accept(this); paths.removeLast();/*www.ja va 2s .co m*/ } }
From source file:org.jsweet.input.typescriptdef.visitor.StringTypeCreator.java
@Override public void visitTypeReference(TypeReference typeReference) { super.visitTypeReference(typeReference); if (typeReference.isStringType()) { TypedDeclaration parentDeclaration = getParent(TypedDeclaration.class); String jsName = strip(typeReference.getName(), "['\"]"); String javaName = toJavaStringType(typeReference.getName()); TypeReference stringTypeReference = null; // try to get parent type reference FunctionDeclaration method = getParent(FunctionDeclaration.class, parentDeclaration); TypeDeclaration declaringType = getParent(TypeDeclaration.class, method); if (method != null && declaringType != null) { Pair<TypeDeclaration, FunctionDeclaration> parentMethod = findSuperMethod(declaringType, method); if (parentMethod != null) { String superMethodQualifiedName = context.getTypeName(parentMethod.getKey()) + "." + parentMethod.getValue().getName(); QualifiedDeclaration<TypedDeclaration> superDeclaration = context.findFirstDeclaration( TypedDeclaration.class, superMethodQualifiedName + "." + parentDeclaration.getName()); logger.info("\n\n)))))) => " + superMethodQualifiedName + "." + parentDeclaration.getName() + " => " + superDeclaration); stringTypeReference = superDeclaration.getDeclaration().getType(); }//from w w w. jav a2 s . c o m } // if type is not resolved, we add it if (stringTypeReference == null) { stringTypeReference = addStringType(typeReference, jsName, javaName); } assert !stringTypeReference.isStringType() : "String type should be expanded by now"; Util.substituteTypeReference(this, parentDeclaration, typeReference, stringTypeReference); } }
From source file:org.kalypso.kalypso1d2d.internal.importNet.AbstractImport2DImportOperation.java
@Override public final IStatus execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException { monitor.beginTask(Messages.getString("AbstractImport2DImportOperation_0"), 100); //$NON-NLS-1$ /* Read the file */ final String srs = m_importData.getSrs(); final int sourceSrid = JTSAdapter.toSrid(srs); final File importFile = m_importData.getFile(); monitor.subTask(/* w w w. j a va 2s.c o m*/ String.format(Messages.getString("AbstractImport2DImportOperation_1"), importFile.getName())); //$NON-NLS-1$ final Pair<IStatus, IPolygonWithName[]> readData = readFileData(importFile, sourceSrid, new SubProgressMonitor(monitor, 33)); final IStatus readStatus = readData.getKey(); final IPolygonWithName[] value = readData.getValue(); if (readStatus.matches(IStatus.ERROR)) { /* Stop here, old data remains unchanged */ return readStatus; } /* Check for cancel */ ProgressUtilities.worked(monitor, 0); monitor.subTask( String.format(Messages.getString("AbstractImport2DImportOperation_2"), importFile.getName())); //$NON-NLS-1$ analyzeElements(value); /* Check for cancel */ ProgressUtilities.worked(monitor, 0); m_data.setElements(value); m_data.setLastReadStatus(readStatus); /* always only return read status, the analyse status is shown in the details panel */ return readStatus; }
From source file:org.kalypso.kalypsomodel1d2d.ui.map.channeledit.editdata.BanklineIntersector.java
private BankData intersectBankline(final IProfileData downProfile, final IProfileData upProfile) throws GM_Exception { final LineString upProfileLine = convertProfilesToLineStrings(upProfile); final LineString downProfileLine = convertProfilesToLineStrings(downProfile); final Pair<LineString, Pair<Point, Point>> intersection = findBankForProfiles(downProfileLine, upProfileLine);// w w w . ja v a2 s . c o m if (intersection == null) return null; final Pair<Point, Point> points = intersection.getValue(); final Point downPoint = points.getLeft(); final Point upPoint = points.getRight(); final LineString bankLine = intersection.getKey(); /* extract line between start end end intersection */ final LineString croppedBankLine = (LineString) JTSUtilities.extractLineString(bankLine, downPoint, upPoint); /* handle z values of start a<nd end point */ final double downZ = findIntersectionZ(downProfile, croppedBankLine.getStartPoint(), bankLine); final double upZ = findIntersectionZ(upProfile, croppedBankLine.getEndPoint(), bankLine); /* cropped line has z if bankLine has z; addionally, we want to force the profile height onto the endpoints */ final LineString croppedBankLineWithZEndPoints = replaceEndpointZ(croppedBankLine, downZ, upZ); /* now make sure, we have z everywhere */ final LineString croppedBankLineWithZ = JTSUtilities.interpolateMissingZ(croppedBankLineWithZEndPoints); final LineString segmentedGeometry = ChannelEditUtil.intersectLineString(croppedBankLineWithZ, m_numberOfBankPoints); return new BankData(m_segment, bankLine, croppedBankLine, segmentedGeometry, false); }
From source file:org.kalypso.model.flood.ui.map.EventManagementWidget.java
protected void handleEventSelectionChanged(final ScrolledComposite sc, final Pair<Group, FeatureComposite> infoGroupComponents, final IStructuredSelection selection) { m_treeSelection = selection.toArray(); final Group infoGroup = infoGroupComponents.getKey(); final FeatureComposite infoComposite = infoGroupComponents.getValue(); infoComposite.disposeControl();/*from ww w .j av a 2s . com*/ final IRunoffEvent runoffEvent = getSelectedEvent(); IKalypsoFeatureTheme runoffEventTheme = findThemeForEvent(runoffEvent); try { // Always check, if sld file exists if (runoffEvent != null) AddEventOperation.checkSLDFile(runoffEvent, getEventFolder(runoffEvent), SLD_TEMPLATE_LOCATION); final IKalypsoCascadingTheme wspThemes = findWspTheme(); if (runoffEventTheme == null && runoffEvent != null) { /* A bit crude: if the theme does not yet exist, we create it right now */ AddEventOperation.addEventThemes(wspThemes, runoffEvent); } /* Also add result theme if results are available */ if (runoffEvent != null && getResultFolder(runoffEvent).exists() && FloodModelHelper.findResultTheme(runoffEvent, wspThemes) == -1) FloodModelHelper.addResultTheme(runoffEvent, wspThemes, -1); } catch (final Exception e) { e.printStackTrace(); } runoffEventTheme = findThemeForEvent(runoffEvent); // TODO: add theme if missing if (runoffEventTheme == null) m_infoWidget.setThemes(null); else m_infoWidget.setThemes(new IKalypsoTheme[] { runoffEventTheme }); updateStylePanel(runoffEventTheme); if (m_treeSelection != null && m_treeSelection.length > 0) { infoComposite.setFeature((Feature) m_treeSelection[0]); infoComposite.createControl(infoGroup, SWT.NONE); } sc.getParent().layout(true, true); final Control panel = sc.getContent(); final Point size = panel.computeSize(SWT.DEFAULT, SWT.DEFAULT); panel.setSize(size); sc.setMinHeight(size.y); getMapPanel().repaintMap(); }