List of usage examples for org.apache.commons.lang3.tuple ImmutablePair of
public static <L, R> ImmutablePair<L, R> of(final L left, final R right)
Obtains an immutable pair of from two objects inferring the generic types.
This factory allows the pair to be created using inference to obtain the generic types.
From source file:io.lavagna.web.helper.UserSession.java
private static ImmutablePair<Integer, String> extractUserIdAndToken(String cookieVal) { if (cookieVal == null) { return null; }// ww w . j a v a2 s.c om try { String[] splitted = cookieVal.split(","); if (splitted.length == 2) { int userId = Integer.valueOf(splitted[0], 10); String token = splitted[1]; if (token != null) { return ImmutablePair.of(userId, token); } } } catch (NullPointerException | NumberFormatException e) { LOG.debug("error while extracting userid and token", e); } return null; }
From source file:io.github.carlomicieli.footballdb.starter.pages.PageTests.java
@Test public void shouldGetValuesFromTablesWithoutHeaderOrBody() { String html = "<table id=\"my-table\">" + "<tr><td>1</td><td>one</td></tr>" + "<tr><td>2</td><td>two</td></tr>" + "<tr><td>3</td><td>three</td></tr>" + "</table>"; Page page = page(fromHtml(html));/* w w w . j a v a 2 s .co m*/ Table table = page.getTableById("my-table").orElse(null); assertThat(table).isNotNull(); assertThat(table.size()).isEqualTo(ImmutablePair.of(3, 2)); }
From source file:com.joyent.manta.http.ApacheHttpHeaderUtils.java
/** * Checks that a request has headers which are compatible. This means that the request either: * <ul>/*from ww w . j a v a2 s . c o m*/ * <li>has no If-Match header and no ETag header</li> * <li>has a single-valued If-Match header</li> * <li>has a single Range header specifying a single byte range (i.e. no multipart ranges)</li> * <li>satisfies both #2 and #3</li> * </ul> * * @param request the request being checked for compatibility * @return the ETag and range hints to be validated against the initial response * @throws HttpDownloadContinuationIncompatibleRequestException when the request cannot be resumed */ static Pair<String, Request> extractDownloadRequestFingerprint(final HttpGet request) throws ProtocolException { String ifMatch = null; Request range = null; ProtocolException ifMatchEx = null; ProtocolException rangeEx = null; try { ifMatch = extractSingleHeaderValue(request, IF_MATCH, false); } catch (final ProtocolException e) { ifMatchEx = e; } try { final String rawRequestRange = extractSingleHeaderValue(request, RANGE, false); if (rawRequestRange != null) { range = HttpRange.parseRequestRange(rawRequestRange); } } catch (final ProtocolException e) { rangeEx = e; } if (ifMatchEx != null && rangeEx != null) { throw new ProtocolException( String.format("Incompatible Range and If-Match request headers for resuming download:%n%s%n%s", rangeEx.getMessage(), ifMatchEx.getMessage())); } else if (ifMatchEx != null) { throw ifMatchEx; } else if (rangeEx != null) { throw rangeEx; } return ImmutablePair.of(ifMatch, range); }
From source file:com.github.jakubkolar.autobuilder.impl.NamedResolver.java
@Nullable @Override//from w ww. j a va2 s.c o m public <T> T resolve(Class<T> type, Optional<Type> typeInfo, String name, Collection<Annotation> annotations) { // If type is primitive like int.class, we must use its wrapper type // because the wrapper type is used as a part of the key in the namedValues // and also because int.class cannot be used in the end to 'unbox' the result // (same in BuiltInResolvers.primitiveTypeResolver, you would get ClassCastException) Class<T> wrappedType = Primitives.wrap(type); @SuppressWarnings("rawtypes") RegisteredValue rv = namedValues.get(ImmutablePair.of(name, (Class) wrappedType)); if (rv == null) { // TODO: try to lookup null, which this way applies to _any_ type rv = namedValues.get(ImmutablePair.of(name, (Class) null)); if (rv == null) { throw new UnsupportedOperationException(String.format( "There is no registered named value with name %s and type %s", name, type.getSimpleName())); } } for (Annotation requiredAnnotation : rv.getAnnotations()) { if (!annotations.contains(requiredAnnotation)) { throw new UnsupportedOperationException(String.format( "The named value with name %s and type %s requires annotations %s, " + "but only these annotations were present: %s", name, type.getSimpleName(), requiredAnnotation, annotations)); } } try { return wrappedType.cast(rv.getValue()); } catch (ClassCastException e) { throw new UnsupportedOperationException( String.format("Named value %s cannot be converted to the required type %s because of: %s", name, type.getSimpleName(), e.getMessage()), e); } }
From source file:com.creditcloud.interestbearing.model.CreditCloudTAConfig.java
public Pair<String, String> firstFund() { if (registeredProducts == null || registeredProducts.isEmpty()) { return null; }//from w w w . ja v a2 s . co m ProductFundMetadata p = registeredProducts.get(0).getProduct(); if (p == null) { return null; } String broker = StringUtils.defaultString(p.getBroker()); String fundId = StringUtils.defaultString(p.getFund_id()); return ImmutablePair.of(broker, fundId); }
From source file:io.github.carlomicieli.footballdb.starter.pages.Table.java
private IntFunction<ImmutablePair<String, String>> bindHeaderWithValue(List<String> cells) { return index -> ImmutablePair.of(headers.get(index), cells.get(index)); }
From source file:io.github.carlomicieli.footballdb.starter.pages.PageTests.java
@Test public void shouldGetValuesFromTablesWithHeaderAndWithoutBody() { String html = "<table id=\"my-table\">" + "<thead><tr><td>col1</td><td>col2</td></tr></thead>" + "<tr><td>1</td><td>one</td></tr>" + "<tr><td>2</td><td>two</td></tr>" + "<tr><td>3</td><td>three</td></tr>" + "</table>"; Page page = page(fromHtml(html));//from w w w .ja va2s .co m Table table = page.getTableById("my-table").orElse(null); assertThat(table).isNotNull(); assertThat(table.header()).contains("col1", "col2"); assertThat(table.size()).isEqualTo(ImmutablePair.of(3, 2)); }
From source file:com.wrmsr.wava.driver.PassType.java
public static Map<String, PassType> buildPassTypeMap(Injector injector) { return injector.getBindings().entrySet().stream() .filter(e -> e.getKey().getTypeLiteral().getRawType() == PassType.class) .map(e -> ImmutablePair.of( e.getKey().getAnnotation() instanceof Named ? ((Named) e.getKey().getAnnotation()).value() : ((PassType) e.getValue().getProvider().get()).getName(), (PassType) e.getValue().getProvider().get())) .collect(toImmutableMap());// w w w . j a va 2s . co m }
From source file:com.wrmsr.wava.util.collect.MoreMultimaps.java
public static <K, V> Multimap<K, V> unmodifiableMultimapView(Map<K, Collection<V>> collectionMap) { // checkArgument(collectionMap.values().stream().allMatch(coll -> !coll.isEmpty())); return new Multimap<K, V>() { private OptionalInt size = OptionalInt.empty(); private int cachedSize() { if (!size.isPresent()) { size = OptionalInt.of(collectionMap.values().stream().mapToInt(coll -> { checkState(!coll.isEmpty()); return coll.size(); }).sum());//from w w w . jav a 2 s . c om } return size.getAsInt(); } @Override public int size() { return cachedSize(); } @Override public boolean isEmpty() { return !collectionMap.isEmpty(); } @Override public boolean containsKey(@Nullable Object key) { return collectionMap.containsKey(key); } @Override public boolean containsValue(@Nullable Object value) { return collectionMap.values().stream().anyMatch(coll -> coll.contains(value)); } @Override public boolean containsEntry(@Nullable Object key, @Nullable Object value) { return collectionMap.getOrDefault(key, ImmutableList.of()).contains(value); } @Override public boolean put(@Nullable K key, @Nullable V value) { throw new UnsupportedOperationException(); } @Override public boolean remove(@Nullable Object key, @Nullable Object value) { throw new UnsupportedOperationException(); } @Override public boolean putAll(@Nullable K key, Iterable<? extends V> values) { throw new UnsupportedOperationException(); } @Override public boolean putAll(Multimap<? extends K, ? extends V> multimap) { throw new UnsupportedOperationException(); } @Override public Collection<V> replaceValues(@Nullable K key, Iterable<? extends V> values) { throw new UnsupportedOperationException(); } @Override public Collection<V> removeAll(@Nullable Object key) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } @Override public Collection<V> get(@Nullable K key) { return collectionMap.getOrDefault(key, ImmutableList.of()); } @Override public Set<K> keySet() { return collectionMap.keySet(); } @Override public Multiset<K> keys() { // FIXME throw new UnsupportedOperationException(); } @Override public Collection<V> values() { return new AbstractCollection<V>() { @Override public Iterator<V> iterator() { return Iterators.concat(collectionMap.values().stream().map(Iterable::iterator).iterator()); } @Override public int size() { return cachedSize(); } }; } @Override public Collection<Map.Entry<K, V>> entries() { return new AbstractCollection<Map.Entry<K, V>>() { @Override public Iterator<Map.Entry<K, V>> iterator() { return Iterators.concat(collectionMap.entrySet().stream() .map(entry -> entry.getValue().stream() .map(value -> ImmutablePair.of(entry.getKey(), value)).iterator()) .iterator()); } @Override public int size() { return cachedSize(); } }; } @Override public Map<K, Collection<V>> asMap() { return collectionMap; } }; }
From source file:com.addthis.hydra.job.store.CachedSpawnDataStore.java
@Override public void putAsChild(String parent, String childId, String value) throws Exception { dataStore.putAsChild(parent, childId, value); cache.put(ImmutablePair.of(parent, childId), value); }