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

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

Introduction

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

Prototype

public void setRight(final R right) 

Source Link

Document

Sets the right element of the pair.

Usage

From source file:be.shad.tsqb.test.OrderingTest.java

@Test
@SuppressWarnings("unchecked")
public void testOrderByAlias() {
    Building building = query.from(Building.class);

    MutablePair<Long, Date> select = query.select(MutablePair.class);
    select.setLeft(building.getId());/* www  .j  a v  a 2  s.  c  o  m*/
    select.setRight(building.getConstructionDate());

    query.orderBy().by(new OrderByProjection(query, "right", true));

    validate(
            "select hobj1.id as left, hobj1.constructionDate as right from Building hobj1 order by hobj1.constructionDate desc");
}

From source file:be.shad.tsqb.test.OrderingTest.java

@Test
@SuppressWarnings("unchecked")
public void testOrderByAliasWithSubQuery() {
    Building building = query.from(Building.class);
    TypeSafeSubQuery<Long> maxId = query.subquery(Long.class);
    Building buildingMaxId = maxId.from(Building.class);
    maxId.select(maxId.hqlFunction().max(buildingMaxId.getId()));

    MutablePair<Long, Date> select = query.select(MutablePair.class);
    select.setLeft(maxId.select());/*www . ja  v  a 2  s .co m*/
    select.setRight(building.getConstructionDate());

    query.orderBy().by(new OrderByProjection(query, "left", true));

    validate(
            "select (select max(hobj2.id) from Building hobj2) as left, hobj1.constructionDate as right from Building hobj1 order by 1 desc");
}

From source file:hu.ppke.itk.nlpg.purepos.model.internal.HashSuffixTree.java

protected void increment(String suffix, T tag, int count) {
    if (representation.containsKey(suffix)) {
        MutablePair<HashMap<T, Integer>, Integer> value = representation.get(suffix);
        HashMap<T, Integer> tagCounts = value.getLeft();
        if (tagCounts.containsKey(tag)) {
            tagCounts.put(tag, tagCounts.get(tag) + count);
        } else {//from ww w . j ava  2s.c  o m
            tagCounts.put(tag, count);
        }
        value.setRight(value.getRight() + count);
    } else {
        HashMap<T, Integer> tagCounts = new HashMap<T, Integer>();
        tagCounts.put(tag, count);
        MutablePair<HashMap<T, Integer>, Integer> value = new MutablePair<HashMap<T, Integer>, Integer>(
                tagCounts, count);
        representation.put(suffix, value);
    }
}

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// w w  w. ja v a  2 s.c  o  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.ChokePointImpl.java

