Java Code Examples for com.eclipsesource.json.JsonObject#getInt()

The following examples show how to use com.eclipsesource.json.JsonObject#getInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Message.java    From zencash-swing-wallet-ui with MIT License 5 votes vote down vote up
public void copyFromJSONObject(JsonObject obj)
{
	// Wire protocol fields
	this.version       = obj.getInt("ver",              1);
	this.from          = obj.getString("from",          "");
	this.message       = obj.getString("message",       "");
	this.sign          = obj.getString("sign",          "");
	this.threadID      = obj.getString("threadid",      "");	
	this.returnAddress = obj.getString("returnaddress", "");
	
	// Additional fields - may be missing, get default values
	this.transactionID = obj.getString("transactionID", "");
	this.time          = new Date(obj.getLong("time",   0));
	this.direction     = DIRECTION_TYPE.valueOf(
			                 obj.getString("direction", DIRECTION_TYPE.RECEIVED.toString()));
	this.verification  = VERIFICATION_TYPE.valueOf(
			                 obj.getString("verification", VERIFICATION_TYPE.UNVERIFIED.toString()));
	
	if (obj.get("isanonymous") != null)
	{
		this.isAnonymous = obj.getBoolean("isanonymous", false);
	} else
	{
		// Determine from content if it is anonymous
		this.isAnonymous = obj.get("threadid") != null; 
	}
}
 
Example 2
Source File: SelfUpdater.java    From Recaf with MIT License 5 votes vote down vote up
/**
 * Fetch the {@link #latestVersion latest version}
 * and {@link #latestArtifact latest artifact url}.
 *
 * @throws IOException
 * 		When opening a connection to the API url fails.
 */
private static void fetchLatestInfo() throws IOException {
	URL updateURL = new URL(API);
	String content = IOUtils.toString(updateURL.openStream(), StandardCharsets.UTF_8);
	JsonObject updateJson = Json.parse(content).asObject();
	// compare versions
	latestVersion = updateJson.getString("tag_name", "2.0.0");
	latestPatchnotes = updateJson.getString("body", "#Error\nCould not fetch update notes.");
	if (isOutdated()) {
		Log.info(LangUtil.translate("update.outdated"));
		JsonArray assets = updateJson.get("assets").asArray();
		for(JsonValue assetValue : assets.values()) {
			JsonObject assetObj = assetValue.asObject();
			String file = assetObj.getString("name", "invalid");
			// Skip non-jars
			if (!file.endsWith(".jar")) {
				continue;
			}
			// Find the largest jar
			int size = assetObj.getInt("size", 0);
			if (size > latestArtifactSize) {
				latestArtifactSize = size;
				String fileURL = assetObj.getString("browser_download_url", null);
				if (fileURL != null)
					latestArtifact = fileURL;
			}
		}
		try {
			String date = updateJson.getString("published_at", null);
			if (date != null)
				latestVersionDate = Instant.parse(date);
		} catch(DateTimeParseException ex) {
			Log.warn("Failed to parse timestamp for latest release");
		}
		if (latestArtifact == null)
			Log.warn(LangUtil.translate("update.fail.nodownload"));
	}
}
 
Example 3
Source File: TslintHelper.java    From typescript.java with MIT License 5 votes vote down vote up
private static Location createLocation(JsonValue value) {
	if (value == null || !value.isObject()) {
		return null;
	}
	JsonObject loc = value.asObject();
	return new Location(loc.getInt("line", -1), loc.getInt("character", -1), loc.getInt("position", -1));
}
 
Example 4
Source File: PlayerAction.java    From microrts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a PlayerAction from a JSON object
 * @param JSON
 * @param gs
 * @param utt
 * @return
 */
public static PlayerAction fromJSON(String JSON, GameState gs, UnitTypeTable utt) {
    PlayerAction pa = new PlayerAction();
    JsonArray a = Json.parse(JSON).asArray();
    for(JsonValue v:a.values()) {
        JsonObject o = v.asObject();
        int id = o.getInt("unitID", -1);
        Unit u = gs.getUnit(id);
        UnitAction ua = UnitAction.fromJSON(o.get("unitAction").asObject(), utt);
        pa.addUnitAction(u, ua);
    }
    return pa;
}
 
Example 5
Source File: UnitAction.java    From microrts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a UnitAction from a JSON object
 *
 * @param o
 * @param utt
 * @return
 */
public static UnitAction fromJSON(JsonObject o, UnitTypeTable utt) {
    UnitAction ua = new UnitAction(o.getInt("type", TYPE_NONE));
    ua.parameter = o.getInt("parameter", DIRECTION_NONE);
    ua.x = o.getInt("x", DIRECTION_NONE);
    ua.y = o.getInt("y", DIRECTION_NONE);
    String ut = o.getString("unitType", null);
    if (ut != null) {
        ua.unitType = utt.getUnitType(ut);
    }

    return ua;
}
 
Example 6
Source File: Unit.java    From microrts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructs a unit from a JSON object
 *
 * @param o
 * @param utt
 * @return
 */
public static Unit fromJSON(JsonObject o, UnitTypeTable utt) {

    Unit u = new Unit(
            o.getLong("ID", -1),
            o.getInt("player", -1),
            utt.getUnitType(o.getString("type", null)),
            o.getInt("x", 0),
            o.getInt("y", 0),
            o.getInt("resources", 0)
    );

    u.hitpoints = o.getInt("hitpoints", 1);
    return u;
}
 
