List of usage examples for com.google.gson JsonObject equals
@Override public boolean equals(Object o)
From source file:com.ca.dvs.utilities.raml.JsonUtil.java
License:Open Source License
/** * Compare two JSON strings/*ww w. ja va 2 s .c om*/ * @param json1 the first of two JSON objects to compare * @param json2 the second of two JSON objects to compare * @return true when the JSON strings compare favorably, otherwise false */ public static boolean equals(String json1, String json2) { boolean match = false; if (null != json1 && null != json2) { JsonParser parser = new JsonParser(); Object obj1 = parser.parse(json1); Object obj2 = parser.parse(json2); if (obj1 instanceof JsonObject && obj2 instanceof JsonObject) { JsonObject jObj1 = (JsonObject) obj1; JsonObject jObj2 = (JsonObject) obj2; match = jObj1.equals(jObj2); } else if (obj1 instanceof JsonArray && obj2 instanceof JsonArray) { JsonArray jAry1 = (JsonArray) obj1; JsonArray jAry2 = (JsonArray) obj2; match = jAry1.equals(jAry2); } } return match; }
From source file:com.ibm.iotf.devicemgmt.device.DeviceActionHandler.java
License:Open Source License
@Override public void run() { final String METHOD = "run"; running = true;/*from www. j a v a2s. co m*/ while (running) { try { JsonObject o = queue.take(); if (o.equals(dummy)) { LoggerUtility.info(CLASS_NAME, METHOD, "Is it time to quit?"); } else { String action = o.get("action").getAsString(); if (action.equals(REBOOT_ACTION)) { LoggerUtility.info(CLASS_NAME, METHOD, "Invoking reboot handler"); handleReboot(this.device.getDeviceAction()); device.getDeviceAction().fireEvent(DeviceAction.REBOOT_STOP); } else if (action.equals(FACTORY_RESET_ACTION)) { LoggerUtility.info(CLASS_NAME, METHOD, "Invoking factory reset handler"); handleFactoryReset(this.device.getDeviceAction()); device.getDeviceAction().fireEvent(DeviceAction.FACTORY_RESET_STOP); } } } catch (InterruptedException e) { LoggerUtility.severe(CLASS_NAME, METHOD, "Unexpected exception " + e.getMessage()); } } LoggerUtility.info(CLASS_NAME, METHOD, "Exiting..."); }
From source file:com.ibm.iotf.devicemgmt.device.DeviceFirmwareHandler.java
License:Open Source License
@Override public void run() { final String METHOD = "run"; running = true;//from ww w . ja va2 s.c o m while (running) { try { JsonObject o = queue.take(); if (o.equals(dummy)) { LoggerUtility.info(CLASS_NAME, METHOD, "Is it time to quit?"); } else { String action = o.get("action").getAsString(); if (action.equals(FIRMWARE_DOWNLOAD)) { LoggerUtility.info(CLASS_NAME, METHOD, "starting download firmware"); device.getDeviceFirmware().setState(FirmwareState.DOWNLOADING); downloadFirmware(device.getDeviceFirmware()); } else if (action.equals(FIRMWARE_UPDATE)) { LoggerUtility.info(CLASS_NAME, METHOD, "starting firmware update"); device.getDeviceFirmware().setUpdateStatus(FirmwareUpdateStatus.IN_PROGRESS); updateFirmware(device.getDeviceFirmware()); device.getDeviceFirmware().setState(FirmwareState.IDLE); if (device.getDeviceFirmware().getUpdateStatus() == FirmwareUpdateStatus.SUCCESS .getStatus()) { String version = device.getDeviceFirmware().getVersion(); if (null != version && !("".equals(version))) { device.getDeviceInfo().setFwVersion(version); } } } } } catch (InterruptedException e) { LoggerUtility.severe(CLASS_NAME, METHOD, "Unexpected exception " + e.getMessage()); } } LoggerUtility.info(CLASS_NAME, METHOD, "Exiting..."); }
From source file:com.ibm.iotf.devicemgmt.device.ManagedDevice.java
License:Open Source License
@Override public void run() { final String METHOD = "run"; running = true;/*from w w w. j av a 2 s . com*/ LoggerUtility.log(Level.FINE, CLASS_NAME, METHOD, "Running..."); while (running) { try { JsonObject o = publishQueue.take(); if (o.equals(dummy)) { LoggerUtility.log(Level.FINE, CLASS_NAME, METHOD, "It is time to quit."); } else { publish(o); } } catch (Exception e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); e.printStackTrace(); running = false; } } LoggerUtility.log(Level.FINE, CLASS_NAME, METHOD, "Exiting..."); }
From source file:com.plnyyanks.frcnotebook.database.DatabaseHandler.java
License:Open Source License
public void importDatabase(JsonObject data) { if (data == null || data.equals(new JsonObject())) return;/*from w w w .ja v a2 s. co m*/ JsonElement e; e = data.get(TABLE_EVENTS); if (e != null) importEvents(e.getAsJsonArray()); e = data.get(TABLE_MATCHES); if (e != null) importMatches(e.getAsJsonArray()); e = data.get(TABLE_TEAMS); if (e != null) importTeams(e.getAsJsonArray()); e = data.get(TABLE_NOTES); if (e != null) importNotes(e.getAsJsonArray()); if (tableExists(TABLE_PREDEF_NOTES)) { try { e = data.get(TABLE_PREDEF_NOTES); if (e != null) importDefNotes(e.getAsJsonArray()); } catch (Exception ex) { } } }
From source file:de.dfki.mmf.input.worldmodel.WorldObjectConeIntersectionCalculator.java
License:Open Source License
/** * * @param worldProperties/*ww w . j a v a 2 s . c o m*/ * @return map containing for each objects those objects whose cone intersect with the object's cone */ public Map<JsonObject, List<JsonObject>> calculateObjectsConeIntersection(List<JsonObject> worldProperties) { //a cone is the area from the robot's position to the world object with certain radius around the world object //map for saving for each object those objects those cones intersect with the object Map<JsonObject, List<JsonObject>> coneIntersectionMap = new HashMap<>(); //get position of robot Position robotPosition = WorldModel.getRobotModel().getRobotPosition(); if (robotPosition == null) { return new HashMap<>(); } for (JsonObject worldObject : worldProperties) { Position worldObjectPosition = null; //get position of current world object if (worldObject.has("xposition") && worldObject.has("yposition") && worldObject.has("zposition")) { double xPos = worldObject.get("xposition").getAsDouble(); double yPos = worldObject.get("yposition").getAsDouble(); double zPos = worldObject.get("zposition").getAsDouble(); worldObjectPosition = new Position(xPos, yPos, zPos); } else if (worldObject.has("position")) { JsonObject innerObject = worldObject.get("position").getAsJsonObject(); if (innerObject.has("xposition") && innerObject.has("yposition") && innerObject.has("zposition")) { double xPos = innerObject.get("xposition").getAsDouble(); double yPos = innerObject.get("yposition").getAsDouble(); double zPos = innerObject.get("zposition").getAsDouble(); worldObjectPosition = new Position(xPos, yPos, zPos); } } if (worldObjectPosition != null) { //list to save objects whose cones intersect with the current one's cone ArrayList<JsonObject> coneIntersectionList = new ArrayList<>(); double worldObjectRadius; //check if certain radius is given for the current world object if (worldObject.has("proximityradius")) { worldObjectRadius = worldObject.get("proximityradius").getAsDouble(); //if not: calculate radius based on the size of the object -> if no size is given: assume small size } else { String sizeSpecification = ""; if (worldObject.has("worldobjectsizecategory")) { sizeSpecification = worldObject.get("worldobjectsizecategory").getAsString(); } worldObjectRadius = calculateProximityRadius(worldObjectPosition, robotPosition, sizeSpecification); } //go through other objects for (JsonObject otherObject : worldProperties) { if (!worldObject.equals(otherObject)) { Position otherObjectPosition = null; //get position of other world object if (otherObject.has("xposition") && otherObject.has("yposition") && otherObject.has("zposition")) { double xPos = otherObject.get("xposition").getAsDouble(); double yPos = otherObject.get("yposition").getAsDouble(); double zPos = otherObject.get("zposition").getAsDouble(); otherObjectPosition = new Position(xPos, yPos, zPos); } else if (otherObject.has("position")) { JsonObject innerObject = otherObject.get("position").getAsJsonObject(); if (innerObject.has("xposition") && innerObject.has("yposition") && innerObject.has("zposition")) { double xPos = innerObject.get("xposition").getAsDouble(); double yPos = innerObject.get("yposition").getAsDouble(); double zPos = innerObject.get("zposition").getAsDouble(); otherObjectPosition = new Position(xPos, yPos, zPos); } } if (otherObjectPosition != null) { double otherObjectRadius; //check if certain radius is given for the other world object if (otherObject.has("proximityradius")) { otherObjectRadius = otherObject.get("proximityradius").getAsDouble(); //if not: calculate radius based on the size of the object -> if no size is given: assume small size } else { String sizeSpecification = ""; if (otherObject.has("worldobjectsizecategory")) { sizeSpecification = otherObject.get("worldobjectsizecategory").getAsString(); } otherObjectRadius = calculateProximityRadius(otherObjectPosition, robotPosition, sizeSpecification); } //check if the cones of the two objects intersect -> if so, add other object to list if (HasConeIntersection(worldObjectPosition, otherObjectPosition, robotPosition, worldObjectRadius, otherObjectRadius)) { coneIntersectionList.add(otherObject); } } } } coneIntersectionMap.put(worldObject, coneIntersectionList); } } return coneIntersectionMap; }
From source file:org.ballerinalang.langserver.formatting.FormattingSourceGen.java
License:Open Source License
private static List<JsonObject> unify(List<JsonObject> toBeUnified) { List<JsonObject> unified = new ArrayList<>(); JsonObject prevWS = null; for (JsonObject wsItem : toBeUnified) { if (prevWS == null) { prevWS = wsItem;/*from w w w . ja v a 2s . com*/ unified.add(prevWS); } else if (prevWS.get("i").getAsInt() != wsItem.get("i").getAsInt() && !prevWS.equals(wsItem)) { unified.add(wsItem); prevWS = wsItem; } } return unified; }
From source file:org.fenixedu.academic.api.infra.FenixAPIFromExternalServer.java
License:Open Source License
private static JsonObject getInformation(String url, String filename) { logger.debug("get file info for \"{}\"", filename); JsonObject infoJson = getFileInfo(filename).getAsJsonObject(); if (!infoJson.equals(empty)) { logger.debug("file info exists"); return infoJson; }/* w w w. java2s. c o m*/ logger.debug("file or file info for \"{}\" doesn't exist, let's try url : {}", filename, url); try { Response response = HTTP_CLIENT.target(url).request(MediaType.APPLICATION_JSON) .header("Authorization", getServiceAuth()).get(); if (response.getStatus() == 200) { infoJson = parser.parse(response.readEntity(String.class)).getAsJsonObject(); logger.debug("got info from url {}, return it. ", url); } else { logger.debug("url errored and returned {}", response.getStatus()); infoJson = empty; } } catch (ProcessingException | JsonSyntaxException e) { logger.debug("http error or json parsing error : {}", e.getLocalizedMessage()); infoJson = empty; } return infoJson; }
From source file:org.jboss.weld.logging.LogMessageIndexDiff.java
License:Apache License
private boolean areMessagesEqual(JsonObject msg1, JsonObject msg2) { List<String> suppressions = extractSuppressions(msg1); suppressions.addAll(extractSuppressions(msg2)); if (!suppressions.isEmpty()) { // Make a copy of JSON representations first JsonParser parser = new JsonParser(); msg1 = parser.parse(msg1.toString()).getAsJsonObject(); msg2 = parser.parse(msg2.toString()).getAsJsonObject(); msg1.remove(SUPPRESSIONS);/*w w w. ja va 2 s . c o m*/ msg2.remove(SUPPRESSIONS); // Then remove all suppressed members // E.g. for @SuppressWarnings("weldlog:msg-value") we'd like to remove msgObj.msg.value for (String suppression : suppressions) { String[] suppressionParts = suppression.substring(SUPPRESS_WARNINGS_PREFIX.length()).split("-"); removeSuppressedMember(msg1, suppressionParts); removeSuppressedMember(msg2, suppressionParts); } } return msg1.equals(msg2); }
From source file:org.mitre.openid.connect.request.ConnectOAuth2RequestFactory.java
License:Apache License
/** * * @param jwtString/*from www. ja va 2s .c om*/ * @param request */ private void processRequestObject(String jwtString, AuthorizationRequest request) { // parse the request object try { JWT jwt = JWTParser.parse(jwtString); if (jwt instanceof SignedJWT) { // it's a signed JWT, check the signature SignedJWT signedJwt = (SignedJWT) jwt; // need to check clientId first so that we can load the client to check other fields if (request.getClientId() == null) { request.setClientId(signedJwt.getJWTClaimsSet().getStringClaim(CLIENT_ID)); } ClientDetailsEntity client = clientDetailsService.loadClientByClientId(request.getClientId()); if (client == null) { throw new InvalidClientException("Client not found: " + request.getClientId()); } JWSAlgorithm alg = signedJwt.getHeader().getAlgorithm(); if (client.getRequestObjectSigningAlg() == null || !client.getRequestObjectSigningAlg().equals(alg)) { throw new InvalidClientException("Client's registered request object signing algorithm (" + client.getRequestObjectSigningAlg() + ") does not match request object's actual algorithm (" + alg.getName() + ")"); } JWTSigningAndValidationService validator = validators.getValidator(client, alg); if (validator == null) { throw new InvalidClientException( "Unable to create signature validator for client " + client + " and algorithm " + alg); } if (!validator.validateSignature(signedJwt)) { throw new InvalidClientException( "Signature did not validate for presented JWT request object."); } } else if (jwt instanceof PlainJWT) { PlainJWT plainJwt = (PlainJWT) jwt; // need to check clientId first so that we can load the client to check other fields if (request.getClientId() == null) { request.setClientId(plainJwt.getJWTClaimsSet().getStringClaim(CLIENT_ID)); } ClientDetailsEntity client = clientDetailsService.loadClientByClientId(request.getClientId()); if (client == null) { throw new InvalidClientException("Client not found: " + request.getClientId()); } if (client.getRequestObjectSigningAlg() == null) { throw new InvalidClientException( "Client is not registered for unsigned request objects (no request_object_signing_alg registered)"); } else if (!client.getRequestObjectSigningAlg().equals(Algorithm.NONE)) { throw new InvalidClientException( "Client is not registered for unsigned request objects (request_object_signing_alg is " + client.getRequestObjectSigningAlg() + ")"); } // if we got here, we're OK, keep processing } else if (jwt instanceof EncryptedJWT) { EncryptedJWT encryptedJWT = (EncryptedJWT) jwt; // decrypt the jwt if we can encryptionService.decryptJwt(encryptedJWT); // TODO: what if the content is a signed JWT? (#525) if (!encryptedJWT.getState().equals(State.DECRYPTED)) { throw new InvalidClientException("Unable to decrypt the request object"); } // need to check clientId first so that we can load the client to check other fields if (request.getClientId() == null) { request.setClientId(encryptedJWT.getJWTClaimsSet().getStringClaim(CLIENT_ID)); } ClientDetailsEntity client = clientDetailsService.loadClientByClientId(request.getClientId()); if (client == null) { throw new InvalidClientException("Client not found: " + request.getClientId()); } } /* * NOTE: Claims inside the request object always take precedence over those in the parameter map. */ // now that we've got the JWT, and it's been parsed, validated, and/or decrypted, we can process the claims JWTClaimsSet claims = jwt.getJWTClaimsSet(); Set<String> responseTypes = OAuth2Utils.parseParameterList(claims.getStringClaim(RESPONSE_TYPE)); if (!responseTypes.isEmpty()) { if (!responseTypes.equals(request.getResponseTypes())) { logger.info( "Mismatch between request object and regular parameter for response_type, using request object"); } request.setResponseTypes(responseTypes); } String redirectUri = claims.getStringClaim(REDIRECT_URI); if (redirectUri != null) { if (!redirectUri.equals(request.getRedirectUri())) { logger.info( "Mismatch between request object and regular parameter for redirect_uri, using request object"); } request.setRedirectUri(redirectUri); } String state = claims.getStringClaim(STATE); if (state != null) { if (!state.equals(request.getState())) { logger.info( "Mismatch between request object and regular parameter for state, using request object"); } request.setState(state); } String nonce = claims.getStringClaim(NONCE); if (nonce != null) { if (!nonce.equals(request.getExtensions().get(NONCE))) { logger.info( "Mismatch between request object and regular parameter for nonce, using request object"); } request.getExtensions().put(NONCE, nonce); } String display = claims.getStringClaim(DISPLAY); if (display != null) { if (!display.equals(request.getExtensions().get(DISPLAY))) { logger.info( "Mismatch between request object and regular parameter for display, using request object"); } request.getExtensions().put(DISPLAY, display); } String prompt = claims.getStringClaim(PROMPT); if (prompt != null) { if (!prompt.equals(request.getExtensions().get(PROMPT))) { logger.info( "Mismatch between request object and regular parameter for prompt, using request object"); } request.getExtensions().put(PROMPT, prompt); } Set<String> scope = OAuth2Utils.parseParameterList(claims.getStringClaim(SCOPE)); if (!scope.isEmpty()) { if (!scope.equals(request.getScope())) { logger.info( "Mismatch between request object and regular parameter for scope, using request object"); } request.setScope(scope); } JsonObject claimRequest = parseClaimRequest(claims.getStringClaim(CLAIMS)); if (claimRequest != null) { Serializable claimExtension = request.getExtensions().get(CLAIMS); if (claimExtension == null || !claimRequest.equals(parseClaimRequest(claimExtension.toString()))) { logger.info( "Mismatch between request object and regular parameter for claims, using request object"); } // we save the string because the object might not be a Java Serializable, and we can parse it easily enough anyway request.getExtensions().put(CLAIMS, claimRequest.toString()); } String loginHint = claims.getStringClaim(LOGIN_HINT); if (loginHint != null) { if (!loginHint.equals(request.getExtensions().get(LOGIN_HINT))) { logger.info( "Mistmatch between request object and regular parameter for login_hint, using requst object"); } request.getExtensions().put(LOGIN_HINT, loginHint); } } catch (ParseException e) { logger.error("ParseException while parsing RequestObject:", e); } }