List of usage examples for org.apache.commons.lang3.tuple Pair getKey
@Override public final L getKey()
Gets the key from this pair.
This method implements the Map.Entry interface returning the left element as the key.
From source file:org.forgerock.openidm.security.impl.PrivateKeyResourceProvider.java
@Override public void createDefaultEntry(String alias) throws Exception { Pair<X509Certificate, PrivateKey> pair = generateCertificate("localhost", "OpenIDM Self-Signed Certificate", "None", "None", "None", "None", DEFAULT_ALGORITHM, DEFAULT_KEY_SIZE, DEFAULT_SIGNATURE_ALGORITHM, null, null);/*from w ww .j a v a 2s . c o m*/ Certificate cert = pair.getKey(); PrivateKey key = pair.getValue(); store.getStore().setEntry(alias, new PrivateKeyEntry(key, new Certificate[] { cert }), new KeyStore.PasswordProtection(store.getPassword().toCharArray())); store.store(); }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.planning.planner.greedy.GreedyPlanner.java
/** * Creates an {@link ValueJoinNode} from the specified arguments. * * @param leftEntry left entry/*from w ww. j a v a2 s. co m*/ * @param rightEntry right entry * @param joinPredicate join predicate * * @return new value join node */ private PlanTableEntry createValueJoinEntry(PlanTableEntry leftEntry, PlanTableEntry rightEntry, CNF joinPredicate) { List<Pair<String, String>> leftProperties = new ArrayList<>(); List<Pair<String, String>> rightProperties = new ArrayList<>(); for (CNFElement e : joinPredicate.getPredicates()) { ComparisonExpression comparison = e.getPredicates().get(0); Pair<String, String> joinProperty = extractJoinProperty(comparison.getLhs()); if (leftEntry.getAllVariables().contains(joinProperty.getKey())) { leftProperties.add(joinProperty); } else { rightProperties.add(joinProperty); } joinProperty = extractJoinProperty(comparison.getRhs()); if (leftEntry.getAllVariables().contains(joinProperty.getKey())) { leftProperties.add(joinProperty); } else { rightProperties.add(joinProperty); } } ValueJoinNode node = new ValueJoinNode(leftEntry.getQueryPlan().getRoot(), rightEntry.getQueryPlan().getRoot(), leftProperties, rightProperties, vertexStrategy, edgeStrategy); Set<String> processedVariables = leftEntry.getProcessedVariables(); processedVariables.addAll(rightEntry.getProcessedVariables()); CNF predicates = mergePredicates(leftEntry, rightEntry); return new PlanTableEntry(GRAPH, processedVariables, predicates, new QueryPlanEstimator(new QueryPlan(node), queryHandler, graphStatistics)); }
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 ww w . j av a 2 s . c o m } 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
/** * Adjust listener order as is registered on * {@link JpaOrmEntityListenerRegistry}/*from w ww. j a va 2 s . co m*/ * * @param ormXml * @param entityListenerElement * @param entityListenerElements * @return true if xml elements had been changed */ private boolean adjustEntityListenerOrder(Document ormXml, Element entityListenerElement, List<Element> entityListenerElements) { // Prepare a Pair list which is a representation of current // entity-listener List<Pair<String, String>> currentOrder = new ArrayList<Pair<String, String>>(); for (Element currentElement : entityListenerElements) { // Each Pair: key (left) = entity-listener class; value (right) // metadataProvider id currentOrder.add(ImmutablePair.of(currentElement.getAttribute(CLASS_ATTRIBUTE), getEntityListenerElementType(currentElement))); } // Create a comparator which can sort the list based on order configured // on registry ListenerOrderComparator comparator = new ListenerOrderComparator(registry.getListenerOrder()); // Clone the Pair list and sort it List<Pair<String, String>> ordered = new ArrayList<Pair<String, String>>(currentOrder); Collections.sort(ordered, comparator); // Check if elements order is different form original boolean changeOrder = false; Pair<String, String> currentPair, orderedPair; for (int i = 0; i < currentOrder.size(); i++) { currentPair = currentOrder.get(i); orderedPair = ordered.get(i); if (!StringUtils.equals(currentPair.getKey(), orderedPair.getKey())) { changeOrder = true; break; } } if (!changeOrder) { // Order is correct: nothing to do return false; } // List for new elements to add List<Node> newList = new ArrayList<Node>(entityListenerElements.size()); // Iterate over final ordered list int curIndex; Node cloned, old; for (int i = 0; i < ordered.size(); i++) { orderedPair = ordered.get(i); // Gets old listener XML node curIndex = indexOfListener(entityListenerElements, orderedPair.getKey()); old = entityListenerElements.get(curIndex); // Clone old node and add to new elements list cloned = old.cloneNode(true); newList.add(cloned); // Remove old listener node from parent entityListenerElement.removeChild(old); } // Add listeners xml nodes to parent again in final order for (Node node : newList) { entityListenerElement.appendChild(node); } return true; }
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>./*w w w.j a v a2 s .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;//from ww w . j a v a 2s. c o m 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();/*from w w w . ja v a 2s . c o m*/ 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();/*from w w w .j a va2 s .com*/ } }
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 ww w.ja v 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(/*from w w w.j ava 2 s.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; }