This is an automated email from the ASF dual-hosted git repository. av pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push: new b129faddb1d IGNITE-20143 GridIntList & GridLongList initial cleanup (#10874) b129faddb1d is described below commit b129faddb1dcf5d8fdc09d3e8787688e9a0e6fff Author: Anton Vinogradov <a...@apache.org> AuthorDate: Fri Aug 4 14:54:32 2023 +0300 IGNITE-20143 GridIntList & GridLongList initial cleanup (#10874) --- .../apache/ignite/internal/util/GridIntList.java | 188 +-------------------- .../apache/ignite/internal/util/GridLongList.java | 141 +--------------- 2 files changed, 5 insertions(+), 324 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java index 724529e797e..e212346de49 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java @@ -17,21 +17,17 @@ package org.apache.ignite.internal.util; -import java.io.DataInput; -import java.io.DataOutput; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.nio.ByteBuffer; import java.util.Arrays; -import java.util.NoSuchElementException; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.SB; import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.plugin.extensions.communication.MessageReader; import org.apache.ignite.plugin.extensions.communication.MessageWriter; -import org.jetbrains.annotations.Nullable; /** * Minimal list API to work with primitive ints. This list exists @@ -91,16 +87,6 @@ public class GridIntList implements Message, Externalizable { idx = size; } - /** - * @return Copy of this list. - */ - public GridIntList copy() { - if (idx == 0) - return new GridIntList(); - - return new GridIntList(Arrays.copyOf(arr, idx)); - } - /** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) @@ -137,30 +123,6 @@ public class GridIntList implements Message, Externalizable { return res; } - /** - * @param l List to add all elements of. - */ - public void addAll(GridIntList l) { - assert l != null; - - if (l.isEmpty()) - return; - - if (arr == null) - arr = new int[4]; - - int len = arr.length; - - while (len < idx + l.size()) - len <<= 1; - - arr = Arrays.copyOf(arr, len); - - System.arraycopy(l.arr, 0, arr, idx, l.size()); - - idx += l.size(); - } - /** * Add element to this array. * @param x Value. @@ -174,35 +136,6 @@ public class GridIntList implements Message, Externalizable { arr[idx++] = x; } - /** - * Clears the list. - */ - public void clear() { - idx = 0; - } - - /** - * Gets the last element. - * - * @return The last element. - */ - public int last() { - return arr[idx - 1]; - } - - /** - * Removes and returns the last element of the list. Complementary method to {@link #add(int)} for stack like usage. - * - * @return Removed element. - * @throws NoSuchElementException If the list is empty. - */ - public int remove() throws NoSuchElementException { - if (idx == 0) - throw new NoSuchElementException(); - - return arr[--idx]; - } - /** * Returns (possibly reordered) copy of this list, excluding all elements of given list. * @@ -278,33 +211,6 @@ public class GridIntList implements Message, Externalizable { return false; } - /** - * @param l List to check. - * @return {@code True} if this list contains all the elements of passed in list. - */ - public boolean containsAll(GridIntList l) { - for (int i = 0; i < l.size(); i++) { - if (!contains(l.get(i))) - return false; - } - - return true; - } - - /** - * @return {@code True} if there are no duplicates. - */ - public boolean distinct() { - for (int i = 0; i < idx; i++) { - for (int j = i + 1; j < idx; j++) { - if (arr[i] == arr[j]) - return false; - } - } - - return true; - } - /** * @param size New size. * @param last If {@code true} the last elements will be removed, otherwise the first. @@ -315,7 +221,7 @@ public class GridIntList implements Message, Externalizable { if (size == idx) return; - if (!last && idx != 0 && size != 0) + if (!last && size != 0) System.arraycopy(arr, idx - size, arr, 0, size); idx = size; @@ -364,26 +270,6 @@ public class GridIntList implements Message, Externalizable { return -1; } - /** - * Removes value from this list. - * - * @param startIdx Index to begin search with. - * @param oldVal Old value. - * @param newVal New value. - * @return Index of replaced value if the value was found and replaced or {@code -1} otherwise. - */ - public int replaceValue(int startIdx, int oldVal, int newVal) { - for (int i = startIdx; i < idx; i++) { - if (arr[i] == oldVal) { - arr[i] = newVal; - - return i; - } - } - - return -1; - } - /** * @return Array copy. */ @@ -404,7 +290,7 @@ public class GridIntList implements Message, Externalizable { } /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + @Override public void readExternal(ObjectInput in) throws IOException { idx = in.readInt(); arr = new int[idx]; @@ -429,59 +315,6 @@ public class GridIntList implements Message, Externalizable { return b.toString(); } - /** - * @param in Input to read list from. - * @return Grid int list. - * @throws IOException If failed. - */ - @Nullable public static GridIntList readFrom(DataInput in) throws IOException { - int idx = in.readInt(); - - if (idx == -1) - return null; - - int[] arr = new int[idx]; - - for (int i = 0; i < idx; i++) - arr[i] = in.readInt(); - - return new GridIntList(arr); - } - - /** - * @param out Output to write to. - * @param list List. - * @throws IOException If failed. - */ - public static void writeTo(DataOutput out, @Nullable GridIntList list) throws IOException { - out.writeInt(list != null ? list.idx : -1); - - if (list != null) { - for (int i = 0; i < list.idx; i++) - out.writeInt(list.arr[i]); - } - } - - /** - * @param to To list. - * @param from From list. - * @return To list (passed in or created). - */ - public static GridIntList addAll(@Nullable GridIntList to, GridIntList from) { - if (to == null) { - GridIntList res = new GridIntList(from.size()); - - res.addAll(from); - - return res; - } - else { - to.addAll(from); - - return to; - } - } - /** * Sorts this list. * Use {@code copy().sort()} if you need a defensive copy. @@ -495,21 +328,6 @@ public class GridIntList implements Message, Externalizable { return this; } - /** - * Removes given number of elements from the end. If the given number of elements is higher than - * list size, then list will be cleared. - * - * @param cnt Count to pop from the end. - */ - public void pop(int cnt) { - assert cnt >= 0 : cnt; - - if (idx < cnt) - idx = 0; - else - idx -= cnt; - } - /** {@inheritDoc} */ @Override public void onAckReceived() { // No-op. @@ -588,7 +406,7 @@ public class GridIntList implements Message, Externalizable { */ public GridIntIterator iterator() { return new GridIntIterator() { - int c = 0; + int c; @Override public boolean hasNext() { return c < idx; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridLongList.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridLongList.java index a9b9ae8a570..4b46a0997d7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridLongList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridLongList.java @@ -17,8 +17,6 @@ package org.apache.ignite.internal.util; -import java.io.DataInput; -import java.io.DataOutput; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; @@ -33,7 +31,6 @@ import org.apache.ignite.internal.util.typedef.internal.SB; import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.plugin.extensions.communication.MessageReader; import org.apache.ignite.plugin.extensions.communication.MessageWriter; -import org.jetbrains.annotations.Nullable; /** * Minimal list API to work with primitive longs. This list exists @@ -97,16 +94,6 @@ public class GridLongList implements Message, Externalizable { idx = size; } - /** - * @return Copy of this list. - */ - public GridLongList copy() { - if (idx == 0) - return new GridLongList(); - - return new GridLongList(Arrays.copyOf(arr, idx)); - } - /** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) @@ -188,15 +175,6 @@ public class GridLongList implements Message, Externalizable { idx = 0; } - /** - * Gets the last element. - * - * @return The last element. - */ - public long last() { - return arr[idx - 1]; - } - /** * Removes and returns the last element of the list. Complementary method to {@link #add(long)} for stack like usage. * @@ -285,33 +263,6 @@ public class GridLongList implements Message, Externalizable { return false; } - /** - * @param l List to check. - * @return {@code True} if this list contains all the elements of passed in list. - */ - public boolean containsAll(GridLongList l) { - for (int i = 0; i < l.size(); i++) { - if (!contains(l.get(i))) - return false; - } - - return true; - } - - /** - * @return {@code True} if there are no duplicates. - */ - public boolean distinct() { - for (int i = 0; i < idx; i++) { - for (int j = i + 1; j < idx; j++) { - if (arr[i] == arr[j]) - return false; - } - } - - return true; - } - /** * @param size New size. * @param last If {@code true} the last elements will be removed, otherwise the first. @@ -322,7 +273,7 @@ public class GridLongList implements Message, Externalizable { if (size == idx) return; - if (!last && idx != 0 && size != 0) + if (!last && size != 0) System.arraycopy(arr, idx - size, arr, 0, size); idx = size; @@ -371,26 +322,6 @@ public class GridLongList implements Message, Externalizable { return -1; } - /** - * Removes value from this list. - * - * @param startIdx Index to begin search with. - * @param oldVal Old value. - * @param newVal New value. - * @return Index of replaced value if the value was found and replaced or {@code -1} otherwise. - */ - public int replaceValue(int startIdx, long oldVal, long newVal) { - for (int i = startIdx; i < idx; i++) { - if (arr[i] == oldVal) { - arr[i] = newVal; - - return i; - } - } - - return -1; - } - /** * @return Array copy. */ @@ -414,7 +345,7 @@ public class GridLongList implements Message, Externalizable { } /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + @Override public void readExternal(ObjectInput in) throws IOException { idx = in.readInt(); arr = new long[idx]; @@ -439,59 +370,6 @@ public class GridLongList implements Message, Externalizable { return S.toString(GridLongList.class, this, "arr", b); } - /** - * @param in Input to read list from. - * @return Grid long list. - * @throws IOException If failed. - */ - @Nullable public static GridLongList readFrom(DataInput in) throws IOException { - int idx = in.readInt(); - - if (idx == -1) - return null; - - long[] arr = new long[idx]; - - for (int i = 0; i < idx; i++) - arr[i] = in.readLong(); - - return new GridLongList(arr); - } - - /** - * @param out Output to write to. - * @param list List. - * @throws IOException If failed. - */ - public static void writeTo(DataOutput out, @Nullable GridLongList list) throws IOException { - out.writeInt(list != null ? list.idx : -1); - - if (list != null) { - for (int i = 0; i < list.idx; i++) - out.writeLong(list.arr[i]); - } - } - - /** - * @param to To list. - * @param from From list. - * @return To list (passed in or created). - */ - public static GridLongList addAll(@Nullable GridLongList to, GridLongList from) { - if (to == null) { - GridLongList res = new GridLongList(from.size()); - - res.addAll(from); - - return res; - } - else { - to.addAll(from); - - return to; - } - } - /** * Sorts this list. * Use {@code copy().sort()} if you need a defensive copy. @@ -505,21 +383,6 @@ public class GridLongList implements Message, Externalizable { return this; } - /** - * Removes given number of elements from the end. If the given number of elements is higher than - * list size, then list will be cleared. - * - * @param cnt Count to pop from the end. - */ - public void pop(int cnt) { - assert cnt >= 0 : cnt; - - if (idx < cnt) - idx = 0; - else - idx -= cnt; - } - /** {@inheritDoc} */ @Override public void onAckReceived() { // No-op.