X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FBaseClass.java;h=26863902e59c8ec1447bbc44b9e1006b60843b5e;hp=abaa9ccbd37d04fe7a48fc8a2a57b8c59ebb267a;hb=0b6140e4a200c4952c9dc003d8389f375191564e;hpb=cf77cb3542f2aefbebdb9aa00b358dbeb4489a73 diff --git a/src/be/nikiroo/jvcard/BaseClass.java b/src/be/nikiroo/jvcard/BaseClass.java index abaa9cc..2686390 100644 --- a/src/be/nikiroo/jvcard/BaseClass.java +++ b/src/be/nikiroo/jvcard/BaseClass.java @@ -241,20 +241,37 @@ public abstract class BaseClass> implements List { /** * Get the recursive state of the current object, i.e., its children. It - * represents the full state information about this object's children. It - * does not check the state of the object itself. + * represents the full state information about this object's children. * * @return a {@link String} representing the current content state of this - * object, i.e., its children + * object, i.e., its children included */ public String getContentState() { StringBuilder builder = new StringBuilder(); + buildContentStateRaw(builder); + return StringUtils.getHash(builder.toString()); + } + /** + * Return the (first) child element with the given ID or NULL if not found. + * + * @param id + * the id to look for + * + * @return the child element or NULL + */ + public E getById(String id) { for (E child : this) { - builder.append(child.getContentState()); + if (id == null) { + if (child.getId() == null) + return child; + } else { + if (id.equals(child.getId())) + return child; + } } - return StringUtils.getHash(builder.toString()); + return null; } /** @@ -275,6 +292,23 @@ public abstract class BaseClass> implements List { */ abstract public String getState(); + /** + * Get the recursive state of the current object, i.e., its children. It + * represents the full state information about this object's children. + * + * It is not hashed. + * + * @param builder + * the {@link StringBuilder} that will represent the current + * content state of this object, i.e., its children included + */ + void buildContentStateRaw(StringBuilder builder) { + builder.append(getState()); + for (E child : this) { + child.buildContentStateRaw(builder); + } + } + /** * Notify that this element has unsaved changes. */