use of java.util.Collection in project elasticsearch by elastic.
the class GeoContextMapping method toInternalQueryContexts.
/**
* Parse a list of {@link GeoQueryContext}
* using <code>parser</code>. A QueryContexts accepts one of the following forms:
*
* <ul>
* <li>Object: GeoQueryContext</li>
* <li>String: GeoQueryContext value with boost=1 precision=PRECISION neighbours=[PRECISION]</li>
* <li>Array: <pre>[GeoQueryContext, ..]</pre></li>
* </ul>
*
* A GeoQueryContext has one of the following forms:
* <ul>
* <li>Object:
* <ul>
* <li><pre>GEO POINT</pre></li>
* <li><pre>{"lat": <i><double></i>, "lon": <i><double></i>, "precision": <i><int></i>, "neighbours": <i><[int, ..]></i>}</pre></li>
* <li><pre>{"context": <i><string></i>, "boost": <i><int></i>, "precision": <i><int></i>, "neighbours": <i><[int, ..]></i>}</pre></li>
* <li><pre>{"context": <i><GEO POINT></i>, "boost": <i><int></i>, "precision": <i><int></i>, "neighbours": <i><[int, ..]></i>}</pre></li>
* </ul>
* <li>String: <pre>GEO POINT</pre></li>
* </ul>
* see {@link GeoUtils#parseGeoPoint(String, GeoPoint)} for GEO POINT
*/
@Override
public List<InternalQueryContext> toInternalQueryContexts(List<GeoQueryContext> queryContexts) {
List<InternalQueryContext> internalQueryContextList = new ArrayList<>();
for (GeoQueryContext queryContext : queryContexts) {
int minPrecision = Math.min(this.precision, queryContext.getPrecision());
GeoPoint point = queryContext.getGeoPoint();
final Collection<String> locations = new HashSet<>();
String geoHash = stringEncode(point.getLon(), point.getLat(), minPrecision);
locations.add(geoHash);
if (queryContext.getNeighbours().isEmpty() && geoHash.length() == this.precision) {
addNeighbors(geoHash, locations);
} else if (queryContext.getNeighbours().isEmpty() == false) {
queryContext.getNeighbours().stream().filter(neighbourPrecision -> neighbourPrecision < geoHash.length()).forEach(neighbourPrecision -> {
String truncatedGeoHash = geoHash.substring(0, neighbourPrecision);
locations.add(truncatedGeoHash);
addNeighbors(truncatedGeoHash, locations);
});
}
internalQueryContextList.addAll(locations.stream().map(location -> new InternalQueryContext(location, queryContext.getBoost(), location.length() < this.precision)).collect(Collectors.toList()));
}
return internalQueryContextList;
}
use of java.util.Collection in project elasticsearch by elastic.
the class ClusterModule method createAllocationDeciders.
// TODO: this is public so allocation benchmark can access the default deciders...can we do that in another way?
/** Return a new {@link AllocationDecider} instance with builtin deciders as well as those from plugins. */
public static Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings, List<ClusterPlugin> clusterPlugins) {
// collect deciders by class so that we can detect duplicates
Map<Class, AllocationDecider> deciders = new LinkedHashMap<>();
addAllocationDecider(deciders, new MaxRetryAllocationDecider(settings));
addAllocationDecider(deciders, new ReplicaAfterPrimaryActiveAllocationDecider(settings));
addAllocationDecider(deciders, new RebalanceOnlyWhenActiveAllocationDecider(settings));
addAllocationDecider(deciders, new ClusterRebalanceAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new ConcurrentRebalanceAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new EnableAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new NodeVersionAllocationDecider(settings));
addAllocationDecider(deciders, new SnapshotInProgressAllocationDecider(settings));
addAllocationDecider(deciders, new FilterAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new SameShardAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new DiskThresholdDecider(settings, clusterSettings));
addAllocationDecider(deciders, new ThrottlingAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new ShardsLimitAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new AwarenessAllocationDecider(settings, clusterSettings));
clusterPlugins.stream().flatMap(p -> p.createAllocationDeciders(settings, clusterSettings).stream()).forEach(d -> addAllocationDecider(deciders, d));
return deciders.values();
}
use of java.util.Collection in project elasticsearch by elastic.
the class ClusterModuleTests method testRegisterAllocationDeciderDuplicate.
public void testRegisterAllocationDeciderDuplicate() {
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new ClusterModule(Settings.EMPTY, clusterService, Collections.<ClusterPlugin>singletonList(new ClusterPlugin() {
@Override
public Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) {
return Collections.singletonList(new EnableAllocationDecider(settings, clusterSettings));
}
})));
assertEquals(e.getMessage(), "Cannot specify allocation decider [" + EnableAllocationDecider.class.getName() + "] twice");
}
use of java.util.Collection in project buck by facebook.
the class Types method getContainerClass.
/**
* @return The raw type of the {@link Collection} a field represents, even if contained in an
* {@link Optional}, but without the ParameterizedType information.
*/
@SuppressWarnings("unchecked")
@Nullable
public static Class<? extends Collection<?>> getContainerClass(Field field) {
Type type = getFirstNonOptionalType(field);
if (!(type instanceof ParameterizedType)) {
return null;
}
Type rawType = ((ParameterizedType) type).getRawType();
if (!(rawType instanceof Class)) {
return null;
}
Class<?> clazz = (Class<?>) rawType;
if (!(Collection.class.isAssignableFrom(clazz))) {
return null;
}
return (Class<? extends Collection<?>>) clazz;
}
use of java.util.Collection in project jetty.project by eclipse.
the class ObjectMBean method getAttribute.
/* ------------------------------------------------------------ */
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
Method getter = (Method) _getters.get(name);
if (getter == null) {
throw new AttributeNotFoundException(name);
}
try {
Object o = _managed;
if (getter.getDeclaringClass().isInstance(this))
// mbean method
o = this;
// get the attribute
Object r = getter.invoke(o, (java.lang.Object[]) null);
// convert to ObjectName if the type has the @ManagedObject annotation
if (r != null) {
if (r.getClass().isArray()) {
if (r.getClass().getComponentType().isAnnotationPresent(ManagedObject.class)) {
ObjectName[] on = new ObjectName[Array.getLength(r)];
for (int i = 0; i < on.length; i++) {
on[i] = _mbeanContainer.findMBean(Array.get(r, i));
}
r = on;
}
} else if (r instanceof Collection<?>) {
@SuppressWarnings("unchecked") Collection<Object> c = (Collection<Object>) r;
if (!c.isEmpty() && c.iterator().next().getClass().isAnnotationPresent(ManagedObject.class)) {
// check the first thing out
ObjectName[] on = new ObjectName[c.size()];
int i = 0;
for (Object obj : c) {
on[i++] = _mbeanContainer.findMBean(obj);
}
r = on;
}
} else {
Class<?> clazz = r.getClass();
while (clazz != null) {
if (clazz.isAnnotationPresent(ManagedObject.class)) {
ObjectName mbean = _mbeanContainer.findMBean(r);
if (mbean != null) {
return mbean;
} else {
return null;
}
}
clazz = clazz.getSuperclass();
}
}
}
return r;
} catch (IllegalAccessException e) {
LOG.warn(Log.EXCEPTION, e);
throw new AttributeNotFoundException(e.toString());
} catch (InvocationTargetException e) {
LOG.warn(Log.EXCEPTION, e);
throw new ReflectionException(new Exception(e.getCause()));
}
}
Aggregations