List of usage examples for org.apache.commons.lang3.tuple MutablePair getLeft
@Override
public L getLeft()
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) *//*w w w .ja v a2 s. co 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) * /*from w w w.j av a 2 s.com*/ * 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>/*from w w w . ja v a 2 s. com*/ * 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;/* www . ja v a 2 s . c o 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()); }
From source file:org.apache.apex.malhar.lib.window.accumulation.Average.java
@Override public MutablePair<Double, Long> accumulate(MutablePair<Double, Long> accu, Double input) { accu.setLeft(accu.getLeft() * ((double) accu.getRight() / (accu.getRight() + 1)) + input / (accu.getRight() + 1)); accu.setRight(accu.getRight() + 1);//from w w w . j a v a 2s . c o m return accu; }
From source file:org.apache.apex.malhar.lib.window.accumulation.Average.java
@Override public MutablePair<Double, Long> merge(MutablePair<Double, Long> accu1, MutablePair<Double, Long> accu2) { accu1.setLeft(accu1.getLeft() * ((double) accu1.getRight() / accu1.getRight() + accu2.getRight()) + accu2.getLeft() * ((double) accu2.getRight() / accu1.getRight() + accu2.getRight())); accu1.setRight(accu1.getRight() + accu2.getRight()); return accu1; }
From source file:org.apache.apex.malhar.lib.window.accumulation.Average.java
@Override public Double getOutput(MutablePair<Double, Long> accumulatedValue) { return accumulatedValue.getLeft(); }
From source file:org.apache.apex.malhar.lib.window.accumulation.AverageTest.java
@Test public void AverageTest() { Average ave = new Average(); MutablePair<Double, Long> accu = ave.defaultAccumulatedValue(); for (int i = 1; i <= 10; i++) { accu = ave.accumulate(accu, (double) i); }/*from w w w. ja v a 2s . c om*/ Assert.assertTrue(5.5 == accu.getLeft()); }