106 lines
3.5 KiB
Java
106 lines
3.5 KiB
Java
package org.greenrobot.greendao.query;
|
|
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import org.greenrobot.greendao.DaoException;
|
|
import org.greenrobot.greendao.Property;
|
|
import org.greenrobot.greendao.internal.SqlUtils;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public interface WhereCondition {
|
|
void a(StringBuilder sb, String str);
|
|
|
|
void a(List<Object> list);
|
|
|
|
public static class PropertyCondition extends AbstractCondition {
|
|
public final Property d;
|
|
public final String e;
|
|
|
|
public PropertyCondition(Property property, String str) {
|
|
this.d = property;
|
|
this.e = str;
|
|
}
|
|
|
|
private static Object a(Property property, Object obj) {
|
|
if (obj != null && obj.getClass().isArray()) {
|
|
throw new DaoException("Illegal value: found array, but simple object required");
|
|
}
|
|
Class<?> cls = property.b;
|
|
if (cls == Date.class) {
|
|
if (obj instanceof Date) {
|
|
return Long.valueOf(((Date) obj).getTime());
|
|
}
|
|
if (obj instanceof Long) {
|
|
return obj;
|
|
}
|
|
throw new DaoException("Illegal date value: expected java.util.Date or Long for value " + obj);
|
|
}
|
|
if (cls == Boolean.TYPE || cls == Boolean.class) {
|
|
if (obj instanceof Boolean) {
|
|
return Integer.valueOf(((Boolean) obj).booleanValue() ? 1 : 0);
|
|
}
|
|
if (obj instanceof Number) {
|
|
int intValue = ((Number) obj).intValue();
|
|
if (intValue != 0 && intValue != 1) {
|
|
throw new DaoException("Illegal boolean value: numbers must be 0 or 1, but was " + obj);
|
|
}
|
|
} else if (obj instanceof String) {
|
|
String str = (String) obj;
|
|
if ("TRUE".equalsIgnoreCase(str)) {
|
|
return 1;
|
|
}
|
|
if ("FALSE".equalsIgnoreCase(str)) {
|
|
return 0;
|
|
}
|
|
throw new DaoException("Illegal boolean value: Strings must be \"TRUE\" or \"FALSE\" (case insensitive), but was " + obj);
|
|
}
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
public PropertyCondition(Property property, String str, Object obj) {
|
|
super(a(property, obj));
|
|
this.d = property;
|
|
this.e = str;
|
|
}
|
|
|
|
@Override // org.greenrobot.greendao.query.WhereCondition
|
|
public void a(StringBuilder sb, String str) {
|
|
SqlUtils.a(sb, str, this.d);
|
|
sb.append(this.e);
|
|
}
|
|
}
|
|
|
|
public static abstract class AbstractCondition implements WhereCondition {
|
|
protected final boolean a;
|
|
protected final Object b;
|
|
protected final Object[] c;
|
|
|
|
public AbstractCondition() {
|
|
this.a = false;
|
|
this.b = null;
|
|
this.c = null;
|
|
}
|
|
|
|
@Override // org.greenrobot.greendao.query.WhereCondition
|
|
public void a(List<Object> list) {
|
|
if (this.a) {
|
|
list.add(this.b);
|
|
return;
|
|
}
|
|
Object[] objArr = this.c;
|
|
if (objArr != null) {
|
|
for (Object obj : objArr) {
|
|
list.add(obj);
|
|
}
|
|
}
|
|
}
|
|
|
|
public AbstractCondition(Object obj) {
|
|
this.b = obj;
|
|
this.a = true;
|
|
this.c = null;
|
|
}
|
|
}
|
|
}
|