Example usage for com.google.gwt.json.client JSONNumber doubleValue

List of usage examples for com.google.gwt.json.client JSONNumber doubleValue

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONNumber doubleValue.

Prototype

public double doubleValue() 

Source Link

Document

Gets the double value this JSONNumber represents.

Usage

From source file:lh.api.showcase.client.JsonParserUtils.java

License:Apache License

public static Airport getAirportInfo(JSONObject jsAirportObj) {

    JSONValue jsAirportCodeVal = jsAirportObj.get("AirportCode");
    JSONValue jsCityCodeVal = jsAirportObj.get("CityCode");
    JSONValue jsCountryCodeVal = jsAirportObj.get("CountryCode");
    JSONValue jsLocationTypeVal = jsAirportObj.get("LocationType");

    if (jsAirportCodeVal == null || jsCityCodeVal == null || jsCountryCodeVal == null
            || jsLocationTypeVal == null) {
        return null;
    }//from  www . j  a v  a 2s. c  o m
    JSONString jsAirportCodeStr = jsAirportCodeVal.isString();
    JSONString jsCityCodeStr = jsCityCodeVal.isString();
    JSONString jsCountryCodeStr = jsCountryCodeVal.isString();
    JSONString jsLocationTypeStr = jsLocationTypeVal.isString();

    JSONObject jsCoordinateObj = jsAirportObj.get("Position").isObject().get("Coordinate").isObject();
    JSONNumber jsLatitudeNum = jsCoordinateObj.get("Latitude").isNumber();
    JSONNumber jsLongitudeNum = jsCoordinateObj.get("Longitude").isNumber();

    JSONObject jsNamesObj = jsAirportObj.get("Names").isObject();

    return new Airport((jsAirportCodeStr == null) ? ("") : (jsAirportCodeStr.toString().replace("\"", "")),
            (jsCityCodeStr == null) ? ("") : (jsCityCodeStr.toString().replace("\"", "")),
            (jsCountryCodeStr == null) ? ("") : (jsCountryCodeStr.toString().replace("\"", "")),
            (jsLocationTypeStr == null) ? ("") : (jsLocationTypeStr.toString().replace("\"", "")),
            jsLatitudeNum.doubleValue(), jsLongitudeNum.doubleValue(), JsonParserUtils.getNamesMap(jsNamesObj));

}

From source file:lh.api.showcase.client.JsonParserUtils.java

License:Apache License

public static String getAircraftCode(JSONValue jsAircraftCodeVal) {
    if (jsAircraftCodeVal == null) {
        return null;
    }/*from   ww w  .j  a v  a  2  s.c  o  m*/
    JSONString jsAircraftCodeStr = jsAircraftCodeVal.isString();
    JSONNumber jsAircraftCodeNum = null;
    if (jsAircraftCodeStr == null) {
        jsAircraftCodeNum = jsAircraftCodeVal.isNumber();
    }
    return (jsAircraftCodeStr != null) ? (jsAircraftCodeStr.toString().replace("\"", ""))
            : ((jsAircraftCodeNum != null) ? (String.valueOf(jsAircraftCodeNum.doubleValue())) : (""));
}

From source file:lh.api.showcase.client.operations.JsonParserFlightUtils.java

License:Apache License

