it.unimi.dsi.fastutil.objects.ReferenceCollection Maven / Gradle / Ivy
Show all versions of fastutil Show documentation
/*
* Copyright (C) 2002-2022 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 static it.unimi.dsi.fastutil.Size64.sizeOf;
/**
* A type-specific {@link Collection}; provides some additional methods that use polymorphism to
* avoid (un)boxing.
*
*
* Additionally, this class defines strengthens (again) {@link #iterator()}.
*
* @see Collection
*/
public interface ReferenceCollection extends Collection, ObjectIterable {
/**
* Returns a type-specific iterator on the elements of this collection.
*
* @apiNote This specification strengthens the one given in {@link java.lang.Iterable#iterator()},
* which was already strengthened in the corresponding type-specific class, but was
* weakened by the fact that this interface extends {@link Collection}.
*
* @return a type-specific iterator on the elements of this collection.
*/
@Override
ObjectIterator iterator();
// If you change these default spliterator methods, you will likely need to update Iterable, List,
// Set, and SortedSet too
/**
* Returns a type-specific spliterator on the elements of this collection.
*
*
* See {@link java.util.Collection#spliterator()} for more documentation on the requirements of the
* returned spliterator.
*
* @apiNote This specification strengthens the one given in
* {@link java.util.Collection#spliterator()}.
*
* Also, this is generally the only {@code spliterator} method subclasses should override.
*
* @implSpec The default implementation returns a late-binding spliterator (see
* {@link java.util.Spliterator Spliterator} for documentation on what binding policies
* mean) that wraps this instance's type specific {@link #iterator}.
*
* Additionally, it reports {@link java.util.Spliterator#SIZED Spliterator.SIZED}
*
* @implNote As this default implementation wraps the iterator, and {@link java.util.Iterator} is an
* inherently linear API, the returned spliterator will yield limited performance gains
* when run in parallel contexts, as the returned spliterator's
* {@link java.util.Spliterator#trySplit() trySplit()} will have linear runtime.
*
* @return a type-specific spliterator on the elements of this collection.
* @since 8.5.0
*/
@Override
default ObjectSpliterator spliterator() {
return ObjectSpliterators.asSpliterator(iterator(), sizeOf(this), ObjectSpliterators.COLLECTION_SPLITERATOR_CHARACTERISTICS);
}
}