Example usage for org.apache.commons.lang3.tuple MutablePair MutablePair

List of usage examples for org.apache.commons.lang3.tuple MutablePair MutablePair

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple MutablePair MutablePair.

Prototype

public MutablePair(final L left, final R right) 

Source Link

Document

Create a new pair instance.

Usage

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
 *//* w  w w . j a  v a 2s  .c  o 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:com.datatorrent.lib.db.jdbc.AbstractJdbcPollInputOperator.java

@Override
public void endWindow() {
    try {/*from www.  j  ava2  s  .  c om*/
        if (currentWindowId > windowManager.getLargestCompletedWindow()) {
            currentWindowRecoveryState = new MutablePair<>(lowerBound, lastEmittedRow);
            windowManager.save(currentWindowRecoveryState, currentWindowId);
        }
    } catch (IOException e) {
        throw new RuntimeException("saving recovery", e);
    }
    if (threadException != null) {
        store.disconnect();
        DTThrowable.rethrow(threadException.get());
    }
}

From source file:AIR.Common.xml.XmlReader.java

private boolean traverseNextSibling() throws IOException {
    /*//from www  . jav  a  2  s . 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:bwem.map.MapInitializerImpl.java

/**
 * 1) Fill in and sort DeltasByAscendingAltitude
 *//*  w  ww. j  av a2  s .c  o  m*/
@Override
public List<MutablePair<WalkPosition, Altitude>> getSortedDeltasByAscendingAltitude(final int mapWalkTileWidth,
        final int mapWalkTileHeight, int altitudeScale) {
    final int range = Math.max(mapWalkTileWidth, mapWalkTileHeight) / 2 + 3; // should suffice for maps with no Sea.

    final List<MutablePair<WalkPosition, Altitude>> deltasByAscendingAltitude = new ArrayList<>();

    for (int dy = 0; dy <= range; ++dy) {
        for (int dx = dy; dx <= range; ++dx) { // Only consider 1/8 of possible deltas. Other ones obtained by symmetry.
            if (dx != 0 || dy != 0) {
                deltasByAscendingAltitude.add(new MutablePair<>(new WalkPosition(dx, dy),
                        new Altitude((int) Math.round(Utils.norm(dx, dy) * altitudeScale))));
            }
        }
    }

    deltasByAscendingAltitude.sort(new PairGenericAltitudeComparator<>());

    return deltasByAscendingAltitude;
}

From source file:bwem.map.MapInitializerImpl.java

/**
 * 2) Fill in ActiveSeaSideList, which basically contains all the seaside miniTiles (from which altitudes are to be computed)
 *    It also includes extra border-miniTiles which are considered as seaside miniTiles too.
 *//* w  ww . ja  v a2s .c o  m*/
@Override
public List<MutablePair<WalkPosition, Altitude>> getActiveSeaSideList(final TerrainData terrainData) {
    final List<MutablePair<WalkPosition, Altitude>> activeSeaSideList = new ArrayList<>();

    for (int y = -1; y <= terrainData.getMapData().getWalkSize().getY(); ++y) {
        for (int x = -1; x <= terrainData.getMapData().getWalkSize().getX(); ++x) {
            final WalkPosition walkPosition = new WalkPosition(x, y);
            if (!terrainData.getMapData().isValid(walkPosition)
                    || terrainData.isSeaWithNonSeaNeighbors(walkPosition)) {
                activeSeaSideList.add(new MutablePair<>(walkPosition, Altitude.ZERO));
            }
        }
    }

    return activeSeaSideList;
}

From source file:AIR.Common.xml.XmlReader.java

private boolean traverseImmediateChild(boolean firstOnly) throws IOException {
    /*//from  ww w .j  a  va2s  . co  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:AIR.Common.xml.XmlReader.java

private void buildDocument(Closeable file) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    if (file instanceof InputStream)
        _doc = builder.build((InputStream) file);
    else if (file instanceof Reader)
        _doc = builder.build((Reader) file);
    _stack.push(new MutablePair<Content, Integer>(_doc.getRootElement(), -1));
    _rootNameSpace = _doc.getRootElement().getNamespace();
    _file = file;// w  w w . j ava 2s  .c om
}

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 ww w.  j a  v  a2  s  . 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.ottogroup.bi.streaming.operator.json.aggregate.WindowedJsonContentAggregatorTest.java

/**
 * Test case for {@link WindowedJsonContentAggregator#aggregateValue(java.io.Serializable, java.io.Serializable, com.ottogroup.bi.streaming.operator.json.JsonContentType, ContentAggregator)}
 * being provided valid values to all parameters 
 *///from   www. java  2 s.  c o  m
@Test
public void testAggregateValue_withValidValuesAndAVG() throws Exception {

    Pair<Integer, Integer> avgValues = new MutablePair<>(Integer.valueOf(10), Integer.valueOf(3));

    Assert.assertEquals(new MutablePair<>(Integer.valueOf(12), Integer.valueOf(4)),
            new WindowedJsonContentAggregator("test", new AggregatorConfiguration()).aggregateValue(
                    Integer.valueOf(2), avgValues, JsonContentType.INTEGER, ContentAggregator.AVG));
}

From source file:com.mirth.connect.server.migration.Migrate3_3_0.java

@Override
public Map<String, Object> getConfigurationPropertiesToAdd() {
    Map<String, Object> propertiesToAdd = new LinkedHashMap<String, Object>();

    propertiesToAdd.put("server.startupdeploy", new MutablePair<Object, String>(true,
            "Determines whether or not channels are deployed on server startup."));

    return propertiesToAdd;
}