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.
/*
* Copyright (c) 2016 Goldman Sachs.
* 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.impl.bag.immutable;
import java.io.Serializable;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Optional;
import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.bag.ImmutableBag;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.predicate.primitive.IntPredicate;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.multimap.MutableMultimap;
import org.eclipse.collections.api.multimap.bag.ImmutableBagMultimap;
import org.eclipse.collections.api.ordered.OrderedIterable;
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.bag.mutable.HashBag;
import org.eclipse.collections.impl.block.factory.Comparators;
import org.eclipse.collections.impl.block.factory.Predicates;
import org.eclipse.collections.impl.block.procedure.MultimapEachPutProcedure;
import org.eclipse.collections.impl.factory.Bags;
import org.eclipse.collections.impl.factory.Sets;
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
import org.eclipse.collections.impl.multimap.bag.HashBagMultimap;
import org.eclipse.collections.impl.tuple.Tuples;
import org.eclipse.collections.impl.utility.ArrayIterate;
import org.eclipse.collections.impl.utility.Iterate;
/**
* @since 1.0
*/
final class ImmutableSingletonBag
extends AbstractImmutableBag implements Serializable
{
private static final long serialVersionUID = 1L;
private final T value;
ImmutableSingletonBag(T object)
{
this.value = object;
}
@Override
public boolean allSatisfy(Predicate super T> predicate)
{
return predicate.accept(this.value);
}
@Override
public boolean noneSatisfy(Predicate super T> predicate)
{
return !predicate.accept(this.value);
}
@Override
public IV injectInto(IV injectedValue, Function2 super IV, ? super T, ? extends IV> function)
{
return function.value(injectedValue, this.value);
}
@Override
public T min(Comparator super T> comparator)
{
return this.value;
}
@Override
public T max(Comparator super T> comparator)
{
return this.value;
}
@Override
public T min()
{
return this.value;
}
@Override
public T max()
{
return this.value;
}
@Override
public > T minBy(Function super T, ? extends V> function)
{
return this.value;
}
@Override
public > T maxBy(Function super T, ? extends V> function)
{
return this.value;
}
@Override
public ImmutableBag newWith(T element)
{
return Bags.immutable.with(this.value, element);
}
@Override
public ImmutableBag newWithout(T element)
{
return this.emptyIfMatchesOrThis(Predicates.equal(element));
}
private ImmutableBag emptyIfMatchesOrThis(Predicate