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.kitodo.dataaccess.storage.memory.MemoryNode.java
@Override public List<Result> getEnumerated() { Pair<Long, Long> range = range(); if (range == null) { return Collections.emptyList(); }/* ww w . j a v a2s.c o m*/ ArrayList<Result> result = new ArrayList<>(range.getValue().intValue()); for (long i = 0; i < (range.getKey() - 1); i++) { result.add(new MemoryResult()); } for (long i = range.getKey(); i <= range.getValue(); i++) { result.add(get(i)); } return result; }
From source file:org.kitodo.dataaccess.storage.memory.MemoryNode.java
@Override public Optional<Long> last() { Pair<Long, Long> range = range(); return range == null ? Optional.empty() : Optional.of(range.getValue()); }
From source file:org.kitodo.dataaccess.storage.memory.MemoryNode.java
@Override public boolean removeFirstOccurrence(Object object) { Pair<Long, Long> range = range(); if (range == null) { return false; }/*from w w w. ja v a 2 s .c o m*/ for (long i = range.getKey(); i <= range.getValue(); i++) { String current = RDF.toURL(i); Collection<ObjectType> objects = edges.get(current); if (objects.remove(object)) { if (objects.isEmpty()) { edges.remove(current); long pos = i; String next; while (edges.containsKey(next = RDF.toURL(++pos))) { edges.put(current, edges.remove(next)); current = next; } } return true; } } return false; }
From source file:org.kitodo.dataaccess.storage.memory.MemoryNode.java
@Override public boolean removeLastOccurrence(Object object) { Pair<Long, Long> range = range(); if (range == null) { return false; }//w w w .j a v a2s.c o m for (long i = range.getValue(); i >= range.getKey(); i--) { String current = RDF.toURL(i); Collection<ObjectType> objects = edges.get(current); if (objects.remove(object)) { if (objects.isEmpty()) { edges.remove(current); long pos = i; String next; while (edges.containsKey(next = RDF.toURL(++pos))) { edges.put(current, edges.remove(next)); current = next; } } return true; } } return false; }
From source file:org.kitodo.dataeditor.ruleset.Labeled.java
/** * Lists the entries alphabetically by the translated label, taking into * account the language preferred by the user for alphabetical sorting. In * the auxiliary map, the keys are sorted by the sequence translated label + * separator + key, to account for the case where multiple keys are * (inadvertently) translated equally.// www.jav a2 s. c o m * * @param ruleset * The ruleset. From the ruleset, we learn which language is a * label that does not have a language attribute, that is what is * the default language of the rule set. * @param elements * The items to sort. The function is so generic that you can * sort divisions, keys, and options with it. * @param keyGetter * A function to extract from the element the value used in the * result map as key. * @param labelGetter * A function that allows you to extract the list of labels from * the element and then select the best translated one. * @param priorityList * The list of languages spoken by the user human * @return a map in the order of the best-fitting translated label */ public static <T> LinkedHashMap<String, String> listByTranslatedLabel(Ruleset ruleset, Collection<T> elements, Function<T, String> keyGetter, Function<T, Collection<Label>> labelGetter, List<LanguageRange> priorityList) { Locale sortLocale = Locale.lookup(priorityList, Arrays.asList(Collator.getAvailableLocales())); TreeMap<String, Pair<String, String>> byLabelSorter = sortLocale != null ? new TreeMap<>(Collator.getInstance(sortLocale)) : new TreeMap<>(); for (T element : elements) { String key = keyGetter.apply(element); Labeled labeled = new Labeled(ruleset, key, labelGetter.apply(element)); String label = labeled.getLabel(priorityList); byLabelSorter.put(label + '\037' + key, Pair.of(key, label)); } LinkedHashMap<String, String> result = new LinkedHashMap<>((int) Math.ceil(elements.size() / 0.75)); for (Pair<String, String> entry : byLabelSorter.values()) { result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:org.kitodo.filemanagement.locking.ImmutableReadFileManagement.java
/** * Returns the immutable read copy for a user and a URI. If necessary, the * file must be created at this point./*ww w . jav a 2s. co m*/ * * @param user * user for whom the immutable read copy is to be returned * @param uri * URI for which the immutable read copy is to be returned * @return the immutable read copy * @throws IOException * if the file does not exist or if an error occurs in disk * access, e.g. because the write permission for the directory * is missing */ URI getImmutableReadCopy(String user, URI uri) throws IOException { urisGivenToUsers.computeIfAbsent(uri, create -> new UserMapForURI()); UserMapForURI userMapForURI = urisGivenToUsers.get(uri); if (userMapForURI.containsKey(user)) { Pair<URI, AtomicInteger> uriWithCount = userMapForURI.get(user); uriWithCount.getValue().incrementAndGet(); return uriWithCount.getKey(); } else { URI uriOfImmutableReadCopy = getUpToDateCopy(uri); userMapForURI.put(user, Pair.of(uriOfImmutableReadCopy, new AtomicInteger(1))); return uriOfImmutableReadCopy; } }
From source file:org.kitodo.filemanagement.locking.ImmutableReadFileManagement.java
/** * Removes a reference to the use of a file as a temporary copy. If no * reference is left, the user is logged out of the temporary copy. Then it * will also be checked if the copy can be deleted. * * @param originUri//from w ww.j a v a 2 s . co m * URI to which the user requested the immutable read lock, that * is, the URI of the original file * @param user * user who held the lock */ void maybeRemoveReadFile(URI originUri, String user) { UserMapForURI userMapForURI = urisGivenToUsers.get(originUri); if (Objects.nonNull(userMapForURI)) { Pair<URI, AtomicInteger> copyUriWithCount = userMapForURI.get(user); if (copyUriWithCount.getValue().decrementAndGet() == 0) { userMapForURI.remove(user); if (userMapForURI.isEmpty()) { urisGivenToUsers.remove(originUri); } cleanUp(copyUriWithCount.getKey(), originUri); } } }
From source file:org.kitodo.production.forms.dataeditor.FieldedMetadataTableRow.java
/** * Reads the contents of the meta-data panel and stores the values in the * appropriate place. If the line is used to edit a field of the METS * structure, this field is set, otherwise the meta-data will be stored in * the list. The hidden meta-data is also written back there again. * * @throws InvalidMetadataValueException * if the content of a meta-data input field is syntactically * wrong// w w w.j a va 2 s. c o m * @throws NoSuchMetadataFieldException * if an input shall be saved to a field of the structure, but * there is no setter corresponding to the name configured in * the rule set */ void preserve() throws InvalidMetadataValueException, NoSuchMetadataFieldException { try { metadata.clear(); for (MetadataTableRow row : rows) { Pair<Method, Object> metsFieldValue = row.getStructureFieldValue(); if (Objects.nonNull(metsFieldValue)) { try { metsFieldValue.getKey().invoke(structure, metsFieldValue.getValue()); } catch (IllegalAccessException | InvocationTargetException e) { throw new IllegalStateException(e); } } else { metadata.addAll(row.getMetadata()); } } metadata.addAll(hiddenMetadata); } catch (InvalidMetadataValueException invalidValueException) { if (Objects.isNull(structure)) { invalidValueException.addParent(metadataView.getId()); } throw invalidValueException; } }
From source file:org.kuali.student.poc.jsonparser.json.SimpleJsonMap.java
public BaseJsonObject get(String key) { for (Pair<String, BaseJsonObject> keyValue : keyValues) { if (keyValue.getKey().equals(key)) { return keyValue.getValue(); }/*from www. j a v a 2 s . co m*/ } return null; }
From source file:org.languagetool.rules.spelling.morfologik.suggestions_ordering.SuggestionsOrderer.java
private float processRow(String sentence, String correctedSentence, String covered, String replacement, Integer contextLength) {/* w ww.j av a 2s.c o m*/ Pair<String, String> context = Pair.of("", ""); int errorStartIdx; int sentencesDifferenceCharIdx = ContextUtils.firstDifferencePosition(sentence, correctedSentence); if (sentencesDifferenceCharIdx != -1) { errorStartIdx = ContextUtils.startOfErrorString(sentence, covered, sentencesDifferenceCharIdx); if (errorStartIdx != -1) { context = ContextUtils.extractContext(sentence, covered, errorStartIdx, contextLength); } } String leftContextCovered = context.getKey(); String rightContextCovered = context.getValue(); String leftContextCorrection = leftContextCovered.isEmpty() ? "" : leftContextCovered.substring(0, leftContextCovered.length() - covered.length()) + replacement; String rightContextCorrection = rightContextCovered.isEmpty() ? "" : replacement + rightContextCovered.substring(covered.length()); boolean firstLetterMatches = ContextUtils.longestCommonPrefix(new String[] { replacement, covered }) .length() != 0; Integer editDistance = ContextUtils.editDistance(covered, replacement); List<String> leftContextCoveredTokenized = nGramUtil .tokenizeString(leftContextCovered.isEmpty() ? covered : leftContextCovered); double leftContextCoveredProba = nGramUtil.stringProbability(leftContextCoveredTokenized, 3); List<String> rightContextCoveredTokenized = nGramUtil .tokenizeString(rightContextCovered.isEmpty() ? covered : rightContextCovered); double rightContextCoveredProba = nGramUtil.stringProbability(rightContextCoveredTokenized, 3); List<String> leftContextCorrectionTokenized = nGramUtil .tokenizeString(leftContextCorrection.isEmpty() ? replacement : leftContextCorrection); double leftContextCorrectionProba = nGramUtil.stringProbability(leftContextCorrectionTokenized, 3); List<String> rightContextCorrectionTokenized = nGramUtil .tokenizeString(rightContextCorrection.isEmpty() ? replacement : rightContextCorrection); double rightContextCorrectionProba = nGramUtil.stringProbability(rightContextCorrectionTokenized, 3); float left_context_covered_length = leftContextCoveredTokenized.size(); float left_context_covered_proba = (float) leftContextCoveredProba; float right_context_covered_length = rightContextCoveredTokenized.size(); float right_context_covered_proba = (float) rightContextCoveredProba; float left_context_correction_length = leftContextCorrectionTokenized.size(); float left_context_correction_proba = (float) leftContextCorrectionProba; float right_context_correction_length = rightContextCorrectionTokenized.size(); float right_context_correction_proba = (float) rightContextCorrectionProba; float first_letter_matches = firstLetterMatches ? 1f : 0f; float edit_distance = editDistance; float[] data = { left_context_covered_length, left_context_covered_proba, right_context_covered_length, right_context_covered_proba, left_context_correction_length, left_context_correction_proba, right_context_correction_length, right_context_correction_proba, first_letter_matches, edit_distance }; FVec featuresVector = FVec.Transformer.fromArray(data, false); double[] predictions = predictor.predict(featuresVector); double predictedScore = predictions.length == 0 ? 0 : predictions[0]; return (float) predictedScore; }