List of usage examples for org.apache.commons.lang3.tuple MutablePair getRight
@Override
public R getRight()
From source file:io.cloudslang.lang.tools.build.tester.parallel.report.SlangTestCaseRunReportGeneratorServiceTest.java
@Test public void generateTestCaseReportTable() throws IOException { HtmlCanvas canvas = mock(HtmlCanvas.class); IRunTestResults runTestResults = mock(IRunTestResults.class); final HtmlCanvas mockTable = mock(HtmlCanvas.class); HtmlCanvas mockTr = mock(HtmlCanvas.class); final MutablePair<Integer, Object> pair = new MutablePair<>(); doAnswer(new Answer() { @Override// ww w . ja va 2 s . co m public Object answer(InvocationOnMock invocationOnMock) throws Throwable { pair.setLeft(0); pair.setRight(invocationOnMock.getArguments()[0]); return mockTable; } }).when(canvas).table(any(HtmlAttributes.class)); doReturn(mockTr).when(mockTable).tr(); doReturn(mockTr).when(mockTr).th(); doReturn(mockTr).when(mockTr).content(anyString()); doReturn(mockTr).when(mockTr).th(any(CharactersWriteable.class)); doReturn(new HtmlCanvas()).when(mockTr)._tr(); doNothing().when(reportGeneratorService).appendTestRuns(any(HtmlCanvas.class), anyMap(), anyString()); Map<String, TestRun> success = mock(Map.class); Map<String, TestRun> failed = mock(Map.class); Map<String, TestRun> skipped = mock(Map.class); doReturn(success).when(runTestResults).getPassedTests(); doReturn(failed).when(runTestResults).getFailedTests(); doReturn(skipped).when(runTestResults).getSkippedTests(); reportGeneratorService.generateTestCaseReportTable(canvas, runTestResults); verify(canvas).table(eq((CharactersWriteable) pair.getRight())); verify(mockTable).tr(); InOrder mockTableInOrder = inOrder(mockTr); mockTableInOrder.verify(mockTr).th(); mockTableInOrder.verify(mockTr).content(eq(TEST_NAME)); mockTableInOrder.verify(mockTr).th(any(HtmlAttributes.class)); mockTableInOrder.verify(mockTr).content(TEST_SUITE); mockTableInOrder.verify(mockTr).th(any(HtmlAttributes.class)); mockTableInOrder.verify(mockTr).content(TEST_STATUS); mockTableInOrder.verify(mockTr).th(); mockTableInOrder.verify(mockTr).content(TEST_FLOW_PATH); mockTableInOrder.verify(mockTr).th(); mockTableInOrder.verify(mockTr).content(TEST_DESCRIPTION); mockTableInOrder.verify(mockTr).th(); mockTableInOrder.verify(mockTr).content(OUTPUTS); mockTableInOrder.verify(mockTr).th(); mockTableInOrder.verify(mockTr).content(EXCEPTION_OR_MESSAGE); mockTableInOrder.verify(mockTr)._tr(); mockTableInOrder.verifyNoMoreInteractions(); verify(reportGeneratorService).appendTestRuns(eq(mockTable), eq(success), eq(PASSED)); verify(reportGeneratorService).appendTestRuns(eq(mockTable), eq(failed), eq(FAILED)); verify(reportGeneratorService).appendTestRuns(eq(mockTable), eq(skipped), eq(SKIPPED)); }
From source file:bwem.Graph.java
private java.util.Map<MutablePair<AreaId, AreaId>, List<WalkPosition>> createRawFrontierByAreaPairMap( final List<MutablePair<MutablePair<AreaId, AreaId>, WalkPosition>> rawFrontier) { final java.util.Map<MutablePair<AreaId, AreaId>, List<WalkPosition>> rawFrontierByAreaPair = new HashMap<>(); for (final MutablePair<MutablePair<AreaId, AreaId>, WalkPosition> raw : rawFrontier) { int a = raw.getLeft().getLeft().intValue(); int b = raw.getLeft().getRight().intValue(); if (a > b) { final int a_tmp = a; a = b;/*from w ww.j a va2s .co m*/ b = a_tmp; } // bwem_assert(a <= b); if (!(a <= b)) { throw new IllegalStateException(); } // bwem_assert((a >= 1) && (b <= areasCount())); if (!((a >= 1) && (b <= getAreaCount()))) { throw new IllegalStateException(); } final MutablePair<AreaId, AreaId> key = new MutablePair<>(new AreaId(a), new AreaId(b)); rawFrontierByAreaPair.computeIfAbsent(key, mp -> new ArrayList<>()).add(raw.getRight()); } return rawFrontierByAreaPair; }
From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java
private void updateContextTable(CodeTemplateContextSet context) { DefaultMutableTreeTableNode root = (DefaultMutableTreeTableNode) templateContextTreeTable .getTreeTableModel().getRoot(); for (Enumeration<? extends MutableTreeTableNode> groups = root.children(); groups.hasMoreElements();) { MutableTreeTableNode group = groups.nextElement(); MutablePair<Integer, String> groupPair = (MutablePair<Integer, String>) group.getUserObject(); boolean allChildren = true; boolean noChildren = true; for (Enumeration<? extends MutableTreeTableNode> children = group.children(); children .hasMoreElements();) {//from w w w . ja v a 2 s . com MutableTreeTableNode child = children.nextElement(); MutablePair<Integer, ContextType> childPair = (MutablePair<Integer, ContextType>) child .getUserObject(); if (context.contains(childPair.getRight())) { childPair.setLeft(MirthTriStateCheckBox.CHECKED); noChildren = false; } else { childPair.setLeft(MirthTriStateCheckBox.UNCHECKED); allChildren = false; } } if (allChildren) { groupPair.setLeft(MirthTriStateCheckBox.CHECKED); } else if (noChildren) { groupPair.setLeft(MirthTriStateCheckBox.UNCHECKED); } else { groupPair.setLeft(MirthTriStateCheckBox.PARTIAL); } } templateContextTreeTable.expandAll(); }
From source file:bwem.Graph.java
public void createChokePoints(final List<StaticBuilding> staticBuildings, final List<Mineral> minerals, final List<MutablePair<MutablePair<AreaId, AreaId>, WalkPosition>> rawFrontier) { Index newIndex = new Index(0); final List<Neutral> blockingNeutrals = new ArrayList<>(); for (final StaticBuilding s : staticBuildings) { if (s.isBlocking()) { blockingNeutrals.add(s);/*from w w w .java 2 s .c o m*/ } } for (final Mineral m : minerals) { if (m.isBlocking()) { blockingNeutrals.add(m); } } //Note: pseudoChokePointsToCreate is only used for pre-allocating the GetChokePoints array size. // This number will highly likely be very small. There is no reason to set a minimum size. // int pseudoChokePointsToCreate = 0; // for (final Neutral blockingNeutral : blockingNeutrals) { // if (blockingNeutral.getNextStacked() == null) { // ++pseudoChokePointsToCreate; // } // } // 1) size the matrix initializeChokePointsMatrix(this.chokePointsMatrix, getAreaCount()); // 2) Dispatch the global raw frontier between all the relevant pairs of areas: final java.util.Map<MutablePair<AreaId, AreaId>, List<WalkPosition>> rawFrontierByAreaPair = createRawFrontierByAreaPairMap( rawFrontier); // 3) For each pair of areas (A, B): for (final java.util.Map.Entry<MutablePair<AreaId, AreaId>, List<WalkPosition>> entry : rawFrontierByAreaPair .entrySet()) { MutablePair<AreaId, AreaId> rawleft = entry.getKey(); final List<WalkPosition> rawFrontierAB = entry.getValue(); // Because our dispatching preserved order, // and because Map::m_RawFrontier was populated in descending order of the altitude (see Map::computeAreas), // we know that rawFrontierAB is also ordered the same way, but let's check it: { final List<Altitude> altitudes = new ArrayList<>(); for (final WalkPosition w : rawFrontierAB) { altitudes.add(getMap().getData().getMiniTile(w).getAltitude()); } // Check if the altitudes array is sorted in descending order. // bwem_assert(is_sorted(altitudes.rbegin(), altitudes.rend())); for (int i = 1; i < altitudes.size(); ++i) { final int prev = altitudes.get(i - 1).intValue(); final int curr = altitudes.get(i).intValue(); if (prev < curr) { throw new IllegalStateException(); } } } // 3.1) Use that information to efficiently cluster rawFrontierAB in one or several chokepoints. // Each cluster will be populated starting with the center of a chokepoint (max altitude) // and finishing with the ends (min altitude). final int clusterMinDist = (int) Math.sqrt(BwemExt.lake_max_miniTiles); final List<List<WalkPosition>> clusters = new ArrayList<>(); for (final WalkPosition w : rawFrontierAB) { boolean added = false; for (final List<WalkPosition> cluster : clusters) { final int distToFront = BwemExt.queenWiseDist(cluster.get(0), w); final int distToBack = BwemExt.queenWiseDist(cluster.get(cluster.size() - 1), w); if (Math.min(distToFront, distToBack) <= clusterMinDist) { if (distToFront < distToBack) { cluster.add(0, w); } else { cluster.add(w); } added = true; break; } } if (!added) { final List<WalkPosition> list = new ArrayList<>(); list.add(w); clusters.add(list); } } // 3.2) Create one Chokepoint for each cluster: final AreaId a = rawleft.getLeft(); final AreaId b = rawleft.getRight(); // getChokePoints(a, b).reserve(clusters.size() + pseudoChokePointsToCreate); for (final List<WalkPosition> cluster : clusters) { getChokePoints(a, b).add(new ChokePointImpl(this, newIndex, getArea(a), getArea(b), cluster)); newIndex = newIndex.add(1); } } // 4) Create one Chokepoint for each pair of blocked areas, for each blocking Neutral: for (final Neutral blockingNeutral : blockingNeutrals) { if (blockingNeutral.getNextStacked() == null) { // in the case where several neutrals are stacked, we only consider the top final List<Area> blockedAreas = blockingNeutral.getBlockedAreas(); for (final Area blockedAreaA : blockedAreas) for (final Area blockedAreaB : blockedAreas) { if (blockedAreaB.equals(blockedAreaA)) { break; // breaks symmetry } final WalkPosition center = getMap().breadthFirstSearch( blockingNeutral.getCenter().toWalkPosition(), // findCond args -> { Object ttile = args[0]; if (!(ttile instanceof MiniTile)) { throw new IllegalArgumentException(); } MiniTile miniTile = (MiniTile) ttile; return miniTile.isWalkable(); }, // visitCond args -> true); final List<WalkPosition> list = new ArrayList<>(); list.add(center); getChokePoints(blockedAreaA, blockedAreaB).add(new ChokePointImpl(this, newIndex, blockedAreaA, blockedAreaB, list, blockingNeutral)); newIndex = newIndex.add(1); } } } // 5) Set the references to the freshly created Chokepoints: for (int loopA = 1; loopA <= getAreaCount(); ++loopA) for (int loopB = 1; loopB < loopA; ++loopB) { final AreaId a = new AreaId(loopA); final AreaId b = new AreaId(loopB); if (!getChokePoints(a, b).isEmpty()) { ((AreaInitializer) getArea(a)).addChokePoints(getArea(b), getChokePoints(a, b)); ((AreaInitializer) getArea(b)).addChokePoints(getArea(a), getChokePoints(a, b)); this.chokePoints.addAll(getChokePoints(a, b)); } } }
From source file:nl.b3p.viewer.config.services.ArcGISService.java
private void updateLayers(final ArcGISService update, final ArcGISFeatureSource linkedFS, final UpdateResult result) { /* This is a lot simpler than WMS, because layers always have an id * (name in WMS and our Layer object) *///from ww w . j a v a2s . c o m Map<String, Layer> updatedLayersById = new HashMap(); SimpleFeatureType ft; for (Layer updateLayer : update.layersById.values()) { MutablePair<Layer, UpdateResult.Status> layerStatus = result.getLayerStatus() .get(updateLayer.getName()); Layer updatedLayer = null; if (layerStatus == null) { // New layer ft = updateLayer.getFeatureType(); if (updateLayer.getFeatureType() != null) { if (linkedFS != null) { updateLayer.setFeatureType( linkedFS.addOrUpdateFeatureType(updateLayer.getName(), ft, new MutableBoolean())); } else { // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); } } result.getLayerStatus().put(updateLayer.getName(), new MutablePair(updateLayer, UpdateResult.Status.NEW)); updatedLayer = updateLayer; } else { assert (layerStatus.getRight() == UpdateResult.Status.MISSING); Layer old = layerStatus.getLeft(); old.setParent(null); old.update(updateLayer, additionalUpdatableDetails); layerStatus.setRight(UpdateResult.Status.UNMODIFIED); // Do not overwrite manually set feature source if (old.getFeatureType() == null || old.getFeatureType().getFeatureSource().getLinkedService() == this) { if (updateLayer.getFeatureType() == null) { // If was set before the old feature type will be removed // later when all orphan MISSING layers are removed if (old.getFeatureType() != null) { layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(null); } else { if (linkedFS != null) { MutableBoolean updated = new MutableBoolean(false); ft = linkedFS.addOrUpdateFeatureType(updateLayer.getName(), updateLayer.getFeatureType(), updated); if (old.getFeatureType() == null || updated.isTrue()) { layerStatus.setRight(UpdateResult.Status.UPDATED); } } else { ft = updateLayer.getFeatureType(); // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(ft); } } updatedLayer = old; } // will be filled in setLayerTree() updatedLayer.getChildren().clear(); updatedLayer.setParent(null); updatedLayer.setService(this); updatedLayersById.put(updateLayer.getName(), updatedLayer); } setLayerTree(getTopLayer(), updatedLayersById, update.childrenByLayerId); }
From source file:nl.b3p.viewer.config.services.ArcIMSService.java
private void updateLayers(final ArcIMSService update, final ArcXMLFeatureSource linkedFS, final UpdateResult result) { /* This is a lot simpler than WMS, because layers always have an id * (name in WMS and our Layer object) * // ww w. j a v a2 s .co m * And even simpler than ArcGIS because layers have no tree structure. */ getTopLayer().getChildren().clear(); SimpleFeatureType ft; for (Layer updateLayer : update.getTopLayer().getChildren()) { MutablePair<Layer, UpdateResult.Status> layerStatus = result.getLayerStatus() .get(updateLayer.getName()); Layer updatedLayer; if (layerStatus == null) { // New layer ft = updateLayer.getFeatureType(); if (updateLayer.getFeatureType() != null) { if (linkedFS != null) { linkedFS.addOrUpdateFeatureType(updateLayer.getName(), ft, new MutableBoolean()); } else { // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); } } result.getLayerStatus().put(updateLayer.getName(), new MutablePair(updateLayer, UpdateResult.Status.NEW)); updatedLayer = updateLayer; } else { assert (layerStatus.getRight() == UpdateResult.Status.MISSING); Layer old = layerStatus.getLeft(); old.update(updateLayer); layerStatus.setRight(UpdateResult.Status.UNMODIFIED); // Do not overwrite manually set feature source if (old.getFeatureType() == null || old.getFeatureType().getFeatureSource().getLinkedService() == this) { if (updateLayer.getFeatureType() == null) { // If was set before the old feature type will be removed // later when all orphan MISSING layers are removed if (old.getFeatureType() != null) { layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(null); } else { if (linkedFS != null) { MutableBoolean updated = new MutableBoolean(false); ft = linkedFS.addOrUpdateFeatureType(updateLayer.getName(), updateLayer.getFeatureType(), updated); if (old.getFeatureType() == null || updated.isTrue()) { layerStatus.setRight(UpdateResult.Status.UPDATED); } } else { ft = updateLayer.getFeatureType(); // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(ft); } } updatedLayer = old; } assert updatedLayer.getChildren().isEmpty(); updatedLayer.setService(this); updatedLayer.setParent(getTopLayer()); getTopLayer().getChildren().add(updatedLayer); } }
From source file:nl.b3p.viewer.config.services.WMSService.java
/** * Internal update method for layers. Update result.layerStatus() which * currently has all layers set to MISSING. New layers are set to NEW, with * a clone plucked from the updated service tree. Existing layers are set to * UNMODIFIED or UPDATED (Layer entities modified) * <p>/* w w w . jav a2 s . c o m*/ * Duplicate layers are not updated (will be removed later). * <p> * Grouping layers (no name) are ignored. */ private void updateLayers(final WMSService update, final Map<String, WFSFeatureSource> linkedFSesByURL, final Set<SimpleFeatureType> updatedFeatureTypes, final UpdateResult result) { final WMSService updatingWMSService = this; update.getTopLayer().accept(new Layer.Visitor() { @Override public boolean visit(Layer l) { if (l.getName() == null) { // Grouping layer only return true; } MutablePair<Layer, UpdateResult.Status> layerStatus = result.getLayerStatus().get(l.getName()); if (layerStatus == null) { // New layer, pluck a copy from the tree that will be made // persistent. // Plucking a clone is necessary because the children // and parent will be set on this instance later on and we // need the original children to traverse the updated service // tree while doing that l = l.pluckCopy(); result.getLayerStatus().put(l.getName(), new MutablePair(l, UpdateResult.Status.NEW)); if (l.getFeatureType() != null) { // We may already have an updated previously persistent // FeatureType / FeatureSource // New FeatureSources were added to the linkedFSesByURL // map in updateWFS() WFSFeatureSource fs = linkedFSesByURL.get(l.getFeatureType().getFeatureSource().getUrl()); l.setFeatureType(fs.getFeatureType(l.getFeatureType().getTypeName())); } } else { if (layerStatus.getRight() != UpdateResult.Status.MISSING) { // Already processed, ignore duplicate layer return true; } Layer old = layerStatus.getLeft(); // Pluck from old tree old.setParent(null); old.getChildren().clear(); // The layer properties are ignored for update status, only // its featuretype determines changed boolean old.update(l); layerStatus.setRight(UpdateResult.Status.UNMODIFIED); // Only update feature type if not manually set to feature // type of feature source not automatically created by loading // this service (has linkedService set to updatingWMSService) if (old.getFeatureType() == null || old.getFeatureType().getFeatureSource().getLinkedService() == updatingWMSService) { // FeatureType instance may be the same (already updated in // updateWFS(), or a new FeatureType (put in linkedFSesByURL // map by the same method) if (l.getFeatureType() != null) { WFSFeatureSource fs = linkedFSesByURL .get(l.getFeatureType().getFeatureSource().getUrl()); boolean wasNull = old.getFeatureType() == null; old.setFeatureType(fs.getFeatureType(l.getFeatureType().getTypeName())); if (wasNull || updatedFeatureTypes.contains(old.getFeatureType())) { layerStatus.setRight(UpdateResult.Status.UPDATED); } } else { if (old.getFeatureType() != null) { layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(null); } } } return true; } }); }
From source file:org.apache.apex.malhar.lib.db.jdbc.AbstractJdbcPollInputOperator.java
@Override public void beginWindow(long windowId) { currentWindowId = windowId;/* w ww .j a v a 2 s . co m*/ if (currentWindowId <= windowManager.getLargestCompletedWindow()) { try { replay(currentWindowId); return; } catch (SQLException e) { throw new RuntimeException("Replay failed", e); } } currentWindowRecoveryState = WindowData.of(currentWindowRecoveryState.key, lastEmittedRow, 0); if (isPollerPartition) { MutablePair<Object, Integer> keyOffset = fetchedKeyAndOffset.get(); if (keyOffset != null && keyOffset.getRight() < lastEmittedRow) { if (!adjustKeyAndOffset.get()) { // rebase offset lastEmittedRow -= keyOffset.getRight(); currentWindowRecoveryState.lowerBound = lastEmittedRow; currentWindowRecoveryState.key = keyOffset.getLeft(); adjustKeyAndOffset.set(true); } } } }
From source file:org.apache.apex.malhar.lib.io.block.PartFileWriter.java
@Override protected String getFileName(AbstractBlockReader.ReaderRecord<Slice> tuple) { MutablePair<Integer, String> blockId = blockInfo.get(tuple.getBlockId()); return blockId.getRight() + PARTSUFFIX + blockId.getLeft(); }
From source file:org.apache.apex.malhar.lib.io.block.PartFileWriter.java
@Override public void finalizeFile(String fileName) throws IOException { MutablePair<Integer, String> blockId = blockInfo.get(Long.parseLong(fileName)); super.finalizeFile(blockId.getRight() + PARTSUFFIX + blockId.getLeft()); }