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

org.aksw.jena_sparql_api.utils.ValueSet Maven / Gradle / Ivy

There is a newer version: 3.17.0-1
Show newest version
package org.aksw.jena_sparql_api.utils;

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

/**
 * A class denoting a positive or negative (intensional) set of values. 
 * 
 * Negative with empty values denotes the set containing all values.
 * 
 * @author raven
 *
 * @param 
 */
public class ValueSet
{
	private Set values;
	private Boolean polarity;

	public ValueSet(Set values, Boolean isPositive)
	{
		super();
		this.values = values;
		this.polarity = isPositive;
	}
	
	
	/**
	 * Create a value set without polarity
	 * 
	 * @param 
	 * @return
	 */
	public static  ValueSet create() {
		return new ValueSet(new HashSet(), null);
	}
	
	public static  ValueSet create(Set values, boolean polarity) {
		return new ValueSet(values, polarity);
	}


	public Boolean getPolarity()
	{
		return (isUnknown()) ? null : polarity;
	}

	public boolean isUnknown()
	{
		return values == null;
	}
	
	public void setPolarity(boolean polarity)
	{
		this.polarity = polarity;
	}
	
	public Set getValues()
	{
		return values;
	}
	
	
	public void merge(ValueSet other) {
		if(other.isUnknown()) {
			if(this.isUnknown()) {
				this.values = null;
			} else {
				return;
			}
		}

		if(this.isUnknown()) {			
			return;
		}		
		if(this.polarity != false && other.polarity == true) {
			this.values.addAll(other.values);
			this.polarity = true;
		} else if (this.polarity != true && other.polarity == false) {
			this.values.retainAll(other.getValues());
			this.polarity = false;
		} else {
			this.values = null;
		}
	}


	@Override
	public String toString()
	{
		return "ValueSet [values=" + values + ", polarity=" + polarity + "]";
	}
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy