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

org.solovyev.common.collections.multiset.SynchronizedMultiSet Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2013 serso aka se.solovyev
 *
 * 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.
 *
 * ---------------------------------------------------------------------
 * Contact details
 *
 * Email: [email protected]
 * Site:  http://se.solovyev.org
 */

package org.solovyev.common.collections.multiset;

import org.solovyev.common.SynchronizedObject;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;

public class SynchronizedMultiSet extends SynchronizedObject> implements MultiSet {

	/*
	**********************************************************************
	*
	*                           CONSTRUCTORS
	*
	**********************************************************************
	*/

	protected SynchronizedMultiSet(@Nonnull MultiSet delegate) {
		super(delegate);
	}

	protected SynchronizedMultiSet(@Nonnull MultiSet delegate, @Nonnull Object mutex) {
		super(delegate, mutex);
	}

	@Nonnull
	public static  SynchronizedMultiSet wrap(@Nonnull MultiSet delegate) {
		return new SynchronizedMultiSet(delegate);
	}

	@Nonnull
	public static  SynchronizedMultiSet wrap(@Nonnull MultiSet delegate, @Nonnull Object mutex) {
		return new SynchronizedMultiSet(delegate, mutex);
	}

	/*
	**********************************************************************
	*
	*                           METHODS
	*
	**********************************************************************
	*/

	@Override
	public int count(E e) {
		synchronized (mutex) {
			return delegate.count(e);
		}
	}

	@Nonnull
	@Override
	public Collection getAll(E e) {
		synchronized (mutex) {
			return delegate.getAll(e);
		}
	}

	@Nonnull
	@Override
	public Set toElementSet() {
		synchronized (mutex) {
			return delegate.toElementSet();
		}
	}

	@Override
	public boolean add(E e, int count) {
		synchronized (mutex) {
			return delegate.add(e, count);
		}
	}

	@Override
	public int remove(E e, int count) {
		synchronized (mutex) {
			return delegate.remove(e, count);
		}
	}

	@Override
	public int size() {
		synchronized (mutex) {
			return delegate.size();
		}
	}

	@Override
	public boolean isEmpty() {
		synchronized (mutex) {
			return delegate.isEmpty();
		}
	}

	@Override
	public boolean contains(Object o) {
		synchronized (mutex) {
			return delegate.contains(o);
		}
	}

	// must be manually synchronized (or may be NotSupportedOperationException should be thrown)
	@Nonnull
	@Override
	public Iterator iterator() {
		synchronized (mutex) {
			return delegate.iterator();
		}
	}

	@Nonnull
	@Override
	public Object[] toArray() {
		synchronized (mutex) {
			return delegate.toArray();
		}
	}

	@Nonnull
	@Override
	public  T[] toArray(@Nonnull T[] a) {
		synchronized (mutex) {
			return delegate.toArray(a);
		}
	}

	@Override
	public boolean add(E e) {
		synchronized (mutex) {
			return delegate.add(e);
		}
	}

	@Override
	public boolean remove(Object o) {
		synchronized (mutex) {
			return delegate.remove(o);
		}
	}

	@Override
	public boolean containsAll(@Nonnull Collection c) {
		synchronized (mutex) {
			return delegate.containsAll(c);
		}
	}

	@Override
	public boolean addAll(@Nonnull Collection c) {
		synchronized (mutex) {
			return delegate.addAll(c);
		}
	}

	@Override
	public boolean removeAll(@Nonnull Collection c) {
		synchronized (mutex) {
			return delegate.removeAll(c);
		}
	}

	@Override
	public boolean retainAll(@Nonnull Collection c) {
		synchronized (mutex) {
			return delegate.retainAll(c);
		}
	}

	@Override
	public void clear() {
		synchronized (mutex) {
			delegate.clear();
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy