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

net.vectorpublish.desktop.vp.system.UnmodifiableSingleSet Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2016, Peter Rader. All rights reserved.
 *  ___ ___               __                 ______         __     __  __         __
 * |   |   |.-----..----.|  |_ .-----..----.|   __ \.--.--.|  |--.|  ||__|.-----.|  |--.
 * |   |   ||  -__||  __||   _||  _  ||   _||    __/|  |  ||  _  ||  ||  ||__ --||     |
 *  \_____/ |_____||____||____||_____||__|  |___|   |_____||_____||__||__||_____||__|__|
 *
 * http://www.gnu.org/licenses/gpl-3.0.html
 */
package net.vectorpublish.desktop.vp.system;

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

public final class UnmodifiableSingleSet implements Set {
	private final T obj;

	public UnmodifiableSingleSet(T obj) {
		this.obj = obj;
	}

	@Override
	public int size() {
		return 1;
	}

	@Override
	public boolean isEmpty() {
		return false;
	}

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

	@Override
	public Iterator iterator() {
		return null;
	}

	@Override
	public Object[] toArray() {
		return obA(obj);
	}

	@Override
	public  T[] toArray(T[] a) {
		return (T[]) obA(obj);
	}

	private T[] obA(T... obj2) {
		return obj2;
	}

	@Override
	@Deprecated
	public boolean add(T e) {
		return false;
	}

	@Override
	@Deprecated
	public boolean remove(Object o) {
		return false;
	}

	@Override
	public boolean containsAll(Collection c) {
		if (c == this) {
			return true;
		}
		if (c.size() != 1)
			return false;
		Object next = c.iterator().next();
		return obj == next || obj.equals(next);
	}

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

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

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

	@Override
	public void clear() {
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy