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

de.invation.code.toval.math.logic.Literal 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;

public class Literal implements Comparator{
	
	private Object item = null;
	private boolean negated = false;
	
	public Literal(Object item){
		this.item = item;
	}
	
	public Literal(Object item, boolean positive){
		this(item);
		this.negated = !positive;
	}
	
	public boolean isNegated(){
		return negated;
	}
	
	public Object getItem(){
		return item;
	}
	
	public Literal getInverse(){
		try{
			return new Literal(item, negated);
		}catch(Exception e){
			return null;
		}
	}
	
	public Literal clone(){
		try{
			return new Literal(item, negated);
		}catch(Exception e){
			return null;
		}
	}
	
	public String toString(){
		if(negated){
			return "\u00AC"+item.toString();
		}
		return item.toString();
	}

	public int compare(Literal o1, Literal o2) {
		return 0;
	}
	
	@Override
	public boolean equals(Object o) {
		
		if (this == o)
			return true;
		if (o == null)
			return false;
		if (o.getClass() != getClass())
			return false;
			   
		if (negated != ((Literal) o).isNegated())
			return false;
		if(!item.equals(((Literal) o).getItem()))
			return false;
		
		return true;

	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy