@Override public Vector<T> removeAll(T element) { HashArrayMappedTrie<Integer, T> result = HashArrayMappedTrie.empty(); for (int i = 0; i < length(); i++) { final T value = get(i); if (!element.equals(value)) { result = result.put(result.size(), value); } } return result.size() == length() ? this : (result.isEmpty() ? empty() : new Vector<>(result)); }
@Override public Array<T> replaceAll(T currentElement, T newElement) { final Object[] arr = new Object[length()]; boolean changed = false; for (int i = 0; i < length(); i++) { final T value = get(i); if (currentElement.equals(value)) { arr[i] = newElement; changed = true; } else { arr[i] = get(i); } } return changed ? wrap(arr) : this; }
@Override public Vector<T> replaceAll(T currentElement, T newElement) { HashArrayMappedTrie<Integer, T> trie = HashArrayMappedTrie.empty(); boolean changed = false; for (int i = 0; i < length(); i++) { final T value = get(i); if (currentElement.equals(value)) { trie = trie.put(trie.size(), newElement); changed = true; } else { trie = trie.put(trie.size(), value); } } return changed ? (trie.isEmpty() ? empty() : new Vector<>(trie)) : this; }
@Override public Array<T> remove(T element) { int index = -1; for (int i = 0; i < length(); i++) { final T value = get(i); if (element.equals(value)) { index = i; break; } } if (index < 0) { return this; } else { return removeAt(index); } }
@Override public Vector<T> remove(T element) { HashArrayMappedTrie<Integer, T> trie = HashArrayMappedTrie.empty(); boolean found = false; for (int i = 0; i < length(); i++) { final T value = get(i); if (found) { trie = trie.put(trie.size(), value); } else { if (element.equals(value)) { found = true; } else { trie = trie.put(trie.size(), value); } } } return trie.size() == length() ? this : trie.isEmpty() ? empty() : new Vector<>(trie); }
@Override public int hashCode() { return value.hashCode(); }