/*
 * Copyright 2009-2010 Yuichiro Moriguchi
 *
 * 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 net.morilib.util.set2;

import java.util.HashSet;
import java.util.Set;

import net.morilib.util.datafactory.SetFactory;

/**
 *
 *
 * @author MORIGUCHI, Yuichiro 2010/08/29
 */
public final class UniversalJavaSet<E>
extends UniversalSet<E, BooleanAlgebricJavaSet<E>>
implements java.io.Serializable {
	
	//
	private static final long serialVersionUID = -1635564820228280236L;
	
	//
	private final Set<E> uni;
	private final SetFactory fac;
	private final BooleanAlgebricJavaSet<E> zero, one;
	
	/**
	 * 
	 * @param universe
	 * @param factory
	 */
	public UniversalJavaSet(Set<E> universe, SetFactory factory) {
		this.uni  = new HashSet<E>(universe);
		this.fac  = factory;
		this.zero = new BooleanAlgebricJavaZeroSet<E>(this);
		this.one  = new BooleanAlgebricJavaOneSet<E>(this);
	}
	
	//
	/*package*/ SetFactory getFactory() {
		return fac;
	}
	
	/* (non-Javadoc)
	 * @see net.morilib.util.set2.UniversalSet#getUniversalSet()
	 */
	@Override
	protected final Set<E> getUniversalSet() {
		return uni;
	}

	/* (non-Javadoc)
	 * @see net.morilib.lang.algebra.BooleanAlgebra#get0()
	 */
	@Override
	public BooleanAlgebricJavaSet<E> get0() {
		return zero;
	}

	/* (non-Javadoc)
	 * @see net.morilib.lang.algebra.BooleanAlgebra#get1()
	 */
	@Override
	public BooleanAlgebricJavaSet<E> get1() {
		return one;
	}

}
