Skip to content

Commit

Permalink
Use MutableArrayList as default stack impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Oct 22, 2023
1 parent fe94557 commit aa1aa2c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ allprojects {

dependencies {
compileOnlyApi("org.jetbrains:annotations:24.0.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
}

var multiRelease = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.stream.Stream;

@SuppressWarnings("unchecked")
public final class MutableArrayList<E> extends AbstractMutableList<E> implements IndexedSeq<E>, Serializable {
public final class MutableArrayList<E> extends AbstractMutableList<E> implements MutableStack<E>, IndexedSeq<E>, Serializable {
private static final long serialVersionUID = 2545219250020890853L;

private static final MutableArrayList.Factory<?> FACTORY = new Factory<>();
Expand Down Expand Up @@ -652,6 +652,25 @@ public int copyToArray(int srcPos, Object @NotNull [] dest, int destPos, int lim
return size == 0 ? ImmutableArray.empty() : (ImmutableArray<E>) ImmutableArray.Unsafe.wrap(Arrays.copyOf(elements, size));
}

//region Stack

@Override
public void push(E value) {
this.append(value);
}

@Override
public E pop() {
return removeLast();
}

@Override
public E peek() {
return getLast();
}

//endregion

//region Serialization

private void writeObject(ObjectOutputStream out) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ public interface MutableStack<E> extends MutableCollection<E> {

@Contract("-> new")
static <E> @NotNull MutableStack<E> create() {
return new MutableSinglyLinkedList<>();
return MutableArrayList.create();
}

// boolean isEmpty();

@Contract(mutates = "this")
void push(E value);

@Contract(mutates = "this")
E pop();

E peek();

boolean isEmpty();
}

0 comments on commit aa1aa2c

Please sign in to comment.