@Test public void testInjectObjectsPathsInTheEnd() { List<String> relsExtPath = new ArrayList<String>() { { add("uuid:root"); add("uuid:monograph"); add("uuid:internalpart"); add("uuid:page"); } }; List<String> expecting = new ArrayList<String>() { { add("uuid:root"); add("uuid:monograph"); add("uuid:internalpart"); add("uuid:page"); add("uuid:subpage"); } }; ObjectPidsPath path = new ObjectPidsPath(relsExtPath.toArray(new String[relsExtPath.size()])); TestCase.assertEquals(relsExtPath, Arrays.asList(path.getPathFromRootToLeaf())); ObjectPidsPath npath = path.injectObjectBetween("uuid:subpage", new AbstractObjectPath.Between(null, "uuid:page")); String[] pathFromRootToLeaf = npath.getPathFromRootToLeaf(); Assert.assertEquals(expecting, Arrays.asList(pathFromRootToLeaf)); npath = path.injectObjectBetween("uuid:subpage", new AbstractObjectPath.Between("uuid:page", null)); pathFromRootToLeaf = npath.getPathFromRootToLeaf(); Assert.assertEquals(expecting, Arrays.asList(pathFromRootToLeaf)); }
@Override public ObjectPidsPath injectObjectBetween(String injectingObject, Between between) { if (between.getAfter() != null && between.getBefore() != null) { int bindex = Arrays.asList(this.pathFromRootToLeaf).indexOf(between.getBefore()); int aindex = Arrays.asList(this.pathFromRootToLeaf).indexOf(between.getAfter()); if (Math.abs(bindex - aindex) == 1) { return new ObjectPidsPath( injectInternal(injectingObject, Math.min(bindex, aindex), Math.max(bindex, aindex))); } else throw new IllegalArgumentException("ambiguous injecting"); } else { String object = between.getAfter() != null ? between.getAfter() : between.getBefore(); if (this.pathFromRootToLeaf[0].equals(object)) { String[] newpath = new String[this.pathFromRootToLeaf.length + 1]; newpath[0] = injectingObject; System.arraycopy(this.pathFromRootToLeaf, 0, newpath, 1, this.pathFromRootToLeaf.length); return new ObjectPidsPath(newpath); } else if (this.pathFromRootToLeaf[this.pathFromRootToLeaf.length - 1].equals(object)) { String[] newpath = new String[this.pathFromRootToLeaf.length + 1]; System.arraycopy(this.pathFromRootToLeaf, 0, newpath, 0, this.pathFromRootToLeaf.length); newpath[newpath.length - 1] = injectingObject; return new ObjectPidsPath(newpath); } else throw new IllegalArgumentException("ambiguous injecting"); } }
ObjectPidsPath extends AbstractObjectPath { @Override public ObjectPidsPath injectObjectBetween(String injectingObject, Between between) { if (between.getAfter() != null && between.getBefore() != null) { int bindex = Arrays.asList(this.pathFromRootToLeaf).indexOf(between.getBefore()); int aindex = Arrays.asList(this.pathFromRootToLeaf).indexOf(between.getAfter()); if (Math.abs(bindex - aindex) == 1) { return new ObjectPidsPath( injectInternal(injectingObject, Math.min(bindex, aindex), Math.max(bindex, aindex))); } else throw new IllegalArgumentException("ambiguous injecting"); } else { String object = between.getAfter() != null ? between.getAfter() : between.getBefore(); if (this.pathFromRootToLeaf[0].equals(object)) { String[] newpath = new String[this.pathFromRootToLeaf.length + 1]; newpath[0] = injectingObject; System.arraycopy(this.pathFromRootToLeaf, 0, newpath, 1, this.pathFromRootToLeaf.length); return new ObjectPidsPath(newpath); } else if (this.pathFromRootToLeaf[this.pathFromRootToLeaf.length - 1].equals(object)) { String[] newpath = new String[this.pathFromRootToLeaf.length + 1]; System.arraycopy(this.pathFromRootToLeaf, 0, newpath, 0, this.pathFromRootToLeaf.length); newpath[newpath.length - 1] = injectingObject; return new ObjectPidsPath(newpath); } else throw new IllegalArgumentException("ambiguous injecting"); } } }
ObjectPidsPath extends AbstractObjectPath { @Override public ObjectPidsPath injectObjectBetween(String injectingObject, Between between) { if (between.getAfter() != null && between.getBefore() != null) { int bindex = Arrays.asList(this.pathFromRootToLeaf).indexOf(between.getBefore()); int aindex = Arrays.asList(this.pathFromRootToLeaf).indexOf(between.getAfter()); if (Math.abs(bindex - aindex) == 1) { return new ObjectPidsPath( injectInternal(injectingObject, Math.min(bindex, aindex), Math.max(bindex, aindex))); } else throw new IllegalArgumentException("ambiguous injecting"); } else { String object = between.getAfter() != null ? between.getAfter() : between.getBefore(); if (this.pathFromRootToLeaf[0].equals(object)) { String[] newpath = new String[this.pathFromRootToLeaf.length + 1]; newpath[0] = injectingObject; System.arraycopy(this.pathFromRootToLeaf, 0, newpath, 1, this.pathFromRootToLeaf.length); return new ObjectPidsPath(newpath); } else if (this.pathFromRootToLeaf[this.pathFromRootToLeaf.length - 1].equals(object)) { String[] newpath = new String[this.pathFromRootToLeaf.length + 1]; System.arraycopy(this.pathFromRootToLeaf, 0, newpath, 0, this.pathFromRootToLeaf.length); newpath[newpath.length - 1] = injectingObject; return new ObjectPidsPath(newpath); } else throw new IllegalArgumentException("ambiguous injecting"); } } ObjectPidsPath(String... pathFromRootToLeaf);  ObjectPidsPath(List<String> pathFromRootToLeaf); }
ObjectPidsPath extends AbstractObjectPath { @Override public ObjectPidsPath injectObjectBetween(String injectingObject, Between between) { if (between.getAfter() != null && between.getBefore() != null) { int bindex = Arrays.asList(this.pathFromRootToLeaf).indexOf(between.getBefore()); int aindex = Arrays.asList(this.pathFromRootToLeaf).indexOf(between.getAfter()); if (Math.abs(bindex - aindex) == 1) { return new ObjectPidsPath( injectInternal(injectingObject, Math.min(bindex, aindex), Math.max(bindex, aindex))); } else throw new IllegalArgumentException("ambiguous injecting"); } else { String object = between.getAfter() != null ? between.getAfter() : between.getBefore(); if (this.pathFromRootToLeaf[0].equals(object)) { String[] newpath = new String[this.pathFromRootToLeaf.length + 1]; newpath[0] = injectingObject; System.arraycopy(this.pathFromRootToLeaf, 0, newpath, 1, this.pathFromRootToLeaf.length); return new ObjectPidsPath(newpath); } else if (this.pathFromRootToLeaf[this.pathFromRootToLeaf.length - 1].equals(object)) { String[] newpath = new String[this.pathFromRootToLeaf.length + 1]; System.arraycopy(this.pathFromRootToLeaf, 0, newpath, 0, this.pathFromRootToLeaf.length); newpath[newpath.length - 1] = injectingObject; return new ObjectPidsPath(newpath); } else throw new IllegalArgumentException("ambiguous injecting"); } } ObjectPidsPath(String... pathFromRootToLeaf);  ObjectPidsPath(List<String> pathFromRootToLeaf); @Override ObjectPidsPath cutHead(int indexFrom); @Override ObjectPidsPath cutTail(int indexFrom); @Override ObjectPidsPath injectRepository(); ObjectPidsPath injectCollections(CollectionsManager col); @Override ObjectPidsPath replace(String src, String dest); @Override ObjectPidsPath injectObjectBetween(String injectingObject, Between between); }
ObjectPidsPath extends AbstractObjectPath { @Override public ObjectPidsPath injectObjectBetween(String injectingObject, Between between) { if (between.getAfter() != null && between.getBefore() != null) { int bindex = Arrays.asList(this.pathFromRootToLeaf).indexOf(between.getBefore()); int aindex = Arrays.asList(this.pathFromRootToLeaf).indexOf(between.getAfter()); if (Math.abs(bindex - aindex) == 1) { return new ObjectPidsPath( injectInternal(injectingObject, Math.min(bindex, aindex), Math.max(bindex, aindex))); } else throw new IllegalArgumentException("ambiguous injecting"); } else { String object = between.getAfter() != null ? between.getAfter() : between.getBefore(); if (this.pathFromRootToLeaf[0].equals(object)) { String[] newpath = new String[this.pathFromRootToLeaf.length + 1]; newpath[0] = injectingObject; System.arraycopy(this.pathFromRootToLeaf, 0, newpath, 1, this.pathFromRootToLeaf.length); return new ObjectPidsPath(newpath); } else if (this.pathFromRootToLeaf[this.pathFromRootToLeaf.length - 1].equals(object)) { String[] newpath = new String[this.pathFromRootToLeaf.length + 1]; System.arraycopy(this.pathFromRootToLeaf, 0, newpath, 0, this.pathFromRootToLeaf.length); newpath[newpath.length - 1] = injectingObject; return new ObjectPidsPath(newpath); } else throw new IllegalArgumentException("ambiguous injecting"); } } ObjectPidsPath(String... pathFromRootToLeaf);  ObjectPidsPath(List<String> pathFromRootToLeaf); @Override ObjectPidsPath cutHead(int indexFrom); @Override ObjectPidsPath cutTail(int indexFrom); @Override ObjectPidsPath injectRepository(); ObjectPidsPath injectCollections(CollectionsManager col); @Override ObjectPidsPath replace(String src, String dest); @Override ObjectPidsPath injectObjectBetween(String injectingObject, Between between); static final Logger LOGGER; static ObjectPidsPath REPOSITORY_PATH; }