diff --git a/json/src/main/java/org/openjdk/skara/json/JSONArray.java b/json/src/main/java/org/openjdk/skara/json/JSONArray.java index aaad0400c..a7d631683 100644 --- a/json/src/main/java/org/openjdk/skara/json/JSONArray.java +++ b/json/src/main/java/org/openjdk/skara/json/JSONArray.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,6 +39,24 @@ public JSONArray(JSONValue[] array) { } } + private void append(JSONValue value) { + if (value instanceof JSONArray) { + for (var v : value.asArray()) { + append(v); + } + } else { + this.values.add(value); + } + } + + public JSONArray(JSONValue value, JSONValue... values) { + this.values = new ArrayList(values.length + 1); + append(value); + for (var v : values) { + append(v); + } + } + public JSONArray(List values) { this.values = new ArrayList(values); } diff --git a/json/src/main/java/org/openjdk/skara/json/JSONBoolean.java b/json/src/main/java/org/openjdk/skara/json/JSONBoolean.java index 939de630c..1309d38f3 100644 --- a/json/src/main/java/org/openjdk/skara/json/JSONBoolean.java +++ b/json/src/main/java/org/openjdk/skara/json/JSONBoolean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ package org.openjdk.skara.json; public class JSONBoolean implements JSONValue { - boolean value; + private boolean value; public JSONBoolean(boolean value) { this.value = value; diff --git a/json/src/main/java/org/openjdk/skara/json/JSONDecimal.java b/json/src/main/java/org/openjdk/skara/json/JSONDecimal.java index 32c648a46..fe7e2fa04 100644 --- a/json/src/main/java/org/openjdk/skara/json/JSONDecimal.java +++ b/json/src/main/java/org/openjdk/skara/json/JSONDecimal.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ package org.openjdk.skara.json; public class JSONDecimal implements JSONValue { - double value; + private double value; public JSONDecimal(double value) { this.value = value; diff --git a/json/src/main/java/org/openjdk/skara/json/JSONNumber.java b/json/src/main/java/org/openjdk/skara/json/JSONNumber.java index 0e555d6fb..2a693c597 100644 --- a/json/src/main/java/org/openjdk/skara/json/JSONNumber.java +++ b/json/src/main/java/org/openjdk/skara/json/JSONNumber.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,11 +22,11 @@ */ package org.openjdk.skara.json; -class JSONNumber implements JSONValue { - long value; +public class JSONNumber implements JSONValue { + private long value; public JSONNumber(int value) { - this.value = (long) value; + this.value = value; } public JSONNumber(long value) { diff --git a/json/src/main/java/org/openjdk/skara/json/JSONObject.java b/json/src/main/java/org/openjdk/skara/json/JSONObject.java index 7c4aac27a..350d61c33 100644 --- a/json/src/main/java/org/openjdk/skara/json/JSONObject.java +++ b/json/src/main/java/org/openjdk/skara/json/JSONObject.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -109,6 +109,10 @@ public JSONObject putNull(String k) { return this; } + public JSONValue remove(String k) { + return value.remove(k); + } + public JSONValue get(String k) { return value.get(k); } @@ -128,6 +132,10 @@ public boolean contains(String field) { return value.containsKey(field); } + public Set keys() { + return value.keySet(); + } + @Override public String toString() { var builder = new StringBuilder(); diff --git a/json/src/main/java/org/openjdk/skara/json/JSONString.java b/json/src/main/java/org/openjdk/skara/json/JSONString.java index c03e199dc..41322ef28 100644 --- a/json/src/main/java/org/openjdk/skara/json/JSONString.java +++ b/json/src/main/java/org/openjdk/skara/json/JSONString.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,8 +22,8 @@ */ package org.openjdk.skara.json; -class JSONString implements JSONValue { - String value; +public class JSONString implements JSONValue { + private String value; public JSONString(String value) { this.value = value; diff --git a/json/src/main/java/org/openjdk/skara/json/JSONValue.java b/json/src/main/java/org/openjdk/skara/json/JSONValue.java index 89b18c3fd..e040d0d16 100644 --- a/json/src/main/java/org/openjdk/skara/json/JSONValue.java +++ b/json/src/main/java/org/openjdk/skara/json/JSONValue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -90,12 +90,12 @@ default List fields() { return asObject().fields(); } - default boolean contains(String field) { - return asObject().contains(field); + default boolean contains(String key) { + return asObject().contains(key); } - default JSONValue get(String field) { - return asObject().get(field); + default JSONValue get(String key) { + return asObject().get(key); } default JSONValue getOrDefault(String field, JSONValue fallback) {