ObjectArrayList<Transition> getTransitions() { if (transitions == null) { transitions = new ObjectArrayList<>(domain.size() * 2); for (DependencyNode node : domain) { if (node.transitions != null) { for (ObjectCursor<Transition> cursor : node.transitionList) { Transition transition = cursor.value; if (transition.filter != null || transition.destination.typeSet != this) { transitions.add(transition); } } } } } return transitions; }
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; } }
@Override public BytesRef binaryValue() { try { CollectionUtils.sortAndDedup(bytesList); int size = bytesList.size(); final byte[] bytes = new byte[totalSize + (size + 1) * 5]; ByteArrayDataOutput out = new ByteArrayDataOutput(bytes); out.writeVInt(size); // write total number of values for (int i = 0; i < size; i ++) { final byte[] value = bytesList.get(i); int valueLength = value.length; out.writeVInt(valueLength); out.writeBytes(value, 0, valueLength); } return new BytesRef(bytes, 0, out.getPosition()); } catch (IOException e) { throw new ElasticsearchException("Failed to get binary value", e); } } }
@Override protected void setPivot(int i) { pivot = array.get(i); }
/** * Deletes the given indices from the tests cluster. If no index name is passed to this method * all indices are removed. */ public void wipeIndices(String... indices) { assert indices != null && indices.length > 0; if (size() > 0) { try { assertAcked(client().admin().indices().prepareDelete(indices)); } catch (IndexNotFoundException e) { // ignore } catch (IllegalArgumentException e) { // Happens if `action.destructive_requires_name` is set to true // which is the case in the CloseIndexDisableCloseAllTests if ("_all".equals(indices[0])) { ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().execute().actionGet(); ObjectArrayList<String> concreteIndices = new ObjectArrayList<>(); for (IndexMetaData indexMetaData : clusterStateResponse.getState().metaData()) { concreteIndices.add(indexMetaData.getIndex().getName()); } if (!concreteIndices.isEmpty()) { assertAcked(client().admin().indices().prepareDelete(concreteIndices.toArray(String.class))); } } } } }
/** * Adds all elements from another iterable. */ public int addAll(Iterable<? extends ObjectCursor<? extends KType>> iterable) { int size = 0; for (ObjectCursor<? extends KType> cursor : iterable) { add(cursor.value); size++; } return size; }
ObjectArrayList<Transition> transitions = new ObjectArrayList<>(typeSet.getTransitions()); List<ConsumerWithNode> consumerEntries = typeSet.getConsumers();
/** * Compare index-aligned elements against another * {@link ObjectIndexedContainer}. * Equality comparison is performed with this object's {@link #equals(Object, Object)} * method. */ protected boolean equalElements(ObjectArrayList<?> other) { int max = size(); if (other.size() != max) { return false; } for (int i = 0; i < max; i++) { if (!this.equals(other.get(i), get(i))) { return false; } } return true; }
/** * Ensure this container can hold at least the given number of elements * without resizing its buffers. * * @param expectedElements * The total number of elements, inclusive. */ @Override public void ensureCapacity(int expectedElements) { final int bufferLen = (buffer == null ? 0 : buffer.length); if (expectedElements > bufferLen) { ensureBufferSpace(expectedElements - size()); } }
/** * Adds all elements from another container. */ public int addAll(ObjectContainer<? extends KType> container) { final int size = container.size(); ensureBufferSpace(size); for (ObjectCursor<? extends KType> cursor : container) { add(cursor.value); } return size; }
private void connectClassValueNodes() { if (classNodeComplete) { return; } classNodeComplete = true; if (classNodeParent == null || classNodeParent.transitions == null) { return; } for (Transition transition : classNodeParent.transitionList.toArray(Transition.class)) { connect(transition.destination.getClassValueNode()); } }
/** * Creates a new list from the elements of another container in its * iteration order. */ public ObjectArrayList(ObjectContainer<? extends KType> container) { this(container.size()); addAll(container); }
@Override public BytesRef binaryValue() { try { CollectionUtils.sortAndDedup(bytesList); int size = bytesList.size(); final byte[] bytes = new byte[totalSize + (size + 1) * 5]; ByteArrayDataOutput out = new ByteArrayDataOutput(bytes); out.writeVInt(size); // write total number of values for (int i = 0; i < size; i ++) { final byte[] value = bytesList.get(i); int valueLength = value.length; out.writeVInt(valueLength); out.writeBytes(value, 0, valueLength); } return new BytesRef(bytes, 0, out.getPosition()); } catch (IOException e) { throw new ElasticsearchException("Failed to get binary value", e); } } }