public Document stateToBson(State state) { Document doc = new Document(); for (Entry<String, Serializable> en : state.entrySet()) { Object val = valueToBson(en.getValue()); if (val != null) { doc.put(keyToBson(en.getKey()), val); } } return doc; }
/** * Makes a deep copy of a {@link State} map, optionally thread-safe. * * @param threadSafe if {@code true}, then thread-safe datastructures are used */ public static State deepCopy(State state, boolean threadSafe) { State copy = new State(state.size(), threadSafe); for (Entry<String, Serializable> en : state.entrySet()) { copy.put(en.getKey(), deepCopy(en.getValue(), threadSafe)); } return copy; }
/** * Changes the deltas stored into actual full values. * * @since 6.0 */ public static void resetDeltas(State state) { if (Boolean.parseBoolean(Framework.getProperty(DISABLED_DELTA_PROP, "false"))) { return; } for (Entry<String, Serializable> en : state.entrySet()) { Serializable value = en.getValue(); if (value instanceof State) { resetDeltas((State) value); } else if (value instanceof Delta) { state.put(en.getKey(), ((Delta) value).getFullValue()); } } }
/** * Compares two {@link State}s. */ public static boolean equalsStrict(State a, State b) { if (a == b) { return true; } if (a == null || b == null) { return false; } if (a.size() != b.size()) { return false; } if (!a.keySet().equals(b.keySet())) { return false; } for (Entry<String, Serializable> en : a.entrySet()) { String key = en.getKey(); Serializable va = en.getValue(); Serializable vb = b.get(key); if (!equalsStrict(va, vb)) { return false; } } return true; }
for (Entry<String, Serializable> es : state.entrySet()) { fieldMap.put(es.getKey(), es.getValue());