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

org.mini2Dx.minibus.messagedata.SetMessageData Maven / Gradle / Ivy

There is a newer version: 1.8.1
Show newest version
/**
 * The MIT License (MIT)
 * 
 * Copyright (c) 2016 See AUTHORS file
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.mini2Dx.minibus.messagedata;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.mini2Dx.minibus.MessageData;
import org.mini2Dx.minibus.pool.OptionallyPooledMessageData;
import org.mini2Dx.minibus.pool.MessageDataPool;
import org.mini2Dx.minibus.pool.PooledMessageData;

/**
 * A {@link MessageData} instance that also implements the {@link Set} interface, backed by a
 * {@link Set} instance
 */
public class SetMessageData extends OptionallyPooledMessageData implements Set {
	private final Set set;

	/**
	 * Constructs a non-pooled {@link SetMessageData} instance backed by a {@link HashSet}
	 */
	public SetMessageData() {
		this(new HashSet());
	}

	/**
	 * Constructs a non-pooled {@link SetMessageData} instance
	 * @param set The backing {@link Set} instance
	 */
	public SetMessageData(Set set) {
		super();
		this.set = set;
	}
	
	/**
	 * Constructs a pooled {@link SetMessageData} instance
	 * @param pool The {@link MessageDataPool} managing this instance
	 */
	public SetMessageData(MessageDataPool pool) {
		super(pool);
		this.set = new HashSet();
	}

	@Override
	public int size() {
		return set.size();
	}

	@Override
	public boolean isEmpty() {
		return set.isEmpty();
	}

	@Override
	public boolean contains(Object o) {
		return set.contains(o);
	}

	@Override
	public Iterator iterator() {
		return set.iterator();
	}

	@Override
	public Object[] toArray() {
		return set.toArray();
	}

	@Override
	public  T[] toArray(T[] a) {
		return set.toArray(a);
	}

	@Override
	public boolean add(T e) {
		return set.add(e);
	}

	@Override
	public boolean remove(Object o) {
		return set.remove(o);
	}

	@Override
	public boolean containsAll(Collection c) {
		return set.containsAll(c);
	}

	@Override
	public boolean addAll(Collection c) {
		return set.addAll(c);
	}

	@Override
	public boolean retainAll(Collection c) {
		return set.retainAll(c);
	}

	@Override
	public boolean removeAll(Collection c) {
		return set.removeAll(c);
	}

	@Override
	public void clear() {
		set.clear();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy