Back to project page NexusData.
The source code is released under:
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCT...
If you think the Android project NexusData listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.github.dkharrat.nexusdata.predicate; //from w w w . j a va 2 s. c om import java.lang.reflect.Field; import com.github.dkharrat.nexusdata.core.ManagedObject; public class FieldPathExpression implements Expression<Object> { private final String fieldPath; public FieldPathExpression(String fieldPath) { this.fieldPath = fieldPath; } public String getFieldPath() { return fieldPath; } @Override public <T> T accept(ExpressionVisitor<T> visitor) { return visitor.visit(this); } @Override public Object evaluate(Object object) { try { if (object instanceof ManagedObject) { return ((ManagedObject)object).getValue(fieldPath); } else { Field field = object.getClass().getDeclaredField(fieldPath); field.setAccessible(true); return field.get(object); } } catch (Exception e) { throw new RuntimeException(e); } } @Override public String toString() { return fieldPath; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; FieldPathExpression that = (FieldPathExpression) o; if (!fieldPath.equals(that.fieldPath)) return false; return true; } @Override public int hashCode() { return fieldPath.hashCode(); } }