Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
fastutil extends the Java Collections Framework by providing type-specific maps, sets, lists, and queues with a small memory footprint and fast access and insertion; it provides also big (64-bit) arrays, sets and lists, sorting algorithms, fast, practical I/O classes for binary and text files, and facilities for memory mapping large files. Note that if you have both this jar and fastutil-core.jar in your dependencies, fastutil-core.jar should be excluded.
/*
* Copyright (C) 2020-2023 Sebastiano Vigna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package it.unimi.dsi.fastutil.objects;
import java.util.Collection;
import java.util.RandomAccess;
import java.util.NoSuchElementException;
import java.lang.reflect.Array;
import java.util.function.Consumer;
import java.util.stream.Collector;
/**
* A type-specific array-based immutable list; provides some additional methods that use
* polymorphism to avoid (un)boxing.
*
*
* Instances of this class are immutable and (contrarily to mutable array-based list
* implementations) the backing array is not exposed. Instances can be built using a variety of
* methods, but note that constructors using an array will not make a defensive copy.
*
*
* This class implements the bulk method {@code getElements()} using high-performance system calls
* (e.g., {@link System#arraycopy(Object,int,Object,int,int) System.arraycopy()}) instead of
* expensive loops.
*/
public class ReferenceImmutableList extends ReferenceLists.ImmutableListBase implements ReferenceList, RandomAccess, Cloneable, java.io.Serializable {
private static final long serialVersionUID = 0L;
@SuppressWarnings({ "unchecked", "rawtypes" })
static final ReferenceImmutableList EMPTY = new ReferenceImmutableList(ObjectArrays.EMPTY_ARRAY);
@SuppressWarnings("unchecked")
private static final K[] emptyArray() {
return (K[])ObjectArrays.EMPTY_ARRAY;
}
/** The backing array; all elements are part of this list. */
private final K a[];
/**
* Creates a new immutable list using a given array.
*
*
* Note that this constructor does not perform a defensive copy.
*
* @param a the array that will be used to back this immutable list.
*/
public ReferenceImmutableList(final K a[]) {
this.a = a;
}
/**
* Creates a new immutable list and fills it with a given collection.
*
* @param c a collection that will be used to fill the immutable list.
*/
public ReferenceImmutableList(final Collection c) {
this(c.isEmpty() ? emptyArray() : ObjectIterators.unwrap(c.iterator()));
}
/**
* Creates a new immutable list and fills it with a given type-specific collection.
*
* @param c a type-specific collection that will be used to fill the immutable list.
*/
public ReferenceImmutableList(final ReferenceCollection c) {
this(c.isEmpty() ? emptyArray() : ObjectIterators.unwrap(c.iterator()));
}
/**
* Creates a new immutable list and fills it with a given type-specific list.
*
* @param l a type-specific list that will be used to fill the immutable list.
*/
@SuppressWarnings("unchecked")
public ReferenceImmutableList(final ReferenceList l) {
this(l.isEmpty() ? emptyArray() : (K[])new Object[l.size()]);
l.getElements(0, a, 0, l.size());
}
/**
* Creates a new immutable list and fills it with the elements of a given array.
*
* @param a an array whose elements will be used to fill the immutable list.
* @param offset the first element to use.
* @param length the number of elements to use.
*/
@SuppressWarnings("unchecked")
public ReferenceImmutableList(final K a[], final int offset, final int length) {
this(length == 0 ? emptyArray() : (K[])new Object[length]);
System.arraycopy(a, offset, this.a, 0, length);
}
/**
* Creates a new immutable list and fills it with the elements returned by a type-specific
* iterator..
*
* @param i a type-specific iterator whose returned elements will fill the immutable list.
*/
public ReferenceImmutableList(final ObjectIterator i) {
this(i.hasNext() ? ObjectIterators.unwrap(i) : emptyArray());
}
/**
* Returns an empty immutable list.
*
* @return an immutable list (possibly shared) that is empty.
*/
@SuppressWarnings("unchecked")
public static ReferenceImmutableList of() {
return EMPTY;
}
/**
* Creates an immutable list using a list of elements.
*
*
* Note that this method does not perform a defensive copy.
*
* @param init a list of elements that will be used to initialize the list.
* @return a new immutable list containing the given elements.
*/
@SafeVarargs
public static ReferenceImmutableList of(final K... init) {
return init.length == 0 ? of() : new ReferenceImmutableList(init);
}
private static ReferenceImmutableList convertTrustedToImmutableList(ReferenceArrayList arrayList) {
if (arrayList.isEmpty()) {
return of();
}
K backingArray[] = arrayList.elements();
if (arrayList.size() != backingArray.length) {
backingArray = java.util.Arrays.copyOf(backingArray, arrayList.size());
}
return new ReferenceImmutableList<>(backingArray);
}
private static final Collector