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

it.amattioli.locate.PlaceSpecification Maven / Gradle / Ivy

The newest version!
package it.amattioli.locate;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import it.amattioli.dominate.hibernate.filters.ComparisonType;
import it.amattioli.dominate.specifications.Assembler;
import it.amattioli.dominate.specifications.ConjunctionSpecification;
import it.amattioli.dominate.specifications.EntitySpecification;
import it.amattioli.dominate.specifications.MultipleEnumSpecification;
import it.amattioli.dominate.specifications.StringSpecification;
import it.amattioli.dominate.specifications.hibernate.CriteriaAssembler;
import it.amattioli.locate.hibernate.PlaceTypeHibernateType;

public class PlaceSpecification extends ConjunctionSpecification {
	private StringSpecification descriptionSpecification = StringSpecification.newInstance("description");
	private Map> codeSpecifications = new HashMap>();
	private MultipleEnumSpecification placeTypeSpec = MultipleEnumSpecification.newInstance("type", PlaceType.class, PlaceTypeHibernateType.class);
	private EntitySpecification parentSpecification = EntitySpecification.newInstance("parent", Place.class);
	private CollectionSpecification zipCodeSpecification = new CollectionSpecification("zipCodes");
	
	public PlaceSpecification() {
		addSpecification(descriptionSpecification);
		addSpecification(placeTypeSpec);
		addSpecification(parentSpecification);
		addSpecification(zipCodeSpecification);
	}
	
	public String getZipCode() {
		return (String)zipCodeSpecification.getValue();
	}
	
	public void setZipCode(String zipCode) {
		zipCodeSpecification.setValue(zipCode);
	}
	
	public String getDescription() {
		return descriptionSpecification.getValue();
	}
	
	public void setDescription(String description) {
		String old = getDescription();
		descriptionSpecification.setValue(description);
		firePropertyChange("description", old, description);
	}
	
	public ComparisonType getDescriptionType() {
		return descriptionSpecification.getComparisonType();
	}
	
	public void setDescriptionType(ComparisonType filterType) {
		ComparisonType old = getDescriptionType();
		descriptionSpecification.setComparisonType(filterType);
		firePropertyChange("descriptionType", old, filterType);
	}
	
	public Collection getPlaceTypes() {
		return placeTypeSpec.getValue();
	}

	public void setPlaceTypes(Collection placeTypes) {
		placeTypeSpec.setValue(placeTypes);
	}
	
	public String getCode(String codeName) {
		StringSpecification codeSpecification = codeSpecifications.get(codeName);
		if (codeSpecification != null) {
			return codeSpecification.getValue();
		} else {
			return null;
		}
	}
	
	public void setCode(String codeName, String value) {
		StringSpecification codeSpecification = codeSpecifications.get(codeName);
		if (codeSpecification == null) {
			codeSpecification = StringSpecification.newInstance("code("+codeName+")");
			codeSpecification.setComparisonType(ComparisonType.EXACT);
			codeSpecifications.put(codeName, codeSpecification);
			addSpecification(codeSpecification);
		}
		codeSpecification.setValue(value);
	}

	public void setParent(Place parent) {
		parentSpecification.setValue(parent);
	}
	
	public Place getParent() {
		return parentSpecification.getValue();
	}
	
	@Override
	public boolean supportsAssembler(Assembler assembler) {
		if (assembler instanceof CriteriaAssembler) return false;
		return super.supportsAssembler(assembler);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy