Skip to content

Commit

Permalink
Merge branch '#400_immutable_linkedlist' of github.com:parsingdata/me…
Browse files Browse the repository at this point in the history
…tal into #400_immutable_linkedlist
  • Loading branch information
mvanaken committed Feb 6, 2024
2 parents db25eee + aecffb6 commit 8750fc3
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions core/src/main/java/io/parsingdata/metal/data/ImmutableList.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.parsingdata.metal.data;

import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.toList;

import static io.parsingdata.metal.Util.checkNotNull;

Expand All @@ -27,12 +28,12 @@
import java.util.List;
import java.util.ListIterator;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.parsingdata.metal.ImmutableObject;
import io.parsingdata.metal.Util;


public class ImmutableList<T> extends ImmutableObject implements List<T> {

private final List<T> innerList;
Expand All @@ -50,7 +51,7 @@ public static <T> ImmutableList<T> create(final T head) {
}

public static <T> ImmutableList<T> create(final T[] array) {
return new ImmutableList<>(new LinkedList<>(Arrays.stream(array).collect(Collectors.toList())));
return new ImmutableList<>(Arrays.stream(array).collect(toList()));
}

public ImmutableList<T> addHead(final T head) {
Expand Down Expand Up @@ -96,21 +97,6 @@ public T get(int index) {
return innerList.get(index);
}

@Override
public T set(int index, T element) {
throw new UnsupportedOperationException();
}

@Override
public void add(int index, T element) {
throw new UnsupportedOperationException();
}

@Override
public T remove(int index) {
throw new UnsupportedOperationException();
}

@Override
public int indexOf(Object o) {
return innerList.indexOf(o);
Expand Down Expand Up @@ -164,23 +150,38 @@ public Object[] toArray() {
}

@Override
public <T1> T1[] toArray(T1[] a) {
public <T> T[] toArray(T[] a) {
return innerList.toArray(a);
}

@Override
public boolean add(T t) {
public boolean containsAll(Collection<?> c) {
return innerList.containsAll(c);
}

@Override
public T set(int index, T element) {
throw new UnsupportedOperationException();
}

@Override
public boolean remove(Object o) {
public void add(int index, T element) {
throw new UnsupportedOperationException();
}

@Override
public boolean containsAll(Collection<?> c) {
return innerList.containsAll(c);
public T remove(int index) {
throw new UnsupportedOperationException();
}

@Override
public boolean add(T t) {
throw new UnsupportedOperationException();
}

@Override
public boolean remove(Object o) {
throw new UnsupportedOperationException();
}

@Override
Expand Down

0 comments on commit 8750fc3

Please sign in to comment.