/** * If an array only consists of zero or one element, which is "*" or "_all" return an empty array * which is usually used as everything */ public static boolean isAllOrWildcard(String[] data) { return CollectionUtils.isEmpty(data) || data.length == 1 && ("_all".equals(data[0]) || "*".equals(data[0])); }
private static IllegalArgumentException newOperatorException(String op) { return new IllegalArgumentException("operator needs to be either " + CollectionUtils.arrayAsArrayList(values()) + ", but not [" + op + "]"); } }
public static void ensureNoSelfReferences(Object value) { Iterable<?> it = convert(value); if (it != null) { ensureNoSelfReferences(it, value, Collections.newSetFromMap(new IdentityHashMap<>())); } }
public static void sortAndDedup(LongArrayList list) { list.elementsCount = sortAndDedup(list.buffer, list.elementsCount); }
@Override protected void doPostCollection() throws IOException { CollectionUtils.ensureNoSelfReferences(aggState); super.doPostCollection(); } }
/** * Returns the given nodes sorted by likelihood of being elected as master, most likely first. * Non-master nodes are not removed but are rather put in the end */ static List<DiscoveryNode> sortByMasterLikelihood(Iterable<DiscoveryNode> nodes) { ArrayList<DiscoveryNode> sortedNodes = CollectionUtils.iterableAsArrayList(nodes); CollectionUtil.introSort(sortedNodes, ElectMasterService::compareNodes); return sortedNodes; }
public static void sort(final BytesRefArray bytes, final int[] indices) { sort(new BytesRefBuilder(), new BytesRefBuilder(), bytes, indices); }
public static Logger getLogger(Class<?> clazz, Index index, String... prefixes) { return getLogger(clazz, asArrayList(Loggers.SPACE, index.getName(), prefixes).toArray(new String[0])); }
@Override public List<ShardRouting> shuffle(List<ShardRouting> shards, int seed) { return CollectionUtils.rotate(shards, seed); }
public static void sortAndDedup(FloatArrayList list) { list.elementsCount = sortAndDedup(list.buffer, list.elementsCount); }
private void set(int i, Object o) { if (o == null) { values[i].clear(); } else { CollectionUtils.ensureNoSelfReferences(o); values[i].copyChars(o.toString()); } }
private List<DiscoveryNode> sortedMasterNodes(Iterable<DiscoveryNode> nodes) { List<DiscoveryNode> possibleNodes = CollectionUtils.iterableAsArrayList(nodes); if (possibleNodes.isEmpty()) { return null; } // clean non master nodes possibleNodes.removeIf(node -> !node.isMasterNode()); CollectionUtil.introSort(possibleNodes, ElectMasterService::compareNodes); return possibleNodes; }
public static void sortAndDedup(final ObjectArrayList<byte[]> array) { int len = array.size(); if (len > 1) { sort(array); int uniqueCount = 1; for (int i = 1; i < len; ++i) { if (!Arrays.equals(array.get(i), array.get(i - 1))) { array.set(uniqueCount++, array.get(i)); } } array.elementsCount = uniqueCount; } }
public static Logger getLogger(Class<?> clazz, ShardId shardId, String... prefixes) { return getLogger(clazz, shardId.getIndex(), asArrayList(Integer.toString(shardId.id()), prefixes).toArray(new String[0])); }
@Override public List<ShardRouting> shuffle(List<ShardRouting> shards, int seed) { return CollectionUtils.rotate(shards, seed); }
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (CollectionUtils.isEmpty(indices)) { validationException = addValidationError("index / indices is missing", validationException); } return validationException; }
public static GeoValidationMethod fromString(String op) { for (GeoValidationMethod method : GeoValidationMethod.values()) { if (method.name().equalsIgnoreCase(op)) { return method; } } throw new IllegalArgumentException("operator needs to be either " + CollectionUtils.arrayAsArrayList(GeoValidationMethod.values()) + ", but not [" + op + "]"); }
public static void sortAndDedup(DoubleArrayList list) { list.elementsCount = sortAndDedup(list.buffer, list.elementsCount); }
private static void ensureNoSelfReferences(final Iterable<?> value, Object originalReference, final Set<Object> ancestors) { if (value != null) { if (ancestors.add(originalReference) == false) { throw new IllegalArgumentException("Iterable object is self-referencing itself"); } for (Object o : value) { ensureNoSelfReferences(convert(o), o, ancestors); } ancestors.remove(originalReference); } }
@Override public InternalAggregation buildAggregation(long owningBucketOrdinal) { Object aggregation; if (combineScript != null) { aggregation = combineScript.execute(); CollectionUtils.ensureNoSelfReferences(aggregation); } else { aggregation = aggState; } return new InternalScriptedMetric(name, aggregation, reduceScript, pipelineAggregators(), metaData()); }