List of usage examples for org.apache.commons.lang3.tuple MutablePair getRight
@Override
public R getRight()
From source file:org.apache.hyracks.storage.am.lsm.btree.LSMBTreeFilterMergeTestDriver.java
@Override protected void runTest(ISerializerDeserializer[] fieldSerdes, int numKeys, BTreeLeafFrameType leafType, ITupleReference lowKey, ITupleReference highKey, ITupleReference prefixLowKey, ITupleReference prefixHighKey) throws Exception { OrderedIndexTestContext ctx = createTestContext(fieldSerdes, numKeys, leafType, true); ctx.getIndex().create();//from w ww. j a v a 2 s. c om ctx.getIndex().activate(); // Start off with one tree bulk loaded. // We assume all fieldSerdes are of the same type. Check the first one // to determine which field types to generate. if (fieldSerdes[0] instanceof IntegerSerializerDeserializer) { orderedIndexTestUtils.bulkLoadIntTuples(ctx, numTuplesToInsert, true, getRandom()); } else if (fieldSerdes[0] instanceof UTF8StringSerializerDeserializer) { orderedIndexTestUtils.bulkLoadStringTuples(ctx, numTuplesToInsert, true, getRandom()); } int maxTreesToMerge = AccessMethodTestsConfig.LSM_BTREE_MAX_TREES_TO_MERGE; ILSMIndexAccessor accessor = (ILSMIndexAccessor) ctx.getIndexAccessor(); IBinaryComparator comp = ctx.getComparatorFactories()[0].createBinaryComparator(); for (int i = 0; i < maxTreesToMerge; i++) { int flushed = 0; for (; flushed < i; flushed++) { Pair<ITupleReference, ITupleReference> minMax = null; if (fieldSerdes[0] instanceof IntegerSerializerDeserializer) { minMax = orderedIndexTestUtils.insertIntTuples(ctx, numTuplesToInsert, true, getRandom()); } else { minMax = orderedIndexTestUtils.insertStringTuples(ctx, numTuplesToInsert, true, getRandom()); } if (minMax != null) { ILSMComponentFilter f = ((LSMBTree) ctx.getIndex()).getCurrentMemoryComponent() .getLSMComponentFilter(); Pair<ITupleReference, ITupleReference> obsMinMax = filterToMinMax(f); Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(obsMinMax.getLeft(), minMax.getLeft(), comp)); Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(obsMinMax.getRight(), minMax.getRight(), comp)); } StubIOOperationCallback stub = new StubIOOperationCallback(); BlockingIOOperationCallbackWrapper waiter = new BlockingIOOperationCallbackWrapper(stub); accessor.scheduleFlush(waiter); waiter.waitForIO(); if (minMax != null) { Pair<ITupleReference, ITupleReference> obsMinMax = filterToMinMax( stub.getLastNewComponent().getLSMComponentFilter()); Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(obsMinMax.getLeft(), minMax.getLeft(), comp)); Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(obsMinMax.getRight(), minMax.getRight(), comp)); } } List<ILSMDiskComponent> flushedComponents = ((LSMBTree) ctx.getIndex()).getImmutableComponents(); MutablePair<ITupleReference, ITupleReference> expectedMergeMinMax = null; for (ILSMDiskComponent f : flushedComponents) { Pair<ITupleReference, ITupleReference> componentMinMax = filterToMinMax(f.getLSMComponentFilter()); if (expectedMergeMinMax == null) { expectedMergeMinMax = MutablePair.of(componentMinMax.getLeft(), componentMinMax.getRight()); } if (TreeIndexTestUtils.compareFilterTuples(expectedMergeMinMax.getLeft(), componentMinMax.getLeft(), comp) > 0) { expectedMergeMinMax.setLeft(componentMinMax.getLeft()); } if (TreeIndexTestUtils.compareFilterTuples(expectedMergeMinMax.getRight(), componentMinMax.getRight(), comp) < 0) { expectedMergeMinMax.setRight(componentMinMax.getRight()); } } accessor.scheduleMerge(NoOpIOOperationCallback.INSTANCE, ((LSMBTree) ctx.getIndex()).getImmutableComponents()); flushedComponents = ((LSMBTree) ctx.getIndex()).getImmutableComponents(); Pair<ITupleReference, ITupleReference> mergedMinMax = filterToMinMax( flushedComponents.get(0).getLSMComponentFilter()); Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(expectedMergeMinMax.getLeft(), mergedMinMax.getLeft(), comp)); Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(expectedMergeMinMax.getRight(), mergedMinMax.getRight(), comp)); orderedIndexTestUtils.checkPointSearches(ctx); orderedIndexTestUtils.checkScan(ctx); orderedIndexTestUtils.checkDiskOrderScan(ctx); orderedIndexTestUtils.checkRangeSearch(ctx, lowKey, highKey, true, true); if (prefixLowKey != null && prefixHighKey != null) { orderedIndexTestUtils.checkRangeSearch(ctx, prefixLowKey, prefixHighKey, true, true); } } ctx.getIndex().deactivate(); ctx.getIndex().destroy(); }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
public Map<String, MutablePair<String, CommentsNodeImpl>> copyMap(CommentsNodeImpl parent) { Map<String, MutablePair<String, CommentsNodeImpl>> result = new HashMap<>(this.dataMap.size()); for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : this.dataMap.entrySet()) { String keyToCpy = entry.getKey(); MutablePair<String, CommentsNodeImpl> valueToCpy = entry.getValue(); CommentsNodeImpl nodeToCpy = valueToCpy.getRight(); CommentsNodeImpl copiedNode;/*from w w w .j a va 2s. co m*/ if (nodeToCpy == null) { copiedNode = null; } else { copiedNode = new CommentsNodeImpl(parent); copiedNode.dataMap.putAll(nodeToCpy.copyMap(parent)); } MutablePair<String, CommentsNodeImpl> copied = new MutablePair<>(valueToCpy.getLeft(), copiedNode); result.put(keyToCpy, copied); } return result; }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
@Override public void trim() { for (Iterator<Entry<String, MutablePair<String, CommentsNodeImpl>>> iterator = this.dataMap.entrySet() .iterator(); iterator.hasNext();) { Entry<String, MutablePair<String, CommentsNodeImpl>> entry = iterator.next(); MutablePair<String, CommentsNodeImpl> value = entry.getValue(); CommentsNodeImpl right = value.getRight(); if (right != null) { right.trim();/*from w ww .ja va 2 s . c o m*/ } if (((right == null) || right.dataMap.isEmpty()) && (value.getLeft() == null)) { iterator.remove(); continue; } if (right == null) { continue; } right.trim(); } }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
@SuppressWarnings("unchecked") Map<String, MutablePair<String, ?>> buildMap() { Map<String, MutablePair<String, ?>> resultMap = new LinkedHashMap<>(this.dataMap.size()); for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : this.dataMap.entrySet()) { MutablePair<String, CommentsNodeImpl> value = entry.getValue(); CommentsNodeImpl right = value.getRight(); String left = value.getLeft(); if ((right == null) && (left == null)) { continue; }//from ww w.j a va2 s . co m Map<String, MutablePair<String, ?>> rightMap = null; if (right != null) { rightMap = right.buildMap(); if (rightMap.isEmpty()) { rightMap = null; if (left == null) { continue; } } } resultMap.put(entry.getKey(), new MutablePair<>(left, rightMap)); } return resultMap; }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
@Override public void join(CommentsNode toJoin_) { if (toJoin_ instanceof EmptyCommentsNode) { return;//w w w. ja v a2 s . com } if (!(toJoin_ instanceof CommentsNodeImpl)) { throw new IllegalArgumentException("Can't join to unknown node type."); } CommentsNodeImpl toJoin = (CommentsNodeImpl) toJoin_; for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : toJoin.dataMap.entrySet()) { String nodeKey = entry.getKey(); MutablePair<String, CommentsNodeImpl> pair = entry.getValue(); String nodeComment = pair.getLeft(); CommentsNodeImpl subNode = pair.getRight(); if (nodeComment != null) { this.setComment(nodeKey, nodeComment); } if (subNode != null) { this.join(nodeKey, subNode); } } }
From source file:org.diorite.config.serialization.comments.CommentsNodeImpl.java
@Override public CommentsNodeImpl getNode(String path) { MutablePair<String, CommentsNodeImpl> nodePair = this.dataMap.get(path); CommentsNodeImpl node = (nodePair == null) ? null : nodePair.getRight(); if (node == null) { MutablePair<String, CommentsNodeImpl> anyNodePair = this.dataMap.get(ANY); node = (anyNodePair == null) ? null : anyNodePair.getRight(); if (node == null) { CommentsNodeImpl commentsNode = new CommentsNodeImpl(this); if (nodePair != null) { nodePair.setRight(commentsNode); } else { this.dataMap.put(path, new MutablePair<>(null, commentsNode)); }//from w w w . j av a2 s. c o m return commentsNode; } return node; } return node; }
From source file:org.diorite.config.serialization.comments.CommentsWriter.java
@SuppressWarnings("unchecked") private void write(Map<String, MutablePair<String, ?>> map) throws IOException { this.updateIndent(true); int keys = map.entrySet().size(); int k = 0;//from w w w.j av a2 s . c o m for (Entry<String, MutablePair<String, ?>> entry : map.entrySet()) { k += 1; MutablePair<String, ?> pair = entry.getValue(); String comment = pair.getLeft(); Map<String, MutablePair<String, ?>> rightMap = (Map<String, MutablePair<String, ?>>) pair.getRight(); int rightKeys = (rightMap == null) ? 0 : rightMap.size(); boolean newLine = keys > 3; if (comment != null) { this.writeComment(comment); } String key = entry.getKey(); this.writeKey(key); if (rightMap != null) { this.write(rightMap); } if (newLine) { this.writeNewLine(false); } } this.writeNewLine(false); this.updateIndent(false); }
From source file:org.jsweet.input.typescriptdef.ast.Scanner.java
protected Pair<TypeDeclaration, FunctionDeclaration> findSuperMethod(TypeDeclaration declaringType, FunctionDeclaration method) {//from www . j a v a 2 s . com MutablePair<TypeDeclaration, FunctionDeclaration> superMethodInfos = new MutablePair<>(); applyToSuperMethod(declaringType, method, (superType, superMethod) -> { superMethodInfos.setLeft(superType); superMethodInfos.setRight(superMethod); }); return superMethodInfos.getRight() == null ? null : superMethodInfos; }
From source file:org.midonet.cluster.LocalDataClientImpl.java
private List<Pair<String, PoolHealthMonitorConfig>> buildPoolHealthMonitorMappings(UUID healthMonitorId, @Nullable HealthMonitorZkManager.HealthMonitorConfig config) throws MappingStatusException, SerializationException, StateAccessException { List<UUID> poolIds = healthMonitorZkManager.getPoolIds(healthMonitorId); List<Pair<String, PoolHealthMonitorConfig>> pairs = new ArrayList<>(); for (UUID poolId : poolIds) { PoolZkManager.PoolConfig poolConfig = poolZkManager.get(poolId); MutablePair<String, PoolHealthMonitorConfig> pair = preparePoolHealthMonitorMappings(poolId, poolConfig, poolMemberZkManager, vipZkManager); if (pair != null) { // Update health monitor config, which can be null PoolHealthMonitorConfig updatedMappingConfig = pair.getRight(); updatedMappingConfig.healthMonitorConfig = new HealthMonitorConfigWithId(config); pair.setRight(updatedMappingConfig); pairs.add(pair);// w ww. ja v a 2s . co m } } return pairs; }
From source file:org.openlmis.fulfillment.Resource2Db.java
Pair<List<String>, List<Object[]>> resourceCsvToBatchedPair(final Resource resource) throws IOException { XLOGGER.entry(resource.getDescription()); // parse CSV/*from www. j av a2s . co m*/ try (InputStreamReader isReader = new InputStreamReader( new BOMInputStream(resource.getInputStream(), ByteOrderMark.UTF_8))) { CSVParser parser = CSVFormat.DEFAULT.withHeader().withNullString("").parse(isReader); // read header row MutablePair<List<String>, List<Object[]>> readData = new MutablePair<>(); readData.setLeft(new ArrayList<>(parser.getHeaderMap().keySet())); XLOGGER.info("Read header: " + readData.getLeft()); // read data rows List<Object[]> rows = new ArrayList<>(); for (CSVRecord record : parser.getRecords()) { if (!record.isConsistent()) { throw new IllegalArgumentException("CSV record inconsistent: " + record); } List theRow = IteratorUtils.toList(record.iterator()); rows.add(theRow.toArray()); } readData.setRight(rows); XLOGGER.exit("Records read: " + readData.getRight().size()); return readData; } }