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

net.anotheria.anodoc.query2.QueryContainsProperty Maven / Gradle / Ivy

There is a newer version: 4.3.0
Show newest version
package net.anotheria.anodoc.query2;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import net.anotheria.anodoc.data.Property;
import net.anotheria.util.StringUtils;

/**
 * Query to List/Array Property. Passes only if Property contains all queried values.
 *
 * IMPORTANT:Not properly tested yet. Use on own risk!!!!
 *
 * @author denis
 * @version $Id: $Id
 */
public class QueryContainsProperty extends QueryProperty{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8649073486730051958L;
	
	/**
	 * 

Constructor for QueryContainsProperty.

* * @param aName a {@link java.lang.String} object. * @param aValues a T object. */ public QueryContainsProperty(String aName, T... aValues){ this(aName, Arrays.asList(aValues)); } /** *

Constructor for QueryContainsProperty.

* * @param aName a {@link java.lang.String} object. * @param aValues a {@link java.util.Collection} object. */ public QueryContainsProperty(String aName, Collection aValues){ super(aName, aValues); } /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public boolean doesMatch(Object o) { if(o== null) return getOriginalValue() == null; List properties = ((List)o); Set toCompare = new HashSet(); for(Property p: properties) toCompare.add(p.getValue()); return toCompare.containsAll(getListValue()); } /** {@inheritDoc} */ @Override public String getComparator() { return " @> "; } /** {@inheritDoc} */ @Override public Object getValue() { Collection values = getListValue(); return StringUtils.surroundWith(StringUtils.concatenateTokens(values, ',', '\'', '\''), '(', ')'); } @SuppressWarnings("unchecked") private Collection getListValue(){ return (Collection) getOriginalValue(); } /** {@inheritDoc} */ @Override public boolean unprepaireable() { return true; } }