All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gs.collections.impl.set.fixed.AbstractMemoryEfficientMutableSet Maven / Gradle / Ivy

Go to download

GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework.

There is a newer version: 7.0.3
Show newest version
/*
 * Copyright 2015 Goldman Sachs.
 *
 * 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 com.gs.collections.impl.set.fixed;

import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.ExecutorService;

import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.set.FixedSizeSet;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.api.set.ParallelUnsortedSetIterable;
import com.gs.collections.impl.factory.Sets;
import com.gs.collections.impl.set.mutable.AbstractMutableSet;
import com.gs.collections.impl.utility.Iterate;

abstract class AbstractMemoryEfficientMutableSet
        extends AbstractMutableSet
        implements FixedSizeSet
{
    protected int nullSafeHashCode(Object element)
    {
        return element == null ? 0 : element.hashCode();
    }

    @Override
    public boolean addAll(Collection collection)
    {
        throw new UnsupportedOperationException("Cannot add to a fixed size set: " + this.getClass());
    }

    @Override
    public boolean addAllIterable(Iterable iterable)
    {
        throw new UnsupportedOperationException("Cannot add to a fixed size set: " + this.getClass());
    }

    @Override
    public boolean retainAll(Collection collection)
    {
        throw new UnsupportedOperationException("Cannot remove from a fixed size set: " + this.getClass());
    }

    @Override
    public boolean retainAllIterable(Iterable iterable)
    {
        throw new UnsupportedOperationException("Cannot remove from a fixed size set: " + this.getClass());
    }

    @Override
    public boolean remove(Object o)
    {
        throw new UnsupportedOperationException("Cannot remove from a fixed size set: " + this.getClass());
    }

    @Override
    public boolean removeAll(Collection collection)
    {
        throw new UnsupportedOperationException("Cannot remove from a fixed size set: " + this.getClass());
    }

    @Override
    public boolean removeAllIterable(Iterable iterable)
    {
        throw new UnsupportedOperationException("Cannot remove from a fixed size set: " + this.getClass());
    }

    @Override
    public boolean removeIf(Predicate predicate)
    {
        throw new UnsupportedOperationException("Cannot remove from a fixed size set: " + this.getClass());
    }

    @Override
    public 

boolean removeIfWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException("Cannot removeIfWith from a fixed size set: " + this.getClass()); } public void clear() { throw new UnsupportedOperationException("Cannot clear a fixed size set: " + this.getClass()); } public MutableSet withAll(Iterable elements) { if (Iterate.isEmpty(elements)) { return this; } return Sets.fixedSize.ofAll(this.toList().withAll(elements)); } public MutableSet withoutAll(Iterable elements) { if (Iterate.isEmpty(elements)) { return this; } return Sets.fixedSize.ofAll(this.toList().withoutAll(elements)); } protected abstract class MemoryEfficientSetIterator implements Iterator { private int next; // next entry to return, defaults to 0 protected abstract T getElement(int i); public boolean hasNext() { return this.next < AbstractMemoryEfficientMutableSet.this.size(); } public T next() { return this.getElement(this.next++); } public void remove() { throw new UnsupportedOperationException("Cannot remove from a fixed size set: " + this.getClass()); } } public ParallelUnsortedSetIterable asParallel(ExecutorService executorService, int batchSize) { return this.toSet().asParallel(executorService, batchSize); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy