List of usage examples for org.apache.commons.lang3.tuple ImmutableTriple ImmutableTriple
public ImmutableTriple(final L left, final M middle, final R right)
From source file:com.minlia.cloud.framework.test.common.web.AbstractSearchReadOnlyLiveTest.java
@Test public final void whenSearchByStartsWithIsPerformed_thenNoExceptions() { // When//from w w w. j a v a 2s . co m final ImmutableTriple<String, ClientOperation, String> nameConstraint = new ImmutableTriple<String, ClientOperation, String>( SearchField.name.toString(), ClientOperation.STARTS_WITH, randomAlphabetic(8)); getApi().searchAll(nameConstraint); }
From source file:com.linkedin.pinot.core.realtime.impl.kafka.KafkaConsumerManager.java
public static ConsumerAndIterator acquireConsumerAndIteratorForConfig( KafkaHighLevelStreamProviderConfig config) { final ImmutableTriple<String, String, String> configKey = new ImmutableTriple<>(config.getTopicName(), config.getGroupId(), config.getZkString()); synchronized (KafkaConsumerManager.class) { // If we have the consumer and it's not already acquired, return it, otherwise error out if it's already acquired if (CONSUMER_AND_ITERATOR_FOR_CONFIG_KEY.containsKey(configKey)) { ConsumerAndIterator consumerAndIterator = CONSUMER_AND_ITERATOR_FOR_CONFIG_KEY.get(configKey); if (CONSUMER_RELEASE_TIME.get(consumerAndIterator).equals(IN_USE)) { throw new RuntimeException( "Consumer/iterator " + consumerAndIterator.getId() + " already in use!"); } else { LOGGER.info("Reusing kafka consumer/iterator with id {}", consumerAndIterator.getId()); CONSUMER_RELEASE_TIME.put(consumerAndIterator, IN_USE); return consumerAndIterator; }/*from w w w . j av a 2s .c o m*/ } LOGGER.info("Creating new kafka consumer and iterator for topic {}", config.getTopicName()); // Create the consumer ConsumerConnector consumer = kafka.consumer.Consumer .createJavaConsumerConnector(config.getKafkaConsumerConfig()); // Create the iterator (can only be done once per consumer) ConsumerIterator<byte[], byte[]> iterator = consumer.createMessageStreams(config.getTopicMap(1)) .get(config.getTopicName()).get(0).iterator(); // Mark both the consumer and iterator as acquired ConsumerAndIterator consumerAndIterator = new ConsumerAndIterator(consumer, iterator); CONSUMER_AND_ITERATOR_FOR_CONFIG_KEY.put(configKey, consumerAndIterator); CONSUMER_RELEASE_TIME.put(consumerAndIterator, IN_USE); LOGGER.info("Created consumer/iterator with id {} for topic {}", consumerAndIterator.getId(), config.getTopicName()); return consumerAndIterator; } }
From source file:com.minlia.cloud.framework.test.common.util.SearchIntegrationTestUtil.java
public static <T extends Serializable> void givenResourceExists_whenSearchByEndsWithEntireKeyIsPerformed_thenResourceIsFound( final IOperations<T> api, final T newEntity, final SearchField key, final ClientOperation op, final String value) { final T existingEntity = api.create(newEntity); // When//from www . j a v a 2s.c o m final ImmutableTriple<String, ClientOperation, String> constraint = new ImmutableTriple<String, ClientOperation, String>( key.toString(), op, value); final List<T> searchResults = api.searchAll(constraint); // Then assertThat(searchResults, hasItem(existingEntity)); }
From source file:com.minlia.cloud.framework.test.common.service.search.AbstractSearchIntegrationTest.java
@Override @Test//from w w w . j av a2 s .c o m public final void givenResourceWithIdExists_whenResourceIsSearchedById_thenSearchOperationIsSuccessful() { final T existingResource = persistNewEntity(); // When final ImmutableTriple<String, ClientOperation, String> idConstraint = new ImmutableTriple<String, ClientOperation, String>( SearchField.id.toString(), EQ, existingResource.getId().toString()); final List<T> searchResults = getApi().searchAll(idConstraint); // Then assertThat(searchResults, Matchers.not(Matchers.<T>empty())); }
From source file:io.github.autsia.crowly.services.geolocation.impl.GeoLocationServiceImpl.java
@Override public Map<String, Triple<Double, Double, Double>> getLocationsAsMap(List<String> regionNames) { Map<String, Triple<Double, Double, Double>> result = new HashMap<>(); try {/*from w w w .j a va 2s. c o m*/ for (String regionName : regionNames) { HttpResponse<JsonNode> request = Unirest.get(geoAPIURL).field("sensor", true) .field("key", geoAPICode).field("address", regionName).asJson(); JSONObject response = request.getBody().getObject().getJSONArray(RESULTS).getJSONObject(0) .getJSONObject(GEOMETRY); JSONObject location = response.getJSONObject(LOCATION); JSONObject bounds = response.getJSONObject(BOUNDS); Point center = getCenter(location); Double distance = getDistance(bounds); result.put(regionName, new ImmutableTriple<>(center.getX(), center.getY(), distance)); } } catch (UnirestException | JSONException e) { logger.error(e.getMessage(), e); } return result; }
From source file:com.minlia.cloud.framework.test.common.web.AbstractSearchReadOnlyLiveTest.java
@Test public final void whenSearchByEndsWithIsPerformed_thenNoExceptions() { // When/*from w ww . ja v a 2s. co m*/ final ImmutableTriple<String, ClientOperation, String> nameConstraint = new ImmutableTriple<String, ClientOperation, String>( SearchField.name.toString(), ENDS_WITH, randomAlphabetic(8)); getApi().searchAll(nameConstraint); }
From source file:it.unibo.alchemist.language.protelis.util.ReflectionUtils.java
/** * @param clazz/*from ww w . j ava 2 s . co m*/ * the class where to search for suitable methods * @param methodName * the method to be invoked * @param args * the arguments for the method * @return the result of the invocation, or an {@link IllegalStateException} * if something goes wrong. */ public static Method searchBestMethod(final Class<?> clazz, final String methodName, final List<Object> args) { final List<Class<?>> argClass = new ArrayList<>(); for (Object i : args) { argClass.add(i.getClass()); } try { return METHOD_CACHE.get((Triple) new ImmutableTriple<>(clazz, methodName, argClass)); } catch (ExecutionException e) { throw new NoSuchMethodError(methodName + "/" + args.size() + argClass + " does not exist in " + clazz + ". You tried to invoke it with arguments " + args); } }
From source file:com.minlia.cloud.framework.test.common.util.SearchIntegrationTestUtil.java
public static <T extends Serializable> void givenResourceExists_whenSearchByEndsWithIncorrectPartOfKeyIsPerformed_thenResourceIsNotFound( final IOperations<T> api, final T existingEntity, final SearchField key, final ClientOperation op, final String value) { final String partOfValue = value.substring(2, 5); // When//from w w w .j a v a 2 s .c o m final ImmutableTriple<String, ClientOperation, String> containsConstraint = new ImmutableTriple<String, ClientOperation, String>( key.toString(), op, partOfValue); final List<T> searchResults = api.searchAll(containsConstraint); // Then assertThat(searchResults, not(hasItem(existingEntity))); }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.description.KubernetesManifest.java
public static Triple<KubernetesApiVersion, KubernetesKind, String> fromFullResourceName( String fullResourceName) { String[] split = fullResourceName.split("\\|"); if (split.length != 3) { throw new IllegalArgumentException("Expected a full resource name of the form <version>|<kind>|<name>"); }/*from w ww. jav a 2 s. c o m*/ KubernetesApiVersion apiVersion = KubernetesApiVersion.fromString(split[0]); KubernetesKind kind = KubernetesKind.fromString(split[1]); String name = split[2]; return new ImmutableTriple<>(apiVersion, kind, name); }
From source file:com.minlia.cloud.framework.test.common.service.search.AbstractSearchIntegrationTest.java
@Override @Test/*from w ww .ja v a 2s. c o m*/ public final void givenResourceWithIdDoesNotExist_whenResourceIsSearchedById_thenResourceIsNotFound() { final T existingResource = persistNewEntity(); // When final ImmutableTriple<String, ClientOperation, String> idConstraint = new ImmutableTriple<String, ClientOperation, String>( SearchField.id.toString(), EQ, IDUtil.randomPositiveLongAsString()); final List<T> searchResults = getApi().searchAll(idConstraint); // Then assertThat(searchResults, not(hasItem(existingResource))); }