private Tree(RelativePath path, Hashes hash, Map<Path.Segment, Tree> children) { super(path, hash == null ? new Hashes(null, null, null) : hash, children); }
public static Hashes of(Entity<?, ?> entity) { String contentHash = null; String identityHash = null; String syncHash = null; if (entity instanceof ContentHashable) { contentHash = ((ContentHashable) entity).getContentHash(); } if (entity instanceof IdentityHashable) { identityHash = ((IdentityHashable) entity).getIdentityHash(); } if (entity instanceof Syncable) { syncHash = ((Syncable) entity).getSyncHash(); } return new Hashes(identityHash, contentHash, syncHash); }
private Hashes hashesOf(AbstractElement<?, ?> el) { String contentHash = null; String identityHash = null; String syncHash = null; if (el instanceof ContentHashable) { contentHash = ((ContentHashable) el).getContentHash(); } if (el instanceof IdentityHashable) { identityHash = ((IdentityHashable) el).getIdentityHash(); } if (el instanceof Syncable) { syncHash = ((Syncable) el).getSyncHash(); } return contentHash == null && identityHash == null && syncHash == null ? null : new Hashes(identityHash, contentHash, syncHash); }
static Hashes of(InventoryStructure<?> inventory, CanonicalPath rootPath, boolean computeIdentity, boolean computeContent, boolean computeSync) { ComputeHash.HashConstructor ctor = new ComputeHash.HashConstructor(new ComputeHash.DigestComputingWriter( ComputeHash.newDigest())); IntermediateHashResult res = ComputeHash.computeHash(rootPath, inventory.getRoot(), ComputeHash.HashableView.of(inventory), ctor, computeIdentity, computeContent, computeSync, rp -> null, rp -> null); return new Hashes(res.identityHash, res.contentHash, res.syncHash); }
public static Tree treeOf(InventoryStructure<?> root, CanonicalPath rootPath, Function<RelativePath, Hashes> hashLoader) { Tree.AbstractBuilder<?>[] tbld = new Tree.AbstractBuilder[1]; Consumer<IntermediateHashContext> startChild = context -> { if (tbld[0] == null) { tbld[0] = Tree.builder(); } else { tbld[0] = tbld[0].startChild(); } }; BiConsumer<IntermediateHashContext, IntermediateHashResult> endChild = (ctx, result) -> { if (tbld[0] instanceof Tree.ChildBuilder) { tbld[0].withHash(new Hashes(result)).withPath(result.path); @SuppressWarnings("unchecked") Tree.AbstractBuilder<?> parent = ((Tree.ChildBuilder<?>) tbld[0]).getParent(); parent.addChild(((Tree.ChildBuilder<?>) tbld[0]).build()); tbld[0] = parent; } }; IntermediateHashResult res = ComputeHash.treeOf(root, rootPath, true, true, true, startChild, endChild, hashLoader); tbld[0].withPath(res.path).withHash(new Hashes(res)); return ((Tree.Builder)tbld[0]).build(); }