Example 7
Source File: UnitType.java    From microrts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a temporary instance with just the name and ID from a JSON object
 * @param o
 * @return
 */
static UnitType createStub(JsonObject o) {
    UnitType ut = new UnitType();
    ut.ID = o.getInt("ID",-1);
    ut.name = o.getString("name",null);
    return ut;
}
 
Example 8
Source File: RecipeJson.java    From Cubes with MIT License 5 votes vote down vote up
public static ItemStack parseStack(JsonValue json) {
  if (json.isString()) {
    return new ItemStack(getItem(json.asString()));
  } else if (json.isObject()) {
    JsonObject obj = json.asObject();
    JsonValue id = obj.get("id");
    if (id == null) throw new JsonException("No id");
    return new ItemStack(getItem(id.asString()), obj.getInt("count", 1), obj.getInt("meta", 0));
  } else if (json.isNull()) {
    return null;
  }
  throw new JsonException("Invalid type " + json.toString());
}
 
Example 9
Source File: BlockJson.java    From Cubes with MIT License 5 votes vote down vote up
private ItemStackPlaceholder parseSingle(JsonObject p) {
  String id = p.getString("id", null);
  if (id == null) throw new JsonException("No itemstack id");
  int count = p.getInt("count", 1);
  int meta = p.getInt("meta", 0);
  return new ItemStackPlaceholder(id, count, meta);
}
 
Example 10
Source File: Player.java    From microrts with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructs a Player from a JSON object
 * @param o
 * @return
 */
public static Player fromJSON(JsonObject o) {
    Player p = new Player(o.getInt("ID",-1),
                          o.getInt("resources",0));
    return p;
}
 
Example 11
Source File: PepperBoxLoadGenerator.java    From pepper-box with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve brokers from zookeeper servers
 *
 * @param properties
 * @return
 */
private String getBrokerServers(Properties properties) {

    StringBuilder kafkaBrokers = new StringBuilder();

    String zookeeperServers = properties.getProperty(ProducerKeys.ZOOKEEPER_SERVERS);

    if (zookeeperServers != null && !zookeeperServers.equalsIgnoreCase(ProducerKeys.ZOOKEEPER_SERVERS_DEFAULT)) {

        try {

            ZooKeeper zk = new ZooKeeper(zookeeperServers, 10000, null);
            List<String> ids = zk.getChildren(PropsKeys.BROKER_IDS_ZK_PATH, false);

            for (String id : ids) {

                String brokerInfo = new String(zk.getData(PropsKeys.BROKER_IDS_ZK_PATH + "/" + id, false, null));
                JsonObject jsonObject = Json.parse(brokerInfo).asObject();

                String brokerHost = jsonObject.getString(PropsKeys.HOST, "");
                int brokerPort = jsonObject.getInt(PropsKeys.PORT, -1);

                if (!brokerHost.isEmpty() && brokerPort != -1) {

                    kafkaBrokers.append(brokerHost);
                    kafkaBrokers.append(":");
                    kafkaBrokers.append(brokerPort);
                    kafkaBrokers.append(",");

                }

            }
        } catch (IOException | KeeperException | InterruptedException e) {

            LOGGER.log(Level.SEVERE, "Failed to get broker information", e);

        }

    }

    if (kafkaBrokers.length() > 0) {

        kafkaBrokers.setLength(kafkaBrokers.length() - 1);

        return kafkaBrokers.toString();

    } else {

        return properties.getProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG);

    }
}
 
Example 12
Source File: PepperBoxKafkaSampler.java    From pepper-box with Apache License 2.0 2 votes vote down vote up
private String getBrokerServers(JavaSamplerContext context) {

        StringBuilder kafkaBrokers = new StringBuilder();

        String zookeeperServers = context.getParameter(ProducerKeys.ZOOKEEPER_SERVERS);

        if (zookeeperServers != null && !zookeeperServers.equalsIgnoreCase(ProducerKeys.ZOOKEEPER_SERVERS_DEFAULT)) {

            try {

                ZooKeeper zk = new ZooKeeper(zookeeperServers, 10000, null);
                List<String> ids = zk.getChildren(PropsKeys.BROKER_IDS_ZK_PATH, false);

                for (String id : ids) {

                    String brokerInfo = new String(zk.getData(PropsKeys.BROKER_IDS_ZK_PATH + "/" + id, false, null));
                    JsonObject jsonObject = Json.parse(brokerInfo).asObject();

                    String brokerHost = jsonObject.getString(PropsKeys.HOST, "");
                    int brokerPort = jsonObject.getInt(PropsKeys.PORT, -1);

                    if (!brokerHost.isEmpty() && brokerPort != -1) {

                        kafkaBrokers.append(brokerHost);
                        kafkaBrokers.append(":");
                        kafkaBrokers.append(brokerPort);
                        kafkaBrokers.append(",");

                    }

                }
            } catch (IOException | KeeperException | InterruptedException e) {

                log.error("Failed to get broker information", e);

            }

        }

        if (kafkaBrokers.length() > 0) {

            kafkaBrokers.setLength(kafkaBrokers.length() - 1);

            return kafkaBrokers.toString();

        } else {

            return  context.getParameter(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG);

        }
    }