com.bestvike.collections.generic.Array Maven / Gradle / Ivy
package com.bestvike.collections.generic;
import com.bestvike.function.Predicate1;
import com.bestvike.linq.IEnumerator;
import com.bestvike.linq.adapter.enumerator.ArrayEnumerator;
import com.bestvike.linq.exception.ExceptionArgument;
import com.bestvike.linq.exception.ThrowHelper;
import com.bestvike.linq.util.ArrayUtils;
import java.util.Collection;
import java.util.List;
/**
* Created by 许崇雷 on 2017-07-19.
*/
public final class Array implements IArray, Cloneable {
private static final Array> EMPTY = new Array<>(ArrayUtils.empty());
private final Object[] elements;
public Array(Object[] elements) {
if (elements == null)
ThrowHelper.throwArgumentNullException(ExceptionArgument.elements);
this.elements = elements;
}
public static Array empty() {
//noinspection unchecked
return (Array) EMPTY;
}
@Override
public IEnumerator enumerator() {
return new ArrayEnumerator<>(this.elements);
}
@Override
public Object[] getArray() {
return this.elements;
}
@Override
public T get(int index) {
//noinspection unchecked
return (T) this.elements[index];
}
@Override
public int _indexOf(T item) {
return ArrayUtils.indexOf(this.elements, item);
}
@Override
public int _lastIndexOf(T item) {
return ArrayUtils.lastIndexOf(this.elements, item);
}
@Override
public int _findIndex(Predicate1 match) {
//noinspection unchecked
return ArrayUtils.findIndex(this.elements, (Predicate1