use of com.fasterxml.jackson.databind.node.IntNode in project elasticsearch by elastic.
the class GeoIpCacheTests method testCachesAndEvictsResults.
public void testCachesAndEvictsResults() throws Exception {
GeoIpCache cache = new GeoIpCache(1);
final NodeCache.Loader loader = key -> new IntNode(key);
JsonNode jsonNode1 = cache.get(1, loader);
assertSame(jsonNode1, cache.get(1, loader));
// evict old key by adding another value
cache.get(2, loader);
assertNotSame(jsonNode1, cache.get(1, loader));
}
use of com.fasterxml.jackson.databind.node.IntNode in project swagger-core by swagger-api.
the class PropertyDeserializer method getEnum.
private static List<String> getEnum(JsonNode node, PropertyBuilder.PropertyId type) {
final List<String> result = new ArrayList<String>();
JsonNode detailNode = getDetailNode(node, type);
if (detailNode != null) {
ArrayNode an = (ArrayNode) detailNode;
for (JsonNode child : an) {
if (child instanceof TextNode || child instanceof NumericNode || child instanceof IntNode || child instanceof LongNode || child instanceof DoubleNode || child instanceof FloatNode) {
result.add(child.asText());
}
}
}
return result.isEmpty() ? null : result;
}
use of com.fasterxml.jackson.databind.node.IntNode in project XRTB by benmfaul.
the class BidRequest method setup.
/**
* Sets up the database of values of the JSON, from the mapped keys in the
* campaigns. THis traverses the JSON once, and stores the required values
* needed by campaigns once.
*
* @throws Exception
* on JSON processing errors.
*/
protected void setup() throws Exception {
id = rootNode.path("id").textValue();
if (id == null) {
throw new Exception("Required field 'id' is missing or wrong type");
}
IntNode in = null;
Object test = null;
// a fast way to keep up
StringBuilder item = new StringBuilder("id");
// Im looking for
try {
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
List list = mapp.get(key);
if (list.size() != 0)
compileList(key, list);
}
// ////////////////////////////////////////////////////////////////////
if ((test = getNode("site.id")) != null)
siteId = ((TextNode) test).textValue();
else {
test = getNode("app.id");
if (test != null) {
siteId = ((TextNode) test).textValue();
}
}
if ((test = getNode("site.domain")) != null)
siteDomain = ((TextNode) test).textValue();
else {
test = getNode("app.domain");
if (test != null) {
siteDomain = ((TextNode) test).textValue();
}
}
// ///////////////
if (siteDomain != null && blackList != null) {
if (blackList.contains(siteDomain)) {
blackListed = true;
return;
}
}
if ((test = getNode("site.name")) != null)
siteName = ((TextNode) test).textValue();
else {
test = getNode("app.name");
if (test != null) {
siteName = ((TextNode) test).textValue();
}
}
////////////////// Fill in pageurl info ////////////////
if ((test = getNode("site.content.url")) != null) {
pageurl = ((TextNode) test).textValue();
} else if ((test = getNode("site.page")) != null) {
pageurl = ((TextNode) test).textValue();
} else {
test = getNode("app.content.url");
if (test != null) {
pageurl = ((TextNode) test).textValue();
}
}
if ((test = database.get("device.geo.lat")) != null && test instanceof MissingNode == false) {
try {
lat = getDoubleFrom(test);
test = database.get("device.geo.lon");
if (test != null)
lon = getDoubleFrom(test);
} catch (Exception error) {
}
}
//////////////////////////////////////////////////////////////////
//
// Handle the impressions
//
ArrayNode imps = (ArrayNode) rootNode.get("imp");
impressions = new ArrayList();
for (int i = 0; i < imps.size(); i++) {
JsonNode obj = imps.get(i);
Impression imp = new Impression(rootNode, obj);
impressions.add(imp);
}
handleRtb4FreeExtensions();
} catch (Exception error) {
// This is an error in the protocol
error.printStackTrace();
if (Configuration.isInitialized() == false)
return;
// error.printStackTrace();
// String str = rootNode.toString();
// System.out.println(str);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
error.printStackTrace(pw);
String str = sw.toString();
String[] lines = str.split("\n");
StringBuilder sb = new StringBuilder();
sb.append("Abmormal processing of bid ");
sb.append(id);
sb.append(", ");
if (lines.length > 0)
sb.append(lines[0]);
if (lines.length > 1)
sb.append(lines[1]);
Controller.getInstance().sendLog(4, "BidRequest:setup():error", sb.toString());
}
}
use of com.fasterxml.jackson.databind.node.IntNode in project XRTB by benmfaul.
the class Node method traverse.
/**
* Traverse an ArrayNode and convert to ArrayList
*
* @param n.
* A Jackson ArrayNode.
* @return List. The list that corresponds to the Jackson ArrayNode.
*/
List traverse(ArrayNode n) {
List list = new ArrayList();
for (int i = 0; i < n.size(); i++) {
Object obj = n.get(i);
if (obj instanceof IntNode) {
IntNode d = (IntNode) obj;
list.add(d.numberValue());
} else if (obj instanceof DoubleNode) {
DoubleNode d = (DoubleNode) obj;
list.add(d.numberValue());
} else if (obj instanceof ArrayNode) {
ArrayNode nodes = (ArrayNode) obj;
for (int k = 0; i < nodes.size(); i++) {
list.add(nodes.get(k));
}
} else if (obj instanceof TextNode) {
TextNode t = (TextNode) obj;
list.add(t.textValue());
} else {
list.add(obj);
}
}
return list;
}
use of com.fasterxml.jackson.databind.node.IntNode in project XRTB by benmfaul.
the class ANode method traverse.
/**
* Traverse an ArrayNode and convert to ArrayList
*
* @param n. A Jackson ArrayNode.
* @return List. The list that corresponds to the Jackson ArrayNode.
*/
List traverse(ArrayNode n) {
List list = new ArrayList();
for (int i = 0; i < n.size(); i++) {
Object obj = n.get(i);
if (obj instanceof IntNode) {
IntNode d = (IntNode) obj;
list.add(d.numberValue());
} else if (obj instanceof DoubleNode) {
DoubleNode d = (DoubleNode) obj;
list.add(d.numberValue());
} else {
TextNode t = (TextNode) obj;
list.add(t.textValue());
}
}
return list;
}
Aggregations