List of usage examples for org.apache.commons.lang3.tuple MutablePair getRight
@Override
public R getRight()
From source file:bwem.util.PairGenericAltitudeComparator.java
@Override public int compare(MutablePair<T, Altitude> o1, MutablePair<T, Altitude> o2) { int a1 = o1.getRight().intValue(); int a2 = o2.getRight().intValue(); return Integer.compare(a1, a2); }
From source file:bwem.util.PairGenericMiniTileAltitudeComparator.java
@Override public int compare(MutablePair<T, MiniTile> o1, MutablePair<T, MiniTile> o2) { int a1 = o1.getRight().getAltitude().intValue(); int a2 = o2.getRight().getAltitude().intValue(); return Integer.compare(a1, a2); }
From source file:net.dv8tion.jda.ConnectionManager.java
private void setupSendingThread() { ratelimitThread = new Thread("Core ConnectionManager Thread") { @Override//from www.j a va 2 s .com public void run() { boolean needRatelimit; boolean attemptedToSend; while (!this.isInterrupted()) { try { //Make sure that we don't send any packets before sending auth info. // if (!sentAuthInfo) // { // Thread.sleep(500); // continue; // } attemptedToSend = false; needRatelimit = false; Map.Entry<String, MutablePair<Long, String>> requestEntry = getNextAudioConnectRequest(); System.out.println(requestEntry); if (requestEntry != null) { String guildId = requestEntry.getKey(); MutablePair<Long, String> audioRequest = requestEntry.getValue(); String channelId = audioRequest.getRight(); AudioManager audioManager = core.getAudioManager(guildId); JSONObject audioConnectPacket = new JSONObject().put("op", 4).put("d", new JSONObject().put("guild_id", guildId).put("channel_id", channelId) .put("self_mute", audioManager.isSelfMuted()) .put("self_deaf", audioManager.isSelfDeafened())); needRatelimit = !send(audioConnectPacket.toString()); System.out.println(needRatelimit); if (!needRatelimit) { //If we didn't get RateLimited, Next allowed connect request will be 2 seconds from now audioRequest.setLeft(System.currentTimeMillis() + 2000); //If the connection is already established, then the packet just sent // was a move channel packet, thus, it won't trigger the removal from // queuedAudioConnections in VoiceServerUpdateHandler because we won't receive // that event just for a move, so we remove it here after successfully sending. if (audioManager.isConnected()) { queuedAudioConnections.remove(guildId); } } attemptedToSend = true; } if (needRatelimit || !attemptedToSend) { Thread.sleep(1000); } } catch (InterruptedException ignored) { LOG.debug("ConnectionManager thread interrupted. Most likely shutting down."); break; } } } }; ratelimitThread.start(); }
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 . j a v a 2 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 ww w . j a v a 2s. 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 *//*from w ww . j a va2s. 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 . jav a2 s . c om @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 *///from ww w .j av a 2 s . 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.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 {// w ww . j a v a 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: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 value variable *//*from w w w . j a v a 2s . c o m*/ @Test public void testAverage_withNullInputToValue() throws Exception { MutablePair<Double, Integer> result = new DoubleContentAggregateFunction() .average(new MutablePair<Double, Integer>(Double.valueOf(1.34), Integer.valueOf(4)), null); Assert.assertEquals(Double.valueOf(1.34), result.getLeft()); Assert.assertEquals(Integer.valueOf(4), result.getRight()); }