/*
* Copyright (c) 2021 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.api.list.primitive;
import java.util.Comparator;
import java.util.Random;
import org.eclipse.collections.api.block.comparator.primitive.DoubleComparator;
import org.eclipse.collections.api.DoubleIterable;
import org.eclipse.collections.api.block.function.primitive.DoubleIntToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleToObjectFunction;
import org.eclipse.collections.api.block.predicate.primitive.DoublePredicate;
import org.eclipse.collections.api.block.procedure.primitive.DoubleProcedure;
import org.eclipse.collections.api.collection.primitive.MutableDoubleCollection;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.tuple.primitive.DoubleDoublePair;
import org.eclipse.collections.api.tuple.primitive.DoubleObjectPair;
This file was automatically generated from template file mutablePrimitiveList.stg.
Since: 3.0.
/**
* This file was automatically generated from template file mutablePrimitiveList.stg.
*
* @since 3.0.
*/
public interface MutableDoubleList extends MutableDoubleCollection, DoubleList
{
void addAtIndex(int index, double element);
boolean addAllAtIndex(int index, double... source);
boolean addAllAtIndex(int index, DoubleIterable source);
double removeAtIndex(int index);
double set(int index, double element);
default void swap(int index1, int index2)
{
double value = this.get(index1);
this.set(index1, this.get(index2));
this.set(index2, value);
}
@Override
MutableDoubleList select(DoublePredicate predicate);
@Override
MutableDoubleList reject(DoublePredicate predicate);
@Override
MutableDoubleList with(double element);
@Override
MutableDoubleList without(double element);
@Override
MutableDoubleList withAll(DoubleIterable elements);
@Override
MutableDoubleList withoutAll(DoubleIterable elements);
Since: 9.0.
/**
* @since 9.0.
*/
@Override
default MutableDoubleList tap(DoubleProcedure procedure)
{
this.forEach(procedure);
return this;
}
<V> MutableList<V> collect(DoubleToObjectFunction<? extends V> function);
Returns a new MutableList using results obtained by applying the specified function to each element
and its corresponding index.
Since: 9.1.
/**
* Returns a new MutableList using results obtained by applying the specified function to each element
* and its corresponding index.
*
* @since 9.1.
*/
@Override
default <V> MutableList<V> collectWithIndex(DoubleIntToObjectFunction<? extends V> function)
{
int[] index = {0};
return this.collect(each -> function.value(each, index[0]++));
}
MutableDoubleList reverseThis();
@Override
MutableDoubleList toReversed();
Since: 6.0.
/**
* @since 6.0.
*/
@Override
MutableDoubleList distinct();
Sorts this list mutating its contents and returns the same mutable list (this).
/**
* Sorts this list mutating its contents and returns the same mutable list (this).
*/
MutableDoubleList sortThis();
Sorts the internal data structure of this list and returns the list itself as a convenience.
/**
* Sorts the internal data structure of this list and returns the list itself as a convenience.
*/
default MutableDoubleList sortThis(DoubleComparator comparator)
{
throw new UnsupportedOperationException("sortThis(DoubleComparator comparator) is not supported on " + this.getClass());
}
Sorts the internal data structure of this list based on the natural order of the key returned by
function
. /**
* Sorts the internal data structure of this list based on the natural order of the key returned by {@code
* function}.
*/
default <T> MutableDoubleList sortThisBy(DoubleToObjectFunction<T> function)
{
return sortThisBy(function, (Comparator<? super T>) Comparator.naturalOrder());
}
Sorts the internal data structure of this list based on the key returned by
function
using the provided comparator
. /**
* Sorts the internal data structure of this list based on the key returned by {@code
* function} using the provided {@code comparator}.
*/
default <T> MutableDoubleList sortThisBy(DoubleToObjectFunction<T> function, Comparator<? super T> comparator)
{
return this.sortThis((i1, i2) -> comparator.compare(function.valueOf(i1), function.valueOf(i2)));
}
Randomly permutes this list mutating its contents and returns the same list (this). Uses java.util.Random
as the source of randomness. /**
* Randomly permutes this list mutating its contents and returns the same list (this).
*
* Uses {@code java.util.Random} as the source of randomness.
*/
default MutableDoubleList shuffleThis()
{
return this.shuffleThis(new Random());
}
Randomly permutes this list mutating its contents and returns the same list (this).
Implements the Fisher-Yates shuffle algorithm using the provided source of randomness.
/**
* Randomly permutes this list mutating its contents and returns the same list (this).
*
* Implements the Fisher-Yates shuffle algorithm using the provided source of randomness.
*/
default MutableDoubleList shuffleThis(Random rnd)
{
for (int j = this.size() - 1; j > 0; j--)
{
int k = rnd.nextInt(j + 1);
double selected = this.get(j);
this.set(j, this.get(k));
this.set(k, selected);
}
return this;
}
@Override
MutableDoubleList asUnmodifiable();
@Override
MutableDoubleList asSynchronized();
Returns an immutable copy of this list.
/**
* Returns an immutable copy of this list.
*/
@Override
ImmutableDoubleList toImmutable();
@Override
MutableDoubleList subList(int fromIndex, int toIndex);
Returns a MutableList
formed from this MutableDoubleList
and another DoubleList
by combining corresponding elements in pairs. If one of the two DoubleList
s is longer than the other, its remaining elements are ignored. Since: 9.1.
/**
* Returns a {@code MutableList} formed from this {@code MutableDoubleList} and another {@code DoubleList} by
* combining corresponding elements in pairs. If one of the two {@code DoubleList}s is longer than the other, its
* remaining elements are ignored.
*
* @since 9.1.
*/
default MutableList<DoubleDoublePair> zipDouble(DoubleIterable iterable)
{
throw new UnsupportedOperationException("Default method to prevent breaking backwards compatibility");
}
Returns a MutableList
formed from this MutableDoubleList
and a ListIterable
by combining corresponding elements in pairs. If one of the two Lists is longer than the other, its remaining elements are ignored. Since: 9.1.
/**
* Returns a {@code MutableList} formed from this {@code MutableDoubleList} and a {@code ListIterable} by
* combining corresponding elements in pairs. If one of the two Lists is longer than the other, its
* remaining elements are ignored.
*
* @since 9.1.
*/
default <T> MutableList<DoubleObjectPair<T>> zip(Iterable<T> list)
{
throw new UnsupportedOperationException("Default method to prevent breaking backwards compatibility");
}
Creates a new empty mutable version of the same List type.
Since: 9.2.
/**
* Creates a new empty mutable version of the same List type.
*
* @since 9.2.
*/
default MutableDoubleList newEmpty()
{
throw new UnsupportedOperationException("Implement in concrete classes.");
}
}