From 6973ec9109fd2651e2284663b6c8039bd830a677 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Sat, 22 Sep 2018 21:07:43 +0100 Subject: Fix sonar problems in Apex Fixed some easy to resolve Sonar issues. Issue-ID: POLICY-1034 Change-Id: Ia8e4606bd4307daca499b4a74c96135211e572fd Signed-off-by: liamfallon --- .../context/schema/avro/AvroSchemaHelper.java | 40 ++++++++++++++-------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro') diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java index ed2b521c4..015d9ea30 100644 --- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java @@ -166,21 +166,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { private String getStringObject(final Object object) { try { if (isObjectString(object)) { - String objectString = object.toString().trim(); - if (objectString.length() == 0) { - return "\"\""; - } else if (objectString.length() == 1) { - return "\"" + objectString + "\""; - } else { - // All strings must be quoted for decoding - if (objectString.charAt(0) != '"') { - objectString = '"' + objectString; - } - if (objectString.charAt(objectString.length() - 1) != '"') { - objectString += '"'; - } - } - return objectString; + return getObjectString(object); } else { return (String) object; } @@ -194,6 +180,30 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { } } + /** + * Get a string object. + * + * @param object the string object + * @return the string + */ + private String getObjectString(final Object object) { + String objectString = object.toString().trim(); + if (objectString.length() == 0) { + return "\"\""; + } else if (objectString.length() == 1) { + return "\"" + objectString + "\""; + } else { + // All strings must be quoted for decoding + if (objectString.charAt(0) != '"') { + objectString = '"' + objectString; + } + if (objectString.charAt(objectString.length() - 1) != '"') { + objectString += '"'; + } + } + return objectString; + } + private boolean isObjectString(final Object object) { return object != null && avroSchema.getType().equals(Schema.Type.STRING); } -- cgit 1.2.3-korg