List of usage examples for com.google.gson JsonElement getAsLong
public long getAsLong()
From source file:org.qcert.runtime.UnaryOperators.java
License:Apache License
public static JsonElement sqrt(JsonElement e) { return new JsonPrimitive((Math.sqrt(e.getAsLong()))); }
From source file:org.qcert.runtime.UnaryOperators.java
License:Apache License
private static long sum_helper(JsonArray ec) { long acc = 0; for (JsonElement elem : ec) { acc += elem.getAsLong(); }/*from w ww . ja va 2 s. co m*/ return acc; }
From source file:org.qcert.runtime.UnaryOperators.java
License:Apache License
public static JsonElement list_min(JsonElement e) { final JsonArray ec = e.getAsJsonArray(); long min = Long.MAX_VALUE; for (final JsonElement elem : ec) { final long eleml = elem.getAsLong(); if (eleml < min) { min = eleml;/*from www. ja va 2 s. c o m*/ } } return new JsonPrimitive(min); }
From source file:org.qcert.runtime.UnaryOperators.java
License:Apache License
public static JsonElement list_max(JsonElement e) { final JsonArray ec = e.getAsJsonArray(); long max = Long.MIN_VALUE; for (final JsonElement elem : ec) { final long eleml = elem.getAsLong(); if (eleml > max) { max = eleml;/* w w w. ja va2s . co m*/ } } return new JsonPrimitive(max); }
From source file:org.qcert.runtime.UnaryOperators.java
License:Apache License
public static JsonElement float_of_int(JsonElement e) { return new JsonPrimitive(e.getAsLong()); }
From source file:org.sleuthkit.autopsy.recentactivity.Chrome.java
License:Open Source License
/** * Search for bookmark files and make artifacts. */// www . j ava 2 s. co m private void getBookmark() { FileManager fileManager = currentCase.getServices().getFileManager(); List<AbstractFile> bookmarkFiles = null; try { bookmarkFiles = fileManager.findFiles(dataSource, "Bookmarks", "Chrome"); //NON-NLS } catch (TskCoreException ex) { String msg = NbBundle.getMessage(this.getClass(), "Chrome.getBookmark.errMsg.errGettingFiles"); logger.log(Level.SEVERE, msg, ex); this.addErrorMessage(this.getName() + ": " + msg); return; } if (bookmarkFiles.isEmpty()) { logger.log(Level.INFO, "Didn't find any Chrome bookmark files."); //NON-NLS return; } dataFound = true; int j = 0; while (j < bookmarkFiles.size()) { AbstractFile bookmarkFile = bookmarkFiles.get(j++); if (bookmarkFile.getSize() == 0) { continue; } String temps = RAImageIngestModule.getRATempPath(currentCase, "chrome") + File.separator + bookmarkFile.getName().toString() + j + ".db"; //NON-NLS try { ContentUtils.writeToFile(bookmarkFile, new File(temps)); } catch (IOException ex) { logger.log(Level.SEVERE, "Error writing temp sqlite db for Chrome bookmark artifacts.{0}", ex); //NON-NLS this.addErrorMessage(NbBundle.getMessage(this.getClass(), "Chrome.getBookmark.errMsg.errAnalyzingFile", this.getName(), bookmarkFile.getName())); continue; } logger.log(Level.INFO, "{0}- Now getting Bookmarks from {1}", new Object[] { moduleName, temps }); //NON-NLS File dbFile = new File(temps); if (context.dataSourceIngestIsCancelled()) { dbFile.delete(); break; } FileReader tempReader; try { tempReader = new FileReader(temps); } catch (FileNotFoundException ex) { logger.log(Level.SEVERE, "Error while trying to read into the Bookmarks for Chrome.", ex); //NON-NLS this.addErrorMessage(NbBundle.getMessage(this.getClass(), "Chrome.getBookmark.errMsg.errAnalyzeFile", this.getName(), bookmarkFile.getName())); continue; } final JsonParser parser = new JsonParser(); JsonElement jsonElement; JsonObject jElement, jRoot, jBookmark; JsonArray jBookmarkArray; try { jsonElement = parser.parse(tempReader); jElement = jsonElement.getAsJsonObject(); jRoot = jElement.get("roots").getAsJsonObject(); //NON-NLS jBookmark = jRoot.get("bookmark_bar").getAsJsonObject(); //NON-NLS jBookmarkArray = jBookmark.getAsJsonArray("children"); //NON-NLS } catch (JsonIOException | JsonSyntaxException | IllegalStateException ex) { logger.log(Level.WARNING, "Error parsing Json from Chrome Bookmark.", ex); //NON-NLS this.addErrorMessage(NbBundle.getMessage(this.getClass(), "Chrome.getBookmark.errMsg.errAnalyzingFile3", this.getName(), bookmarkFile.getName())); continue; } for (JsonElement result : jBookmarkArray) { JsonObject address = result.getAsJsonObject(); if (address == null) { continue; } JsonElement urlEl = address.get("url"); //NON-NLS String url; if (urlEl != null) { url = urlEl.getAsString(); } else { url = ""; } String name; JsonElement nameEl = address.get("name"); //NON-NLS if (nameEl != null) { name = nameEl.getAsString(); } else { name = ""; } Long date; JsonElement dateEl = address.get("date_added"); //NON-NLS if (dateEl != null) { date = dateEl.getAsLong(); } else { date = Long.valueOf(0); } String domain = Util.extractDomain(url); try { BlackboardArtifact bbart = bookmarkFile.newArtifact(ARTIFACT_TYPE.TSK_WEB_BOOKMARK); Collection<BlackboardAttribute> bbattributes = new ArrayList<>(); //TODO Revisit usage of deprecated constructor as per TSK-583 bbattributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_URL.getTypeID(), NbBundle.getMessage(this.getClass(), "Chrome.parentModuleName"), url)); bbattributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_TITLE.getTypeID(), NbBundle.getMessage(this.getClass(), "Chrome.parentModuleName"), name)); bbattributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(), NbBundle.getMessage(this.getClass(), "Chrome.parentModuleName"), (date / 1000000) - Long.valueOf("11644473600"))); bbattributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID(), NbBundle.getMessage(this.getClass(), "Chrome.parentModuleName"), NbBundle.getMessage(this.getClass(), "Chrome.moduleName"))); bbattributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DOMAIN.getTypeID(), NbBundle.getMessage(this.getClass(), "Chrome.parentModuleName"), domain)); bbart.addAttributes(bbattributes); } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Error while trying to insert Chrome bookmark artifact{0}", ex); //NON-NLS this.addErrorMessage(NbBundle.getMessage(this.getClass(), "Chrome.getBookmark.errMsg.errAnalyzingFile4", this.getName(), bookmarkFile.getName())); } } dbFile.delete(); } IngestServices.getInstance().fireModuleDataEvent( new ModuleDataEvent(NbBundle.getMessage(this.getClass(), "Chrome.parentModuleName"), BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK)); }
From source file:org.structr.core.PropertySetGSONAdapter.java
License:Open Source License
private Object getTypedValue(JsonElement valueElement, String type) { Object value = null;// w ww.ja v a 2 s . co m if ((type == null) || type.equals("null")) { value = valueElement.getAsJsonNull(); } else if (type.equals("String")) { value = valueElement.getAsString(); } else if (type.equals("Number")) { value = valueElement.getAsNumber(); } else if (type.equals("Boolean")) { value = valueElement.getAsBoolean(); } else if (type.equals("JsonArray")) { value = valueElement.getAsJsonArray(); } else if (type.equals("JsonObject")) { value = valueElement.getAsJsonObject(); } else if (type.equals("Integer")) { value = valueElement.getAsInt(); } else if (type.equals("Long")) { value = valueElement.getAsLong(); } else if (type.equals("Double")) { value = valueElement.getAsDouble(); } else if (type.equals("Float")) { value = valueElement.getAsFloat(); } else if (type.equals("Byte")) { value = valueElement.getAsByte(); } else if (type.equals("Short")) { value = valueElement.getAsShort(); } else if (type.equals("Character")) { value = valueElement.getAsCharacter(); } else if (type.equals("BigDecimal")) { value = valueElement.getAsBigDecimal(); } else if (type.equals("BigInteger")) { value = valueElement.getAsBigInteger(); } return value; }
From source file:org.terasology.persistence.typeHandling.gson.GsonPersistedDataArray.java
License:Apache License
@Override public TLongList getAsLongArray() { TLongList result = new TLongArrayList(size()); for (JsonElement element : array) { result.add(element.getAsLong()); }// ww w .j a v a 2s . c o m return result; }
From source file:org.uorm.serializer.DefaultJsonSerializer.java
License:Apache License
@Override public Map<String, Object> deserialize2(Class<?> cls, String json) throws Exception { JsonStreamParser parser = new JsonStreamParser(json); if (parser.hasNext()) { JsonObject jsonobj = parser.next().getAsJsonObject(); Set<Entry<String, JsonElement>> jset = jsonobj.entrySet(); if (!jset.isEmpty()) { Map<String, PropertyDescriptor> propMap = ObjectMappingCache.getInstance() .getObjectPropertyMap(cls); Map<String, Object> instance = new HashMap<String, Object>(); for (Entry<String, JsonElement> entry : jset) { String name = entry.getKey(); JsonElement val = entry.getValue(); if (!val.isJsonNull()) { PropertyDescriptor descriptor = propMap.get(name); if (descriptor != null) { Class<?> memberType = descriptor.getPropertyType(); if (memberType == String.class) { instance.put(name, val.getAsString()); } else if (memberType == Integer.class || memberType == Integer.TYPE) { instance.put(name, val.getAsInt()); } else if (memberType == Byte.class || memberType == Byte.TYPE) { instance.put(name, val.getAsByte()); } else if (memberType == Double.class || memberType == Double.TYPE) { instance.put(name, val.getAsDouble()); } else if (memberType == Float.class || memberType == Float.TYPE) { instance.put(name, val.getAsFloat()); } else if (memberType == Long.class || memberType == Long.TYPE) { instance.put(name, val.getAsLong()); } else if (memberType == Short.class || memberType == Short.TYPE) { instance.put(name, val.getAsShort()); } else if (memberType == Boolean.class || memberType == Boolean.TYPE) { instance.put(name, val.getAsBoolean()); } else if (memberType == BigDecimal.class) { instance.put(name, val.getAsBigDecimal()); } else if (memberType == BigInteger.class) { instance.put(name, val.getAsBigInteger()); } else if (memberType == byte[].class) { instance.put(name, val.getAsString().getBytes()); } else if (memberType == java.sql.Timestamp.class) { Long time = parserDate(val.getAsString()); if (time == null) { instance.put(name, null); } else { instance.put(name, new java.sql.Timestamp(time)); }// w w w.j ava2 s .co m } else if (memberType == java.sql.Date.class) { Long time = parserDate(val.getAsString()); if (time == null) { instance.put(name, null); } else { instance.put(name, new java.sql.Date(time)); } } else if (memberType == java.util.Date.class) { Long time = parserDate(val.getAsString()); if (time == null) { instance.put(name, null); } else { instance.put(name, new java.util.Date(time)); } } else {//default String instance.put(name, val.getAsString()); } } else {//String instance.put(name, val.getAsString()); } } } return instance; } } return null; }
From source file:org.virtue.game.logic.social.ChatManager.java
License:Open Source License
public void deserialiseData(JsonObject chatData) { onlineStatus = OnlineStatus.forCode(chatData.get("onlineStatus").getAsInt()); if (onlineStatus == null) { onlineStatus = OnlineStatus.FRIENDS; }// ww w.j av a 2 s .c om lastFriendsChat = chatData.get("lastFriendsChat").getAsString(); autoJoinFriendsChat = chatData.get("autoJoinFc").getAsBoolean(); JsonElement clanData = chatData.get("clanHash"); if (clanData != null) { myClanHash = clanData.getAsLong(); } }