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

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

Introduction

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

Prototype

@Override
public L getLeft() 

Source Link

Usage

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  w w  w.j a v a  2  s  .  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:net.dv8tion.jda.ConnectionManager.java

private Map.Entry<String, MutablePair<Long, String>> getNextAudioConnectRequest() {
    synchronized (queuedAudioConnections) {
        long now = System.currentTimeMillis();
        Iterator<Map.Entry<String, MutablePair<Long, String>>> it = queuedAudioConnections.entrySet()
                .iterator();/*from   ww  w . ja v a2  s.  c o m*/
        while (it.hasNext()) {
            Map.Entry<String, MutablePair<Long, String>> entry = it.next();
            MutablePair<Long, String> audioRequest = entry.getValue();
            if (audioRequest.getLeft() < now) {
                String channelId = audioRequest.getRight();
                String guildId = entry.getKey();
                ConnectionListener listener = core.getAudioManager(guildId).getConnectionListener();

                if (!core.getClient().inGuild(guildId)) {
                    it.remove();
                    if (listener != null)
                        listener.onStatusChange(ConnectionStatus.DISCONNECTED_REMOVED_FROM_GUILD);
                    continue;
                }

                if (!core.getClient().voiceChannelExists(channelId)) {
                    it.remove();
                    if (listener != null)
                        listener.onStatusChange(ConnectionStatus.DISCONNECTED_CHANNEL_DELETED);
                    continue;
                }

                if (!core.getClient().hasPermissionInChannel(channelId, 1 << 20)) //VOICE_CONNECT
                {
                    it.remove();
                    if (listener != null)
                        listener.onStatusChange(ConnectionStatus.DISCONNECTED_LOST_PERMISSION);
                    continue;
                }

                return entry;
            }
        }
    }

    return null;
}

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 null to both parameters
 *///from  w w  w  .j av a2 s .c  o  m
@Test
public void testAverage_withNullInputForBothParameters() throws Exception {
    MutablePair<Double, Integer> result = new DoubleContentAggregateFunction().average(null, null);
    Assert.assertEquals(Double.valueOf(0), result.getLeft());
    Assert.assertEquals(Integer.valueOf(0), 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 null as input to both parameters
 *//*www. ja  v  a 2 s.c  o m*/
@Test
public void testAverage_withNullInput() throws Exception {
    MutablePair<Integer, Integer> result = new IntegerContentAggregateFunction().average(null, null);
    Assert.assertEquals(Integer.valueOf(0), result.getLeft());
    Assert.assertEquals(Integer.valueOf(0), result.getRight());
}

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 null to sumAndCount variable
 *//*w w  w. ja v a 2 s  .c  o m*/
@Test
public void testAverage_withNullInputToSumAndCount() throws Exception {
    MutablePair<Double, Integer> result = new DoubleContentAggregateFunction().average(null,
            Double.valueOf(1.23));
    Assert.assertEquals(Double.valueOf(1.23), result.getLeft());
    Assert.assertEquals(Integer.valueOf(1), 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 null as input to old sumAndCount parameter
 *//*ww  w . j a v  a 2s .c o m*/
@Test
public void testAverage_withSumAndCountNullInput() throws Exception {
    MutablePair<Integer, Integer> result = new IntegerContentAggregateFunction().average(null,
            Integer.valueOf(123));
    Assert.assertEquals(Integer.valueOf(123), result.getLeft());
    Assert.assertEquals(Integer.valueOf(1), 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.// w  ww.java 2  s .com
 * 
 * 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:AIR.Common.xml.XmlReader.java

private boolean traverseImmediateChild(boolean firstOnly) throws IOException {
    /*//from  www.  ja  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;
}

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 w  ww.  ja v a 2s  .  c om
    }
    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:hu.ppke.itk.nlpg.purepos.model.internal.HashSuffixGuesser.java

/**
 * Calculates the probability for a given suffix and tag.
 * /* www . j  av  a2  s  .co  m*/
 * @param word
 *            the word which has the suffix
 * @param index
 *            end position of the suffix (usually the length of the suffix)
 * @param tag
 *            POS tag
 * @return
 */
@Deprecated
protected double getTagProbTnT(String word, int index, T tag) {

    if (index >= 0 && freqTable.containsKey(word.substring(index))) {
        String suffix = word.substring(index);

        MutablePair<HashMap<T, Integer>, Integer> suffixValue = freqTable.get(suffix);
        Integer tagSufFreq = suffixValue.getLeft().get(tag);
        Double tagSufFreqD;
        int newindex = index - 1;
        if (tagSufFreq == null) {
            newindex = -1;
            tagSufFreqD = 0.0;
        } else {
            tagSufFreqD = tagSufFreq.doubleValue();
        }
        Double relFreq = tagSufFreqD / suffixValue.getRight();
        double nTagProb = getTagProbTnT(word, newindex, tag);

        return (theta * relFreq + nTagProb) / thetaPlusOne;
    } else
        return 0;
}