@Override public State readPartialState(String id, Collection<String> keys) { if (id == null) { return null; } State state = states.get(id); if (state != null) { if (keys != null && !keys.isEmpty()) { State partialState = new State(); for (String key : keys) { Serializable value = state.get(key); if (value != null) { partialState.put(key, value); } } state = partialState; } if (log.isTraceEnabled()) { log.trace("Mem: READ " + id + ": " + state); } } return state; }
/** * 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; }
public State bsonToState(Document doc) { if (doc == null) { return null; } State state = new State(doc.keySet().size()); for (String key : doc.keySet()) { if (idKey == null && MONGODB_ID.equals(key)) { // skip native id if it's not mapped to something continue; } state.put(bsonToKey(key), bsonToValue(doc.get(key))); } return state; }
Serializable old = state.get(key); if (old == null) { old = new State(true); // thread-safe state.put(key, old);