public static Flight getFlightInfo(JSONObject jsFlightObj) {

    if (jsFlightObj == null) {
        return null;
    }//from  w w  w .j  a  va  2s . com

    // departure
    JSONObject jsDepartureObj = jsFlightObj.get("Departure").isObject();
    Flight.FlightNode flightNodeDeparture = getFlightNodeInfo(jsDepartureObj);
    Flight.Departure departure = null;
    if (flightNodeDeparture != null) {
        departure = new Flight.Departure(flightNodeDeparture);
    }

    // arrival
    JSONObject jsArrivalObj = jsFlightObj.get("Arrival").isObject();
    Flight.FlightNode flightNodeArrival = getFlightNodeInfo(jsArrivalObj);
    Flight.Arrival arrival = null;
    if (flightNodeDeparture != null) {
        arrival = new Flight.Arrival(flightNodeArrival);
    }

    // aircraft code
    String aircraftCode = JsonParserUtils
            .getAircraftCode(jsFlightObj.get("Equipment").isObject().get("AircraftCode"));

    //MarketingCarrier
    JSONObject jsMarketingCarrierObj = jsFlightObj.get("MarketingCarrier").isObject();
    JSONString jsAirlineIdStr = jsMarketingCarrierObj.get("AirlineID").isString();

    JSONString jsFlightNumberStr = jsMarketingCarrierObj.get("FlightNumber").isString();
    JSONNumber jsFlightNumberNum = jsMarketingCarrierObj.get("FlightNumber").isNumber();

    String flightNumber = (jsFlightNumberStr != null) ? (jsFlightNumberStr.toString().replace("\"", ""))
            : ((jsFlightNumberNum != null) ? (String.valueOf(jsFlightNumberNum.doubleValue())) : (""));

    // details
    JSONValue jsDetailsVal = jsFlightObj.get("Details");
    JSONObject jsDetailsObj = null;
    if (jsDetailsVal != null) {
        jsDetailsObj = jsDetailsVal.isObject();
    }

    // flight status
    JSONString jsFlightStatusCodeStr = getStringIfExist(jsFlightObj, "FlightStatus", "Code");
    JSONString jsFlightStatusDefinitionStr = getStringIfExist(jsFlightObj, "FlightStatus", "Definition");

    return new Flight(departure, arrival, aircraftCode,
            (jsAirlineIdStr == null) ? ("") : (jsAirlineIdStr.toString().replace("\"", "")), flightNumber,
            getDetailsInfo(jsDetailsObj),
            new Flight.StatusCodeDefinition(
                    (jsFlightStatusCodeStr == null) ? (FlightStatusCode.NA.toString())
                            : (jsFlightStatusCodeStr.toString().replace("\"", "")),
                    (jsFlightStatusDefinitionStr == null) ? ("")
                            : (jsFlightStatusDefinitionStr.toString().replace("\"", ""))));
}

From source file:lh.api.showcase.client.operations.JsonParserFlightUtils.java

License:Apache License

private static Flight.Details getDetailsInfo(JSONObject jsDetailsObj) {
    if (jsDetailsObj == null) {
        return null;
    }/* w ww  .jav  a  2 s .  c  o  m*/
    JSONNumber jsStopsNumber = jsDetailsObj.get("Stops").isObject().get("StopQuantity").isNumber();
    JSONNumber jsDaysOfOperationNumber = jsDetailsObj.get("DaysOfOperation").isNumber();

    JSONObject jsDatePeriodObj = jsDetailsObj.get("DatePeriod").isObject();
    JSONString jsEffectiveStr = jsDatePeriodObj.get("Effective").isString();
    JSONString jsExpirationStr = jsDatePeriodObj.get("Expiration").isString();

    Flight.Details.Builder detailsBuilder = new Flight.Details.Builder();
    detailsBuilder.setStopQuantity(Long.valueOf((long) jsStopsNumber.doubleValue()))
            .setDaysOfOperation(String.valueOf(jsDaysOfOperationNumber.doubleValue()))
            .setEffectiveDateStr(
                    (jsEffectiveStr == null) ? ("") : (jsEffectiveStr.toString().replace("\"", "")))
            .setExpirationDateStr(
                    (jsExpirationStr == null) ? ("") : (jsExpirationStr.toString().replace("\"", "")));

    return detailsBuilder.build();
}

From source file:lh.api.showcase.client.operations.JsonParserFlightUtils.java

License:Apache License

