Skip to content

Commit

Permalink
Make new arrays mutable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghislain Fourny committed Jul 31, 2024
1 parent f225718 commit 57c0e2f
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/rumbledb/items/ItemFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,14 @@ public Item createArrayItem() {
return new ArrayItem();
}

public Item createArrayItem(List<Item> items) {
return new ArrayItem(items);
public Item createArrayItem(List<Item> items, boolean mutable) {
Item result = new ArrayItem(items);
if (mutable) {
result.setMutabilityLevel(0);
} else {
result.setMutabilityLevel(-1);
}
return result;
}

public Item createObjectItem(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/rumbledb/items/LazyObjectItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Item getItem() {
return ItemFactory.getInstance().createNullItem();
}
}
return ItemFactory.getInstance().createArrayItem(items);
return ItemFactory.getInstance().createArrayItem(items, true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/rumbledb/items/ObjectItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public ObjectItem(Map<String, List<Item>> keyValuePairs) {
List<Item> values = keyValuePairs.get(key);
// for each key, convert the lists of values into arrayItems
if (values.size() > 1) {
Item valuesArray = ItemFactory.getInstance().createArrayItem(values);
Item valuesArray = ItemFactory.getInstance().createArrayItem(values, false);
valueList.add(valuesArray);
} else if (values.size() == 1) {
Item value = values.get(0);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/rumbledb/items/parsing/ItemParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static Item getItemFromObject(JsonReader object, ExceptionMetadata metada
values.add(getItemFromObject(object, metadata));
}
object.endArray();
return ItemFactory.getInstance().createArrayItem(values);
return ItemFactory.getInstance().createArrayItem(values, false);
}
if (object.peek() == JsonToken.BEGIN_OBJECT) {
List<String> keys = new ArrayList<>();
Expand Down Expand Up @@ -203,7 +203,7 @@ public static Item getItemFromYAML(
// System.err.println("Next token (reading array): " + nt.toString());
}
// System.err.println("Finished reading array.");
return ItemFactory.getInstance().createArrayItem(values);
return ItemFactory.getInstance().createArrayItem(values, false);
}
if (lookahead.equals(com.fasterxml.jackson.core.JsonToken.START_OBJECT)) {
List<String> keys = new ArrayList<>();
Expand Down Expand Up @@ -595,7 +595,7 @@ private static Item convertValueToItem(
members.add(convertValueToItem(value, dataType, metadata, memberType));
}
}
Item item = ItemFactory.getInstance().createArrayItem(members);
Item item = ItemFactory.getInstance().createArrayItem(members, false);
if (itemType == null || itemType.equals(BuiltinTypesCatalogue.arrayItem)) {
return item;
} else {
Expand All @@ -615,7 +615,7 @@ private static Item convertValueToItem(
for (double value : denseVector.values()) {
members.add(ItemFactory.getInstance().createDoubleItem(value));
}
Item item = ItemFactory.getInstance().createArrayItem(members);
Item item = ItemFactory.getInstance().createArrayItem(members, false);
if (itemType == null || itemType.equals(BuiltinTypesCatalogue.arrayItem)) {
return item;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Item call(Item arg0) throws Exception {
for (String key : arg0.getKeys()) {
Item value = arg0.getItemByKey(key);
Item arrayValue = ItemFactory.getInstance()
.createArrayItem(new ArrayList<Item>(Collections.singletonList(value)));
.createArrayItem(new ArrayList<Item>(Collections.singletonList(value)), false);
keyValuePairs.put(key, new ArrayList<Item>(Collections.singletonList(arrayValue)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Item materializeFirstItemOrNull(
if (!this.children.isEmpty()) {
result.addAll(this.children.get(0).materialize(dynamicContext));
}
Item item = ItemFactory.getInstance().createArrayItem(result);
Item item = ItemFactory.getInstance().createArrayItem(result, true);
return item;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Item materializeFirstItemOrNull(DynamicContext dynamicContext) {
valueIterator.close();
// SIMILAR TO ZORBA, if value is more than one item, wrap it in an array
if (currentResults.size() > 1) {
values.add(ItemFactory.getInstance().createArrayItem(currentResults));
values.add(ItemFactory.getInstance().createArrayItem(currentResults, true));
} else if (currentResults.size() == 1) {
values.add(currentResults.get(0));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ private static Item validate(Item item, ItemType itemType, ExceptionMetadata met
}
Integer minLength = itemType.getMinLengthFacet();
Integer maxLength = itemType.getMaxLengthFacet();
Item arrayItem = ItemFactory.getInstance().createArrayItem(members);
Item arrayItem = ItemFactory.getInstance().createArrayItem(members, true);
if (itemType.getName() == null) {
itemType = itemType.getBaseType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public PendingUpdateList getPendingUpdateList(DynamicContext context) {
for (Item item : tempContent) {
copyContent.add((Item) SerializationUtils.clone(item));
}
content = ItemFactory.getInstance().createArrayItem(copyContent);
content = ItemFactory.getInstance().createArrayItem(copyContent, true);
}

UpdatePrimitiveFactory factory = UpdatePrimitiveFactory.getInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/rumbledb/server/RumbleHttpHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static Item assembleResponse(RumbleRuntimeConfiguration configuration, L
);
} else {
if (results != null) {
Item values = ItemFactory.getInstance().createArrayItem(results);
Item values = ItemFactory.getInstance().createArrayItem(results, false);
output.putItemByKey("values", values);
}
}
Expand Down

0 comments on commit 57c0e2f

Please sign in to comment.