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

com.gs.collections.impl.list.mutable.primitive.SynchronizedBooleanList Maven / Gradle / Ivy

/*
 * Copyright 2014 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.list.mutable.primitive;

import java.util.Collection;
import java.util.Collections;

import com.gs.collections.api.BooleanIterable;
import com.gs.collections.api.LazyBooleanIterable;
import com.gs.collections.api.block.function.primitive.BooleanToObjectFunction;
import com.gs.collections.api.block.function.primitive.ObjectBooleanToObjectFunction;
import com.gs.collections.api.block.function.primitive.ObjectBooleanIntToObjectFunction;
import com.gs.collections.api.block.predicate.primitive.BooleanPredicate;
import com.gs.collections.api.block.procedure.primitive.BooleanIntProcedure;
import com.gs.collections.api.iterator.BooleanIterator;
import com.gs.collections.api.list.MutableList;
import com.gs.collections.api.list.primitive.BooleanList;
import com.gs.collections.api.list.primitive.ImmutableBooleanList;
import com.gs.collections.api.list.primitive.MutableBooleanList;
import com.gs.collections.impl.collection.mutable.primitive.AbstractSynchronizedBooleanCollection;
import com.gs.collections.impl.factory.primitive.BooleanLists;
import com.gs.collections.impl.lazy.primitive.LazyBooleanIterableAdapter;
import com.gs.collections.impl.lazy.primitive.ReverseBooleanIterable;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;

/**
 * A synchronized view of a {@link MutableBooleanList}. It is imperative that the user manually synchronize on the collection when iterating over it using the
 * {@link BooleanIterator}, as per {@link Collections#synchronizedCollection(Collection)}.
 * 

* This file was automatically generated from template file synchronizedPrimitiveList.stg. *

* * @see MutableBooleanList#asSynchronized() * @see MutableList#asSynchronized() * @since 3.1. */ @ThreadSafe public final class SynchronizedBooleanList extends AbstractSynchronizedBooleanCollection implements MutableBooleanList { private static final long serialVersionUID = 1L; SynchronizedBooleanList(MutableBooleanList list) { super(list); } SynchronizedBooleanList(MutableBooleanList list, Object newLock) { super(list, newLock); } @GuardedBy("getLock()") private MutableBooleanList getMutableBooleanList() { return (MutableBooleanList) this.getBooleanCollection(); } public boolean get(int index) { synchronized (this.getLock()) { return this.getMutableBooleanList().get(index); } } public boolean getFirst() { synchronized (this.getLock()) { return this.getMutableBooleanList().getFirst(); } } public boolean getLast() { synchronized (this.getLock()) { return this.getMutableBooleanList().getLast(); } } public int indexOf(boolean value) { synchronized (this.getLock()) { return this.getMutableBooleanList().indexOf(value); } } public int lastIndexOf(boolean value) { synchronized (this.getLock()) { return this.getMutableBooleanList().lastIndexOf(value); } } public void addAtIndex(int index, boolean element) { synchronized (this.getLock()) { this.getMutableBooleanList().addAtIndex(index, element); } } public boolean addAllAtIndex(int index, boolean... source) { synchronized (this.getLock()) { return this.getMutableBooleanList().addAllAtIndex(index, source); } } public boolean addAllAtIndex(int index, BooleanIterable source) { synchronized (this.getLock()) { return this.getMutableBooleanList().addAllAtIndex(index, source); } } public boolean removeAtIndex(int index) { synchronized (this.getLock()) { return this.getMutableBooleanList().removeAtIndex(index); } } public boolean set(int index, boolean element) { synchronized (this.getLock()) { return this.getMutableBooleanList().set(index, element); } } @Override public SynchronizedBooleanList with(boolean element) { synchronized (this.getLock()) { this.getMutableBooleanList().add(element); } return this; } @Override public SynchronizedBooleanList without(boolean element) { synchronized (this.getLock()) { this.getMutableBooleanList().remove(element); } return this; } @Override public SynchronizedBooleanList withAll(BooleanIterable elements) { synchronized (this.getLock()) { this.getMutableBooleanList().addAll(elements.toArray()); } return this; } @Override public SynchronizedBooleanList withoutAll(BooleanIterable elements) { synchronized (this.getLock()) { this.getMutableBooleanList().removeAll(elements); } return this; } @Override public MutableBooleanList select(BooleanPredicate predicate) { synchronized (this.getLock()) { return this.getMutableBooleanList().select(predicate); } } @Override public MutableBooleanList reject(BooleanPredicate predicate) { synchronized (this.getLock()) { return this.getMutableBooleanList().reject(predicate); } } @Override public MutableList collect(BooleanToObjectFunction function) { synchronized (this.getLock()) { return this.getMutableBooleanList().collect(function); } } @Override public boolean equals(Object otherList) { synchronized (this.getLock()) { return this.getMutableBooleanList().equals(otherList); } } @Override public int hashCode() { synchronized (this.getLock()) { return this.getMutableBooleanList().hashCode(); } } @Override public LazyBooleanIterable asLazy() { synchronized (this.getLock()) { return new LazyBooleanIterableAdapter(this); } } @Override public MutableBooleanList asUnmodifiable() { return new UnmodifiableBooleanList(this); } @Override public MutableBooleanList asSynchronized() { return this; } @Override public ImmutableBooleanList toImmutable() { int size = this.size(); if (size == 0) { return BooleanLists.immutable.with(); } if (size == 1) { return BooleanLists.immutable.with(this.getFirst()); } return BooleanLists.immutable.with(this.toArray()); } public MutableBooleanList reverseThis() { synchronized (this.getLock()) { this.getMutableBooleanList().reverseThis(); } return this; } public MutableBooleanList toReversed() { synchronized (this.getLock()) { return this.getMutableBooleanList().toReversed(); } } public LazyBooleanIterable asReversed() { return ReverseBooleanIterable.adapt(this); } public void forEachWithIndex(BooleanIntProcedure procedure) { synchronized (this.getLock()) { this.getMutableBooleanList().forEachWithIndex(procedure); } } public T injectInto(T injectedValue, ObjectBooleanToObjectFunction function) { synchronized (this.getLock()) { return this.getMutableBooleanList().injectInto(injectedValue, function); } } public T injectIntoWithIndex(T injectedValue, ObjectBooleanIntToObjectFunction function) { synchronized (this.getLock()) { return this.getMutableBooleanList().injectIntoWithIndex(injectedValue, function); } } public MutableBooleanList subList(int fromIndex, int toIndex) { throw new UnsupportedOperationException("subList not yet implemented!"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy