Package com.dooapp.gaedo.finders.informers

Source Code of com.dooapp.gaedo.finders.informers.ObjectFieldInformer

package com.dooapp.gaedo.finders.informers;

import java.lang.reflect.Field;

import com.dooapp.gaedo.finders.FieldInformer;
import com.dooapp.gaedo.finders.QueryExpression;
import com.dooapp.gaedo.finders.expressions.AnythingExpression;
import com.dooapp.gaedo.finders.expressions.EqualsExpression;
import com.dooapp.gaedo.finders.expressions.Expressions;
import com.dooapp.gaedo.properties.Property;

public class ObjectFieldInformer implements
    FieldInformer {

  /**
   * Field associated to epressions generated by this informer
   */
  protected final Property source;

  public ObjectFieldInformer(Property source) {
    super();
    this.source = source;
  }

  /**
   * The most common check : is field value equals to input value
   *
   * @param value
   *            expected value
   * @return a {@link EqualsExpression} checking field value is given value
   */
  public QueryExpression equalsTo(Object value) {
    return new EqualsExpression(source, value);
  }

  /**
   * The second most common check : is field value different from input value
   *
   * @param value
   *            expected value
   * @return a {@link EqualsExpression} checking field value is given value
   *         embedded in {@link Expressions#not(QueryExpression)} call
   */
  public QueryExpression differentFrom(Object value) {
    return Expressions.not(equalsTo(value));
  }

  /**
   * The thirsd most common check : this value is anything. It's a common way to have the field have any value.
   * @return
   */
  public QueryExpression isAnything() {
    return new AnythingExpression(source);
  }

  @Override
  public String toString() {
    StringBuilder sOut = new StringBuilder();
    sOut.append(getClass().getName()).append(" on field ").append(source.toGenericString());
    return sOut.toString();
  }

  @Override
  public Property getField() {
    return source;
  }
}
TOP

Related Classes of com.dooapp.gaedo.finders.informers.ObjectFieldInformer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.