List of usage examples for org.apache.commons.lang3.tuple MutablePair getRight
@Override
public R getRight()
From source file:com.ottogroup.bi.streaming.operator.json.aggregate.functions.IntegerContentAggregateFunctionTest.java
/** * Test case for {@link IntegerContentAggregateFunction#average(org.apache.commons.lang3.tuple.MutablePair, Integer)} * being provided null as input to new value parameter *///from w w w . ja v a 2s . c o m @Test public void testAverage_withNewValueNullInput() throws Exception { MutablePair<Integer, Integer> result = new IntegerContentAggregateFunction() .average(new MutablePair<Integer, Integer>(Integer.valueOf(125), Integer.valueOf(3)), null); Assert.assertEquals(Integer.valueOf(125), result.getLeft()); Assert.assertEquals(Integer.valueOf(3), result.getRight()); }
From source file:hu.mta.sztaki.lpds.cloud.simulator.DeferredEvent.java
/** * If the call for eventAction() is no longer necessary at the previously * specified time then the user can cancel this call to arrive with this * function./*from w w w . j a v a 2 s.c o m*/ * * Calling this function will have no effect on events that are already past * due. */ public void cancel() { if (received) return; if (!cancelled) { cancelled = true; MutablePair<Integer, DeferredEvent[]> simultaneousReceiverPairs = toSweep.get(eventArrival); if (simultaneousReceiverPairs != null) { int len = simultaneousReceiverPairs.getLeft(); DeferredEvent[] simultaneousReceivers = simultaneousReceiverPairs.getRight(); // For performance reasons this removal operation does not keep // the order of the array entries for (int i = 0; i < len; i++) { if (simultaneousReceivers[i] == this) { len--; if (len > i) { simultaneousReceivers[i] = simultaneousReceivers[len]; } simultaneousReceivers[len] = null; break; } } if (len == 0) { toSweep.remove(eventArrival); dispatcherSingleton.updateDispatcher(); } else { simultaneousReceiverPairs.setLeft(len); } } } }
From source file:com.ottogroup.bi.streaming.operator.json.aggregate.functions.DoubleContentAggregateFunctionTest.java
/** * Test case for {@link DoubleContentAggregateFunction#average(org.apache.commons.lang3.tuple.MutablePair, Double)} * being provided valid input/*from www . j a v a 2s .co m*/ */ @Test public void testAverage_withValidInput() throws Exception { MutablePair<Double, Integer> result = new DoubleContentAggregateFunction().average( new MutablePair<Double, Integer>(Double.valueOf(1.34), Integer.valueOf(4)), Double.valueOf(8.22)); Assert.assertEquals(Double.valueOf(9.56), result.getLeft()); Assert.assertEquals(Integer.valueOf(5), result.getRight()); }
From source file:com.ottogroup.bi.streaming.operator.json.aggregate.functions.IntegerContentAggregateFunctionTest.java
/** * Test case for {@link IntegerContentAggregateFunction#average(org.apache.commons.lang3.tuple.MutablePair, Integer)} * being provided valid input to both parameters *///from w ww. j a v a 2 s . co m @Test public void testAverage_withValidInput() throws Exception { MutablePair<Integer, Integer> result = new IntegerContentAggregateFunction().average( new MutablePair<Integer, Integer>(Integer.valueOf(125), Integer.valueOf(3)), Integer.valueOf(43)); Assert.assertEquals(Integer.valueOf(168), result.getLeft()); Assert.assertEquals(Integer.valueOf(4), result.getRight()); }
From source file:bwem.example.MapPrinterExample.java
/** * Draws the specified map data to the internal map printer and generates an image file. * * @param theMap the specified BWEM map data to print * @param filename the specified file without a file extension *///from w w w .j a v a2 s . c o m public void printMap(Map theMap, String filename) { java.util.Map<Integer, Color> mapZoneColor = new HashMap<>(); for (int y = 0; y < theMap.getData().getMapData().getWalkSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getWalkSize().getX(); ++x) { WalkPosition p = new WalkPosition(x, y); MiniTile miniTile = theMap.getData().getMiniTile(p, CheckMode.NO_CHECK); Color col; if (miniTile.isSea()) { if (mapPrinter.showSeaSide && theMap.getData().isSeaWithNonSeaNeighbors(p)) col = MapPrinter.CustomColor.SEA_SIDE.color(); else col = MapPrinter.CustomColor.SEA.color(); } else { if (mapPrinter.showLakes && miniTile.isLake()) { col = MapPrinter.CustomColor.LAKE.color(); } else { if (mapPrinter.showAltitude) { int c = 255 - ((miniTile.getAltitude().intValue() * 255) / theMap.getHighestAltitude().intValue()); col = new Color(c, c, c); } else { col = MapPrinter.CustomColor.TERRAIN.color(); } if (mapPrinter.showAreas || mapPrinter.showContinents) if (miniTile.getAreaId().intValue() > 0) { Area area = theMap.getArea(miniTile.getAreaId()); Color zoneColor = getZoneColor(area, mapZoneColor); int red = zoneColor.getRed() * col.getRed() / 255; int green = zoneColor.getGreen() * col.getGreen() / 255; col = new Color(red, green, 0); } else { col = MapPrinter.CustomColor.TINY_AREA.color(); } } } mapPrinter.point(p, col); } if (mapPrinter.showData) for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) { int data = ((TileImpl) theMap.getData().getTile(new TilePosition(x, y))).getInternalData(); int c = (((data / 1) * 1) % 256); Color col = new Color(c, c, c); WalkPosition origin = (new TilePosition(x, y)).toWalkPosition(); mapPrinter.rectangle(origin, origin.add(new WalkPosition(3, 3)), col, MapPrinter.fill_t.fill); } if (mapPrinter.showUnbuildable) for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) if (!theMap.getData().getTile(new TilePosition(x, y)).isBuildable()) { WalkPosition origin = (new TilePosition(x, y)).toWalkPosition(); mapPrinter.rectangle(origin.add(new WalkPosition(1, 1)), origin.add(new WalkPosition(2, 2)), MapPrinter.CustomColor.UNBUILDABLE.color()); } if (mapPrinter.showGroundHeight) for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) { Tile.GroundHeight groundHeight = theMap.getData().getTile(new TilePosition(x, y)) .getGroundHeight(); if (groundHeight.intValue() >= Tile.GroundHeight.HIGH_GROUND.intValue()) for (int dy = 0; dy < 4; ++dy) for (int dx = 0; dx < 4; ++dx) { WalkPosition p = (new TilePosition(x, y).toWalkPosition()) .add(new WalkPosition(dx, dy)); if (theMap.getData().getMiniTile(p, CheckMode.NO_CHECK).isWalkable()) // groundHeight is usefull only for walkable miniTiles if (((dx + dy) & (groundHeight == Tile.GroundHeight.HIGH_GROUND ? 1 : 3)) != 0) mapPrinter.point(p, MapPrinter.CustomColor.HIGHER_GROUND.color()); } } if (mapPrinter.showAssignedResources) for (Area area : theMap.getAreas()) for (Base base : area.getBases()) { for (Mineral m : base.getMinerals()) mapPrinter.line(base.getCenter().toWalkPosition(), m.getCenter().toWalkPosition(), MapPrinter.CustomColor.BASES.color()); for (Geyser g : base.getGeysers()) mapPrinter.line(base.getCenter().toWalkPosition(), g.getCenter().toWalkPosition(), MapPrinter.CustomColor.BASES.color()); } if (mapPrinter.showGeysers) for (Geyser g : theMap.getNeutralData().getGeysers()) printNeutral(theMap, g, MapPrinter.CustomColor.GEYSERS.color()); if (mapPrinter.showMinerals) for (Mineral m : theMap.getNeutralData().getMinerals()) printNeutral(theMap, m, MapPrinter.CustomColor.MINERALS.color()); if (mapPrinter.showStaticBuildings) for (StaticBuilding s : theMap.getNeutralData().getStaticBuildings()) printNeutral(theMap, s, MapPrinter.CustomColor.STATIC_BUILDINGS.color()); if (mapPrinter.showStartingLocations) for (TilePosition t : theMap.getData().getMapData().getStartingLocations()) { WalkPosition origin = t.toWalkPosition(); WalkPosition size = UnitType.Terran_Command_Center.tileSize().toWalkPosition(); // same size for other races mapPrinter.rectangle(origin, origin.add(size).subtract(new WalkPosition(1, 1)), MapPrinter.CustomColor.STARTING_LOCATIONS.color(), MapPrinter.fill_t.fill); } if (mapPrinter.showBases) for (Area area : theMap.getAreas()) { for (Base base : area.getBases()) { WalkPosition origin = base.getLocation().toWalkPosition(); WalkPosition size = UnitType.Terran_Command_Center.tileSize().toWalkPosition(); // same size for other races MapPrinter.dashed_t dashMode = base.getBlockingMinerals().isEmpty() ? MapPrinter.dashed_t.not_dashed : MapPrinter.dashed_t.dashed; mapPrinter.rectangle(origin, origin.add(size).subtract(new WalkPosition(1, 1)), MapPrinter.CustomColor.BASES.color(), MapPrinter.fill_t.do_not_fill, dashMode); } } if (mapPrinter.showChokePoints) { for (MutablePair<MutablePair<AreaId, AreaId>, WalkPosition> f : theMap.getRawFrontier()) mapPrinter.point(f.getRight(), mapPrinter.showAreas ? MapPrinter.CustomColor.CHOKE_POINTS_SHOW_AREAS.color() : MapPrinter.CustomColor.CHOKE_POINTS_SHOW_CONTINENTS.color()); for (Area area : theMap.getAreas()) for (ChokePoint cp : area.getChokePoints()) { ChokePoint.Node[] nodes = { ChokePoint.Node.END1, ChokePoint.Node.END2 }; for (ChokePoint.Node n : nodes) mapPrinter.square(cp.getNodePosition(n), 1, new Color(255, 0, 255), MapPrinter.fill_t.fill); mapPrinter.square(cp.getCenter(), 1, new Color(0, 0, 255), MapPrinter.fill_t.fill); } } //TODO: Handle exception. try { mapPrinter.writeImageToFile(Paths.get(filename + ".png"), "png"); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:AIR.Common.xml.XmlReader.java
private boolean traverseNextSibling() throws IOException { /*//from w ww.ja va 2s .c o m * if (_file.available () == 0) { return false; } */ if (_stack.size() == 0) return false; MutablePair<Content, Integer> currentTop = _stack.pop(); if (_stack.size() != 0) { MutablePair<Content, Integer> topElement = _stack.peek(); // We already went into topElement's children and so there is no // need to check if it of type element. Element topElementNode = (Element) topElement.getLeft(); int nextChild = topElement.getRight() + 1; if (topElementNode.getChildren().size() > nextChild) { topElement.setRight(nextChild); Element nextTraversalNode = topElementNode.getChildren().get(nextChild); _stack.push(new MutablePair<Content, Integer>(nextTraversalNode, -1)); return true; } } // else put the previous top back on the top. _stack.push(currentTop); return false; }
From source file:AIR.Common.xml.XmlReader.java
private boolean traverseImmediateChild(boolean firstOnly) throws IOException { /*/*from w ww .j a v a 2s .c o m*/ * if (_file.available () == 0) { return false; } */ if (_stack.size() == 0) return false; MutablePair<Content, Integer> topElement = _stack.peek(); Content node = topElement.getLeft(); if (node.getCType() == CType.Element) { Element topElementNode = (Element) node; int nextChild = 0; if (!firstOnly) nextChild = topElement.getRight() + 1; // if we have a next child then we will go to that. if (topElementNode.getChildren().size() > nextChild) { topElement.setRight(nextChild); Element nextTraversalNode = topElementNode.getChildren().get(nextChild); _stack.push(new MutablePair<Content, Integer>(nextTraversalNode, -1)); return true; } } return false; }
From source file:com.ottogroup.bi.streaming.operator.json.aggregate.functions.IntegerContentAggregateFunction.java
/** * @see com.ottogroup.bi.streaming.operator.json.aggregate.functions.JsonContentAggregateFunction#average(org.apache.commons.lang3.tuple.Pair, java.io.Serializable) *//*w ww . j av a 2s.c o m*/ public MutablePair<Integer, Integer> average(MutablePair<Integer, Integer> sumAndCount, Integer value) throws Exception { if (sumAndCount == null && value == null) return new MutablePair<>(Integer.valueOf(0), Integer.valueOf(0)); if (sumAndCount == null && value != null) return new MutablePair<>(Integer.valueOf(value.intValue()), Integer.valueOf(1)); if (sumAndCount != null && value == null) return sumAndCount; sumAndCount.setLeft(sumAndCount.getLeft().intValue() + value.intValue()); sumAndCount.setRight(sumAndCount.getRight().intValue() + 1); return sumAndCount; }
From source file:com.ottogroup.bi.streaming.operator.json.aggregate.functions.DoubleContentAggregateFunction.java
/** * @see com.ottogroup.bi.streaming.operator.json.aggregate.functions.JsonContentAggregateFunction#average(org.apache.commons.lang3.tuple.MutablePair, java.io.Serializable) */// www .ja v a 2 s. c om public MutablePair<Double, Integer> average(MutablePair<Double, Integer> sumAndCount, Double value) throws Exception { if (sumAndCount == null && value == null) return new MutablePair<>(Double.valueOf(0), Integer.valueOf(0)); if (sumAndCount == null && value != null) return new MutablePair<>(Double.valueOf(value.doubleValue()), Integer.valueOf(1)); if (sumAndCount != null && value == null) return sumAndCount; sumAndCount.setLeft(sumAndCount.getLeft().doubleValue() + value.doubleValue()); sumAndCount.setRight(sumAndCount.getRight().intValue() + 1); return sumAndCount; }
From source file:hu.mta.sztaki.lpds.cloud.simulator.DeferredEvent.java
/** * Allows constructing objects that will receive an eventAction() call from * Timed after delay ticks./* w w w . j a v a2s .c o m*/ * * @param delay * the number of ticks that should pass before this deferred * event object's eventAction() will be called. */ public DeferredEvent(final long delay) { if (delay <= 0) { eventArrival = Timed.getFireCount(); eventAction(); received = true; return; } eventArrival = Timed.calcTimeJump(delay); MutablePair<Integer, DeferredEvent[]> simultaneousReceiverPairs = toSweep.get(eventArrival); if (simultaneousReceiverPairs == null) { simultaneousReceiverPairs = new MutablePair<Integer, DeferredEvent[]>(0, new DeferredEvent[5]); toSweep.put(eventArrival, simultaneousReceiverPairs); } int len = simultaneousReceiverPairs.getLeft(); DeferredEvent[] simultaneousReceivers = simultaneousReceiverPairs.getRight(); if (len == simultaneousReceivers.length) { DeferredEvent[] temp = new DeferredEvent[simultaneousReceivers.length * 2]; System.arraycopy(simultaneousReceivers, 0, temp, 0, len); simultaneousReceivers = temp; simultaneousReceiverPairs.setRight(temp); } simultaneousReceivers[len++] = this; simultaneousReceiverPairs.setLeft(len); if (!dispatcherSingleton.isSubscribed() || dispatcherSingleton.getNextEvent() > eventArrival) { dispatcherSingleton.updateDispatcher(); } }