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

de.invation.code.toval.math.logic.ClauseSet Maven / Gradle / Ivy

Go to download

TOVAL comprises a set of java classes for common programming issues. It includes utils for arrays, lists, sets and collections for convenient handling and modification, but also support for mathematic definitions concerning logic (clauses + resolution) together with some algorithms for permutations, powersets and resolution. Additionally it contains a number of types for multisets, matrices with object keys and much more.

The newest version!
package de.invation.code.toval.math.logic;


import java.util.Comparator;
import java.util.Iterator;

import de.invation.code.toval.types.HashList;





public class ClauseSet extends HashList implements Comparator{
	
	private static final long serialVersionUID = 1L;
	
	public ClauseSet(){}
	
	public ClauseSet(Clause k){
		add(k);
	}
	
	public HashList getItems(){
		HashList set = new HashList();
		for(Iterator iter=iterator(); iter.hasNext();)
			set.addAll(iter.next().getItems());
		return set;
	}
	
	public ClauseSet union(ClauseSet k){
		ClauseSet r = new ClauseSet();
		r.addAll(this);
		r.addAll(k);
		return r;
	}

	public int compare(ClauseSet o1, ClauseSet o2) {
		return o1.size()-o2.size();
	}
	
	@Override
	public boolean equals(Object o) {
		
		if (this == o)
			return true;
		if (o == null)
			return false;
		if (o.getClass() != getClass())
			return false;
		if (!((ClauseSet) o).containsAll(this))
			return false;
		if(!containsAll((ClauseSet) o))
			return false;
		
		return true;
	}
	
	public String toString(){
		if(isEmpty()){
			return "{}";
		} else {
			String s = "{";
			for(Iterator i = iterator(); i.hasNext();){
				s += i.next().toString();
				if(i.hasNext()){
					s += ",";
				}
			}
			s += "}";
			return s;
		}
	}
	
}