public ChokePointImpl(final Graph graph, final Index index, final Area area1, final Area area2,
        final List<WalkPosition> geometry, final Neutral blockingNeutral) {

    //        bwem_assert(!geometry.empty());
    if (geometry.isEmpty()) {
        throw new IllegalArgumentException();
    }/*  w  w  w  . ja va2s  .  c  o  m*/

    this.graph = graph;
    this.index = index;
    this.areas = new Pair<>(area1, area2);
    this.geometry = geometry;

    // Ensures that in the case where several neutrals are stacked, blockingNeutral points to the bottom one:
    this.blockingNeutral = blockingNeutral != null
            ? getMap().getData().getTile(blockingNeutral.getTopLeft()).getNeutral()
            : blockingNeutral;

    this.isBlocked = blockingNeutral != null;
    this.isPseudo = this.isBlocked;

    this.nodes = new WalkPosition[Node.NODE_COUNT.ordinal()];
    this.nodes[Node.END1.ordinal()] = geometry.get(0);
    this.nodes[Node.END2.ordinal()] = geometry.get(geometry.size() - 1);

    this.nodesInArea = new ArrayList<>(Node.NODE_COUNT.ordinal());
    for (int i = 0; i < Node.NODE_COUNT.ordinal(); ++i) {
        this.nodesInArea.add(new MutablePair<>(new WalkPosition(0, 0), new WalkPosition(0, 0)));
    }

    int i = geometry.size() / 2;
    while ((i > 0) && (getMap().getData().getMiniTile(geometry.get(i - 1)).getAltitude().intValue() > getMap()
            .getData().getMiniTile(geometry.get(i)).getAltitude().intValue())) {
        --i;
    }
    while ((i < geometry.size() - 1) && (getMap().getData().getMiniTile(geometry.get(i + 1)).getAltitude()
            .intValue() > getMap().getData().getMiniTile(geometry.get(i)).getAltitude().intValue())) {
        ++i;
    }
    this.nodes[Node.MIDDLE.ordinal()] = geometry.get(i);

    for (int n = 0; n < Node.NODE_COUNT.ordinal(); ++n) {
        for (final Area area : new Area[] { area1, area2 }) {
            final WalkPosition nodeInArea = getGraph().getMap().breadthFirstSearch(this.nodes[n],
                    // findCond
                    args -> {
                        final Object ttile = args[0];
                        final Object tpos = args[1];
                        final Object tmap = args[args.length - 1];
                        if (ttile instanceof MiniTile && tpos instanceof WalkPosition && tmap instanceof Map) {
                            final MiniTile miniTile = (MiniTile) ttile;
                            final WalkPosition w = (WalkPosition) tpos;
                            final Map map = (Map) tmap;
                            return (miniTile.getAreaId().equals(area.getId()) && map.getData()
                                    .getTile(w.toTilePosition(), CheckMode.NO_CHECK).getNeutral() == null);
                        } else {
                            throw new IllegalArgumentException();
                        }
                    },
                    // visitCond
                    args -> {
                        final Object ttile = args[0];
                        final Object tpos = args[1];
                        final Object tmap = args[args.length - 1];
                        if (ttile instanceof MiniTile && tpos instanceof WalkPosition) {
                            final MiniTile miniTile = (MiniTile) ttile;
                            final WalkPosition w = (WalkPosition) tpos;
                            final Map map = (Map) tmap;
                            return (miniTile.getAreaId().equals(area.getId())
                                    || (isBlocked() && (((MiniTileImpl) miniTile).isBlocked()
                                            || map.getData().getTile(w.toTilePosition(), CheckMode.NO_CHECK)
                                                    .getNeutral() != null)));
                        } else {
                            throw new IllegalArgumentException("Invalid argument list.");
                        }
                    });

            /**
             * Note: In the original C++ code, "nodeInArea" is a reference to a "WalkPosition" in
             * "nodesInArea" which changes! Change that object here (after the call to "breadthFirstSearch")...
             */
            final WalkPosition left = nodesInArea.get(n).getLeft();
            final WalkPosition right = nodesInArea.get(n).getRight();
            final MutablePair<WalkPosition, WalkPosition> replacementPair = new MutablePair<>(left, right);
            if (area.equals(this.areas.getFirst())) {
                replacementPair.setLeft(nodeInArea);
            } else {
                replacementPair.setRight(nodeInArea);
            }
            this.nodesInArea.set(n, replacementPair);
        }
    }
}

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  ava2s  . co 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)
 *//*from  ww  w . j  a  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:AIR.Common.xml.XmlReader.java

private boolean traverseNextSibling() throws IOException {
    /*//from   w w  w.  jav a 2  s  . co  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 readToDescendant(String item) throws XmlReaderException, IOException {
    MutablePair<Content, Integer> alwaysTop = null;
    if (_stack.size() > 0) {
        alwaysTop = _stack.peek();/*from   ww  w  .ja va2  s.  co m*/
    }
    while (_stack.size() != 0) {
        MutablePair<Content, Integer> topElement = _stack.peek();

        if (topElement.getLeft().getCType() == CType.Element) {
            Element topElementNode = (Element) topElement.getLeft();
            if (StringUtils.equals(item, topElementNode.getName()))
                return true;

            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));
            } else {
                // we do not want to pop the original top node (alwaysTop) as we are
                // only doing descendant.
                if (!alwaysTop.equals(topElement))
                    _stack.pop();
                else
                    break;
            }
        }
    }

    return false;
}

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

private boolean traverseImmediateChild(boolean firstOnly) throws IOException {
    /*/*from   w  w  w  .j  a v a2  s .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;
}