use of com.fasterxml.jackson.databind.node.IntNode in project XRTB by benmfaul.
the class ANode method iterateObject.
/**
* Iterate over a Jackson object and create a Java Map.
*
* @param node. ObjectNode. The Jackson node to set up as a Map.
* @return Map. Returns the Map implementation of the Jackson node.
*/
Map iterateObject(ObjectNode node) {
Map m = new HashMap();
Iterator it = node.iterator();
it = node.fieldNames();
while (it.hasNext()) {
String key = (String) it.next();
Object s = node.get(key);
if (s instanceof TextNode) {
TextNode t = (TextNode) s;
m.put(key, t.textValue());
} else if (s instanceof DoubleNode) {
DoubleNode t = (DoubleNode) s;
m.put(key, t.numberValue());
} else if (s instanceof IntNode) {
IntNode t = (IntNode) s;
m.put(key, t.numberValue());
} else
// indeterminate, need to traverse
m.put(key, s);
}
return m;
}
use of com.fasterxml.jackson.databind.node.IntNode in project XRTB by benmfaul.
the class BidRequest method getDoubleFrom.
/**
* Return a double, whether it's integer or not.
*
* @param o
* Obhect. The json object.
* @return double. Returns the value as a double.
* @throws Exception
* if the object is not a number.
*/
public static double getDoubleFrom(Object o) throws Exception {
double x = 0;
if (o instanceof DoubleNode) {
DoubleNode dn = (DoubleNode) o;
x = dn.doubleValue();
} else if (o instanceof MissingNode) {
throw new Exception("Missing value from: " + o.toString());
} else {
IntNode dn = (IntNode) o;
x = dn.doubleValue();
}
return x;
}
use of com.fasterxml.jackson.databind.node.IntNode in project XRTB by benmfaul.
the class Node method testInternal.
/**
* Internal version of test() when recursion is required (NOT_* form)
*
* @param value.
* Object. Converts the value of the bid request field (Jackson)
* to the appropriate Java object.
* @return boolean. Returns true if the operation succeeded.
* @throws Exception
* if the value is not recognized or is not compatible with
* this.value.
*/
public boolean testInternal(Object value) throws Exception {
if (value == null || value instanceof MissingNode == true) {
// request.
if (!(operator == EXISTS || operator == NOT_EXISTS)) {
if (notPresentOk)
return true;
return false;
}
}
Number nvalue = null;
String svalue = null;
// Set qvalue = null;
Set qval = null;
if (value instanceof String)
svalue = (String) value;
if (value instanceof IntNode) {
IntNode n = (IntNode) value;
nvalue = n.numberValue();
} else if (value instanceof TextNode) {
TextNode tn = (TextNode) value;
svalue = tn.textValue();
} else if (value instanceof ArrayNode) {
List list = traverse((ArrayNode) value);
qvalue = new TreeSet(list);
} else if (value instanceof ObjectNode) {
ObjectNode n = (ObjectNode) value;
mvalue = iterateObject(n);
} else if (value instanceof Double) {
// (Node) value;
DoubleNode n = new DoubleNode((Double) value);
nvalue = n.numberValue();
} else if (value instanceof DoubleNode) {
DoubleNode n = (DoubleNode) value;
n.asDouble();
// (Node) value;
DoubleNode nn = new DoubleNode(n.asDouble());
nvalue = nn.numberValue();
} else if (value instanceof Integer) {
// (Node) value;
IntNode n = new IntNode((Integer) value);
nvalue = n.numberValue();
} else if (value instanceof Collection) {
qvalue = new TreeSet();
qvalue.addAll((Collection) value);
}
switch(operator) {
case QUERY:
return true;
case EQUALS:
return processEquals(ival, nvalue, sval, svalue, qval, qvalue);
case NOT_EQUALS:
return !processEquals(ival, nvalue, sval, svalue, qval, qvalue);
case STRINGIN:
if (lval != null) {
boolean member = false;
for (int i = 0; i < lval.size(); i++) {
Object test = lval.get(i);
if (test instanceof String) {
String testS = (String) test;
member |= processStringin(ival, nvalue, testS, svalue, qval, qvalue);
}
}
return member;
}
return processStringin(ival, nvalue, sval, svalue, qval, qvalue);
case NOT_STRINGIN:
if (lval != null) {
boolean member = false;
for (int i = 0; i < lval.size(); i++) {
Object test = lval.get(i);
if (test instanceof String) {
String testS = (String) test;
member |= processStringin(ival, nvalue, testS, svalue, qval, qvalue);
}
}
return !member;
}
return !processStringin(ival, nvalue, sval, svalue, qval, qvalue);
case REGEX:
case NOT_REGEX:
boolean member = true;
if (svalue != null) {
member = processRegex(ival, nvalue, sval, svalue, qval, qvalue);
}
if (operator == NOT_REGEX)
return !member;
else
return member;
case MEMBER:
case NOT_MEMBER:
if (sval != null && (sval.startsWith("@") || sval.startsWith("$"))) {
Object x = LookingGlass.get(sval);
boolean t = false;
if (x instanceof NavMap) {
NavMap nm = (NavMap) x;
t = nm.contains(svalue);
} else if (x instanceof BloomFilter) {
BloomFilter b = (BloomFilter) x;
t = b.mightContain(svalue);
} else if (x instanceof Set) {
Set set = (Set) x;
t = set.contains(svalue);
}
if (operator == NOT_MEMBER)
return !t;
else
return t;
}
if (qvalue == null) {
if (lval != null)
qvalue = new HashSet(lval);
else {
qvalue = new HashSet();
if (svalue == null)
qvalue.addAll((Collection) value);
else
qvalue.add(svalue);
}
}
if (nvalue == null && svalue == null) {
if (this.value instanceof String)
svalue = (String) this.value;
else {
try {
nvalue = (Integer) this.value;
} catch (Exception error) {
return false;
//System.out.println("QVALUE: " + qvalue);
//System.out.println("THIS VALUE: " + this.value);
//System.out.println("VALUE: " + value);
}
}
}
boolean test = false;
test = processMember(nvalue, svalue, qvalue);
if (operator == MEMBER)
return test;
else
return !test;
case INTERSECTS:
case NOT_INTERSECTS:
if (qvalue == null) {
if (lval != null)
qvalue = new TreeSet(lval);
}
if (qval == null) {
if (svalue != null) {
qval = new TreeSet();
qval.add(svalue);
} else {
if (nvalue != null) {
qval = new TreeSet();
qval.add(nvalue);
} else if (lval != null) {
qval = new TreeSet(lval);
}
}
} else {
if (svalue != null) {
qval.add(svalue);
} else {
if (nvalue != null) {
qval.add(nvalue.intValue());
}
}
}
if (qval == null)
qval = new TreeSet(lval);
boolean xxx = processIntersects(qval, qvalue);
if (operator == INTERSECTS)
return xxx;
return !xxx;
case INRANGE:
return computeInRange(mvalue, lval);
case NOT_INRANGE:
return !computeInRange(mvalue, lval);
case DOMAIN:
return computeInDomain(nvalue, lval);
case NOT_DOMAIN:
return !computeInDomain(nvalue, lval);
case LESS_THAN:
case LESS_THAN_EQUALS:
case GREATER_THAN:
case GREATER_THAN_EQUALS:
return processLTE(operator, ival, nvalue, sval, svalue, qval, qvalue);
case EXISTS:
case NOT_EXISTS:
boolean rc = false;
if (value == null)
rc = false;
else
rc = value instanceof ObjectNode;
if (operator == EXISTS)
return rc;
return !rc;
default:
return false;
}
}
use of com.fasterxml.jackson.databind.node.IntNode in project XRTB by benmfaul.
the class Node method iterateObject.
/**
* Iterate over a Jackson object and create a Java Map.
*
* @param node.
* ObjectNode. The Jackson node to set up as a Map.
* @return Map. Returns the Map implementation of the Jackson node.
*/
Map iterateObject(ObjectNode node) {
Map m = new HashMap();
Iterator it = node.iterator();
it = node.fieldNames();
while (it.hasNext()) {
String key = (String) it.next();
Object s = node.get(key);
if (s instanceof TextNode) {
TextNode t = (TextNode) s;
m.put(key, t.textValue());
} else if (s instanceof DoubleNode) {
DoubleNode t = (DoubleNode) s;
m.put(key, t.numberValue());
} else if (s instanceof IntNode) {
IntNode t = (IntNode) s;
m.put(key, t.numberValue());
} else
// indeterminate, need to traverse
m.put(key, s);
}
return m;
}
Aggregations