private static Flight.FlightNode getFlightNodeInfo(JSONObject jsNodeObj) {
    if (jsNodeObj == null) {
        return null;
    }//www .ja  va 2s  .  c o  m
    JSONString jsAirportCodeStr = jsNodeObj.get("AirportCode").isString();

    JSONString jsScheduledTimeLocalStr = jsNodeObj.get("ScheduledTimeLocal").isObject().get("DateTime")
            .isString();
    JSONString jsScheduledTimeUtcStr = getStringIfExist(jsNodeObj, "ScheduledTimeUTC", "DateTime");

    JSONString jsEstimatedOrActualTimeLocalStr = getStringIfExist(jsNodeObj, "EstimatedTimeLocal",
            "ActualTimeLocal", "DateTime");
    JSONString jsEstimatedOrActualTimeUtcStr = getStringIfExist(jsNodeObj, "EstimatedTimeUTC", "ActualTimeUTC",
            "DateTime");

    JSONString jsTimeStatusCodeStr = getStringIfExist(jsNodeObj, "TimeStatus", "Code");
    JSONString jsTimeStatusDefinitionStr = getStringIfExist(jsNodeObj, "TimeStatus", "Definition");

    JSONString jsTerminalGateStr = getStringIfExist(jsNodeObj, "Terminal", "Gate");

    JSONString jsTerminalStr = getStringIfExist(jsNodeObj, "Terminal", "Name");
    JSONNumber jsTerminalNum = getNumberIfExist(jsNodeObj, "Terminal", "Name");

    String terminal = (jsTerminalStr != null) ? (jsTerminalStr.toString().replace("\"", ""))
            : ((jsTerminalNum != null) ? (String.valueOf(jsTerminalNum.doubleValue())) : (""));

    Flight.FlightNode.Builder flightNodeBuilder = new Flight.FlightNode.Builder();
    flightNodeBuilder
            .setAirportCode((jsAirportCodeStr == null) ? ("") : (jsAirportCodeStr.toString().replace("\"", "")))
            .setScheduledTimeLocal((jsScheduledTimeLocalStr == null) ? ("")
                    : (jsScheduledTimeLocalStr.toString().replace("\"", "")))
            .setScheduledTimeUtc((jsScheduledTimeUtcStr == null) ? ("")
                    : (jsScheduledTimeUtcStr.toString().replace("\"", "")))
            .setEstimatedOrActualTimeLocal((jsEstimatedOrActualTimeLocalStr == null) ? ("")
                    : (jsEstimatedOrActualTimeLocalStr.toString().replace("\"", "")))
            .setEstimatedOrActualTimeUtc((jsEstimatedOrActualTimeUtcStr == null) ? ("")
                    : (jsEstimatedOrActualTimeUtcStr.toString().replace("\"", "")))
            .setTimeStatus(new Flight.StatusCodeDefinition(
                    (jsTimeStatusCodeStr == null) ? (TimeStatusCode.NO.toString())
                            : (jsTimeStatusCodeStr.toString().replace("\"", "")),
                    (jsTimeStatusDefinitionStr == null) ? ("")
                            : (jsTimeStatusDefinitionStr.toString().replace("\"", ""))))
            .setTerminal(terminal).setTerminalGate(
                    (jsTerminalGateStr == null) ? ("") : (jsTerminalGateStr.toString().replace("\"", "")));

    return flightNodeBuilder.build();
}

From source file:lh.api.showcase.client.referencedata.cities.CitiesResponseJsonParser.java

License:Apache License

