List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair
public ImmutablePair(final L left, final R right)
From source file:org.amanzi.neo.loader.core.synonyms.SynonymsManagerTest.java
@SuppressWarnings("unchecked") @Test//from w w w . j a v a 2s .co m public void testCheckActivityOnLoadSynonyms() throws Exception { when(registry.getConfigurationElementsFor("org.amanzi.loaderSynonyms")) .thenReturn(new IConfigurationElement[] {}); synonymsManager = spy(new SynonymsManager(registry)); doReturn(new ImmutablePair<INodeType, Synonyms>(DEFAULT_NODE_TYPE, new Synonyms(StringUtils.EMPTY, ArrayUtils.EMPTY_STRING_ARRAY))).when(synonymsManager) .parseSynonyms(any(Entry.class)); String[] lines = { SYNONYMS_LINE_WITH_SUBTYPE, SYNONYMS_LINE_WITHOUT_CLASS }; synonymsManager.loadSynonyms(getSynonymsStream(lines)); verify(synonymsManager, times(lines.length)).parseSynonyms(any(Entry.class)); }
From source file:org.amanzi.neo.loader.core.synonyms.SynonymsManagerTest.java
@Test public void testCheckParsingFullStatisticsLine() throws Exception { String[] synonymsArray = getSynonyms(SYNONYM_BASE, SYNONYMBS_NUMBER); Entry<Object, Object> entry = new ImmutablePair<Object, Object>(KEY_WITH_SUBTYPE_AND_CLASS, getSynonymsLine(synonymsArray)); when(registry.getConfigurationElementsFor("org.amanzi.loaderSynonyms")) .thenReturn(new IConfigurationElement[] {}); synonymsManager = new SynonymsManager(registry); Pair<INodeType, Synonyms> result = synonymsManager.parseSynonyms(entry); assertEquals("unexpected subtype", DEFAULT_NODE_TYPE, result.getKey()); Synonyms synonyms = result.getValue(); assertNotNull("synonyms should not be null", synonyms); assertEquals("unexpected property", DEFAULT_PROPERTY, synonyms.getPropertyName()); assertEquals("unexpected class", DEFAULT_CLASS, synonyms.getSynonymType().getSynonymClass()); assertTrue("unexpected synonyms", Arrays.equals(synonymsArray, synonyms.getPossibleHeaders())); }
From source file:org.amanzi.neo.loader.core.synonyms.SynonymsManagerTest.java
@Test public void testCheckParsingStatisticsLineWithoutClass() throws Exception { String[] synonymsArray = getSynonyms(SYNONYM_BASE, SYNONYMBS_NUMBER); Entry<Object, Object> entry = new ImmutablePair<Object, Object>(KEY_WITH_NODETYPE, getSynonymsLine(synonymsArray)); when(registry.getConfigurationElementsFor("org.amanzi.loaderSynonyms")) .thenReturn(new IConfigurationElement[] {}); synonymsManager = spy(new SynonymsManager(registry)); Pair<INodeType, Synonyms> result = synonymsManager.parseSynonyms(entry); assertEquals("unexpected subtype", DEFAULT_NODE_TYPE, result.getKey()); Synonyms synonyms = result.getValue(); assertNotNull("synonyms should not be null", synonyms); assertEquals("unexpected property", DEFAULT_PROPERTY, synonyms.getPropertyName()); assertEquals("unexpected class", SynonymType.UNKOWN, synonyms.getSynonymType()); assertTrue("unexpected synonyms", Arrays.equals(synonymsArray, synonyms.getPossibleHeaders())); }
From source file:org.apache.apex.examples.nyctaxi.NycTaxiDataServer.java
public Pair<String, String> recommendZip(double lat, double lon) { String currentZip = NycLocationUtils.getZip(lat, lon); String zip = currentZip;/*from w w w . j a v a 2s . c o m*/ String[] neighboringZips = NycLocationUtils.getNeighboringZips(zip); double dollars = servingData.containsKey(zip) ? servingData.get(zip) : 0; LOG.info("Current zip: {}={}", zip, dollars); for (String neigboringZip : neighboringZips) { double tmpDollars = servingData.containsKey(neigboringZip) ? servingData.get(neigboringZip) : 0; LOG.info("Neighboring zip: {}={}", neigboringZip, tmpDollars); if (tmpDollars > dollars) { dollars = tmpDollars; zip = neigboringZip; } } return new ImmutablePair<>(currentZip, zip); }
From source file:org.apache.apex.malhar.lib.state.spillable.SpillableSetMultimapImpl.java
/** * Note that this always returns null because the set is no longer valid after this call * * @param key//from w ww . j av a 2 s .c om * @return null */ @Override public Set<V> removeAll(@NotNull Object key) { SpillableSetImpl<V> spillableSet = getHelper((K) key); if (spillableSet != null) { cache.remove((K) key); map.put((K) key, new ImmutablePair<>(0, spillableSet.getHead())); spillableSet.clear(); removedSets.add(spillableSet); } return null; }
From source file:org.apache.apex.malhar.lib.state.spillable.SpillableSetMultimapImpl.java
@Override public void endWindow() { for (K key : cache.getChangedKeys()) { SpillableSetImpl<V> spillableSet = cache.get(key); spillableSet.endWindow();//from ww w . j av a2 s. com map.put(key, new ImmutablePair<>(spillableSet.size(), spillableSet.getHead())); } for (SpillableSetImpl removedSet : removedSets) { removedSet.endWindow(); } removedSets.clear(); cache.endWindow(); map.endWindow(); keyValueSerdeManager.resetReadBuffer(); }
From source file:org.apache.apex.malhar.lib.utils.serde.PairSerde.java
@Override public Pair<T1, T2> deserialize(Input input) { T1 first = serde1.deserialize(input); T2 second = serde2.deserialize(input); return new ImmutablePair<>(first, second); }
From source file:org.apache.apex.malhar.lib.utils.serde.PairSerdeTest.java
@Test public void simpleSerdeTest() { PairSerde<String, Integer> serdePair = new PairSerde<>(new StringSerde(), new IntSerde()); Pair<String, Integer> pair = new ImmutablePair<>("abc", 123); SerializationBuffer buffer = new SerializationBuffer(new WindowedBlockStream()); serdePair.serialize(pair, buffer);//from ww w . ja v a 2 s .c o m Slice slice = buffer.toSlice(); Pair<String, Integer> deserializedPair = serdePair .deserialize(new Input(slice.buffer, slice.offset, slice.length)); Assert.assertEquals(pair, deserializedPair); }
From source file:org.apache.apex.malhar.lib.utils.serde.SerdePairSlice.java
@Override public Pair<T1, T2> deserialize(Slice slice, MutableInt offset) { T1 first = serde1.deserialize(slice, offset); T2 second = serde2.deserialize(slice, offset); return new ImmutablePair<>(first, second); }
From source file:org.apache.apex.malhar.lib.utils.serde.SerdePairSliceTest.java
@Test public void simpleSerdeTest() { SerdePairSlice<String, Integer> serdePair = new SerdePairSlice<>(new SerdeStringSlice(), new SerdeIntSlice()); Pair<String, Integer> pair = new ImmutablePair<>("abc", 123); Slice slice = serdePair.serialize(pair); Pair<String, Integer> deserializedPair = serdePair.deserialize(slice); Assert.assertEquals(pair, deserializedPair); }