X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.server.io%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2Fio%2FJSONObjectUtils.java;fp=bundles%2Forg.simantics.document.server.io%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2Fio%2FJSONObjectUtils.java;h=558ee320459e519823852eac43d654763e90906f;hp=8913645a9946c3f4884fd4e8c5ae9f028afaea1a;hb=a0e3814041d624e3d72c21210d188e56439757aa;hpb=49178b3ca3e43a700298124de4adb7305c7092b7 diff --git a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/JSONObjectUtils.java b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/JSONObjectUtils.java index 8913645a9..558ee3204 100644 --- a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/JSONObjectUtils.java +++ b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/JSONObjectUtils.java @@ -13,6 +13,7 @@ package org.simantics.document.server.io; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -343,4 +344,72 @@ public class JSONObjectUtils { else return Collections.emptyList(); } + + @SuppressWarnings("unchecked") + public static Collection getTreeTableCell(IJSONObject object) { + try { + Object treeTableCells = object.getValue("tableCells"); + if (treeTableCells instanceof String) { + String tableCellsS = (String) treeTableCells; + if (tableCellsS.length() == 0) + return Collections.emptyList(); + } + if (treeTableCells != null) { + return (List) treeTableCells; + } else { + return Collections.emptyList(); + } + } catch (ClassCastException e) { + e.printStackTrace(); + } + return Collections.emptyList(); + } + + public static final boolean equalObjects(Object oldValue, Object newValue) { + if (newValue != null) { + if (newValue.getClass().isArray()) { + return arrayEquals(newValue, oldValue); + } else { + return newValue.equals(oldValue); + } + } else + return oldValue == null; + } + + + /** + * @param av1 an array (guaranteed) + * @param av2 any object + * @return true if the two arrays are equal + */ + private static final boolean arrayEquals(Object av1, Object av2) { + if (av2 == null) + return false; + Class c1 = av1.getClass().getComponentType(); + Class c2 = av2.getClass().getComponentType(); + if (c2 == null || !c1.equals(c2)) + return false; + boolean p1 = c1.isPrimitive(); + boolean p2 = c2.isPrimitive(); + if (p1 != p2) + return false; + if (!p1) + return Arrays.equals((Object[]) av1, (Object[]) av2); + if (boolean.class.equals(c1)) + return Arrays.equals((boolean[]) av1, (boolean[]) av2); + else if (byte.class.equals(c1)) + return Arrays.equals((byte[]) av1, (byte[]) av2); + else if (int.class.equals(c1)) + return Arrays.equals((int[]) av1, (int[]) av2); + else if (long.class.equals(c1)) + return Arrays.equals((long[]) av1, (long[]) av2); + else if (float.class.equals(c1)) + return Arrays.equals((float[]) av1, (float[]) av2); + else if (double.class.equals(c1)) + return Arrays.equals((double[]) av1, (double[]) av2); + throw new RuntimeException("Unsupported objects for equality testing ." + av1 + " vs. " + av2); + + } + + }