private City getCityInfo(JSONObject jsCityObj) {
    JSONValue jsCityCodeVal = jsCityObj.get("CityCode");
    JSONValue jsCountryCodeVal = jsCityObj.get("CountryCode");

    if (jsCityCodeVal == null || jsCountryCodeVal == null) {
        return null;
    }//w w  w.  j  a v  a 2  s .com
    JSONString jsCityCodeStr = jsCityCodeVal.isString();
    JSONString jsCountryCodeStr = jsCountryCodeVal.isString();

    JSONNumber jsLatitudeNum = null;
    JSONNumber jsLongitudeNum = null;
    JSONValue jsCoordinateVal = jsCityObj.get("Position");
    if (jsCoordinateVal != null) {
        JSONObject jsCoordinateObj = jsCoordinateVal.isObject().get("Coordinate").isObject();
        jsLatitudeNum = jsCoordinateObj.get("Latitude").isNumber();
        jsLongitudeNum = jsCoordinateObj.get("Longitude").isNumber();
    }

    JSONObject jsNamesObj = jsCityObj.get("Names").isObject();

    JSONValue jsAirportsVal = jsCityObj.get("Airports");
    JSONObject jsAirportsObj = (jsAirportsVal == null) ? (null) : (jsAirportsVal.isObject());

    return new City((jsCityCodeStr == null) ? ("") : (jsCityCodeStr.toString().replace("\"", "")),
            (jsCountryCodeStr == null) ? ("") : (jsCountryCodeStr.toString().replace("\"", "")),
            (jsLatitudeNum == null) ? (null) : (jsLatitudeNum.doubleValue()),
            (jsLongitudeNum == null) ? (null) : (jsLongitudeNum.doubleValue()), getAirportInfo(jsAirportsObj),
            JsonParserUtils.getNamesMap(jsNamesObj));
}

From source file:lh.api.showcase.client.referencedata.nearestairports.NearestAirportsResponseJsonParser.java

License:Apache License

private NearestAirport getNearestAirportInfo(JSONObject jsAirportObj) {

    Airport airport = JsonParserUtils.getAirportInfo(jsAirportObj);
    if (airport != null) {

        JSONObject jsProximityVal = jsAirportObj.get("Distance").isObject();
        JSONNumber jsDistanceNum = jsProximityVal.get("Value").isNumber();
        JSONString jsUomStr = jsProximityVal.get("UOM").isString();

        return new NearestAirport(airport, jsDistanceNum.doubleValue(), jsUomStr.toString().replace("\"", ""));
    }/*from w  w w.j  a  v a  2s. c o m*/
    return null;
}

From source file:net.opentsdb.tsd.client.QueryUi.java

License:Open Source License

private void refreshVersion() {
    asyncGetJson(VERSION_URL, new GotJsonCallback() {
        public void got(final JSONValue json) {
            final JSONObject bd = json.isObject();
            final JSONString shortrev = bd.get("short_revision").isString();
            final JSONString status = bd.get("repo_status").isString();
            final JSONNumber stamp = bd.get("timestamp").isNumber();
            final JSONString user = bd.get("user").isString();
            final JSONString host = bd.get("host").isString();
            final JSONString repo = bd.get("repo").isString();
            build_data.setHTML("OpenTSDB built from revision " + shortrev.stringValue() + " in a "
                    + status.stringValue() + " state<br/>" + "Built on "
                    + new Date((long) (stamp.doubleValue() * 1000)) + " by " + user.stringValue() + '@'
                    + host.stringValue() + ':' + repo.stringValue());
        }/* w  w  w .j a v  a 2 s . co m*/
    });
}

From source file:org.apache.solr.explorer.client.util.json.JSONUtils.java

License:Apache License

/**
 * Converts JSON value to integer./*w ww  .  j  av  a2  s .co  m*/
 *
 * @param jsonValue the JSON value.
 * @return the integer value.
 */
public static Integer jsonValueToInt(JSONValue jsonValue) {
    JSONNumber number = jsonValue.isNumber();
    if (number == null) {
        throw new JSONException("Not an integer: " + jsonValue);
    } else {
        return new Double(number.doubleValue()).intValue();
    }
}

From source file:org.apache.solr.explorer.client.util.json.JSONUtils.java

License:Apache License

/**
 * Converts JSON value to long./*ww w .ja v a2 s .c  o  m*/
 *
 * @param jsonValue the JSON value.
 * @return the integer value.
 */
public static Long jsonValueToLong(JSONValue jsonValue) {
    JSONNumber number = jsonValue.isNumber();
    if (number == null) {
        throw new JSONException("Not a long: " + jsonValue);
    } else {
        return new Double(number.doubleValue()).longValue();
    }
}