@Test public void testNormalize() { UploadRootPathsNormalizer n = new UploadRootPathsNormalizer(); final List<TransferItem> list = new ArrayList<TransferItem>(); list.add(new TransferItem(new Path("/a", EnumSet.of(Path.Type.directory)), new NullLocal(System.getProperty("java.io.tmpdir"), "a") { @Override public boolean isDirectory() { return true; } @Override public boolean isFile() { return false; } }, "1")); list.add(new TransferItem(new Path("/a", EnumSet.of(Path.Type.file)), new NullLocal(System.getProperty("java.io.tmpdir"), "a" + File.separator + "b"), "2")); final List<TransferItem> normalized = n.normalize(list); assertEquals(1, normalized.size()); final TransferItem i = normalized.iterator().next(); assertEquals(new Path("/a", EnumSet.of(Path.Type.directory)), i.remote); assertEquals("1", i.lockId); }
@Override public List<TransferItem> normalize(final List<TransferItem> roots) { final List<TransferItem> normalized = new ArrayList<TransferItem>(); for(TransferItem upload : roots) { boolean duplicate = false; for(Iterator<TransferItem> iter = normalized.iterator(); iter.hasNext(); ) { TransferItem n = iter.next(); if(upload.local.isChild(n.local)) { duplicate = true; break; } if(n.local.isChild(upload.local)) { iter.remove(); } if(upload.remote.equals(n.remote)) { final Path parent = upload.remote.getParent(); final String filename = upload.remote.getName(); String proposal; int no = 0; int index = filename.lastIndexOf('.'); Path remote; do { if(index != -1 && index != 0) { proposal = String.format("%s-%d%s", filename.substring(0, index), ++no, filename.substring(index)); } else { proposal = String.format("%s-%d", filename, ++no); } remote = new Path(parent, proposal, upload.remote.getType()); } while(false); if(log.isInfoEnabled()) { log.info(String.format("Changed name from %s to %s", filename, remote.getName())); } upload.remote = remote; } } if(!duplicate) { normalized.add(new TransferItem(upload.remote, upload.local, upload.lockId, upload.checksum)); } } return normalized; }
UploadRootPathsNormalizer implements RootPathsNormalizer<List<TransferItem>> { @Override public List<TransferItem> normalize(final List<TransferItem> roots) { final List<TransferItem> normalized = new ArrayList<TransferItem>(); for(TransferItem upload : roots) { boolean duplicate = false; for(Iterator<TransferItem> iter = normalized.iterator(); iter.hasNext(); ) { TransferItem n = iter.next(); if(upload.local.isChild(n.local)) { duplicate = true; break; } if(n.local.isChild(upload.local)) { iter.remove(); } if(upload.remote.equals(n.remote)) { final Path parent = upload.remote.getParent(); final String filename = upload.remote.getName(); String proposal; int no = 0; int index = filename.lastIndexOf('.'); Path remote; do { if(index != -1 && index != 0) { proposal = String.format("%s-%d%s", filename.substring(0, index), ++no, filename.substring(index)); } else { proposal = String.format("%s-%d", filename, ++no); } remote = new Path(parent, proposal, upload.remote.getType()); } while(false); if(log.isInfoEnabled()) { log.info(String.format("Changed name from %s to %s", filename, remote.getName())); } upload.remote = remote; } } if(!duplicate) { normalized.add(new TransferItem(upload.remote, upload.local, upload.lockId, upload.checksum)); } } return normalized; } }
UploadRootPathsNormalizer implements RootPathsNormalizer<List<TransferItem>> { @Override public List<TransferItem> normalize(final List<TransferItem> roots) { final List<TransferItem> normalized = new ArrayList<TransferItem>(); for(TransferItem upload : roots) { boolean duplicate = false; for(Iterator<TransferItem> iter = normalized.iterator(); iter.hasNext(); ) { TransferItem n = iter.next(); if(upload.local.isChild(n.local)) { duplicate = true; break; } if(n.local.isChild(upload.local)) { iter.remove(); } if(upload.remote.equals(n.remote)) { final Path parent = upload.remote.getParent(); final String filename = upload.remote.getName(); String proposal; int no = 0; int index = filename.lastIndexOf('.'); Path remote; do { if(index != -1 && index != 0) { proposal = String.format("%s-%d%s", filename.substring(0, index), ++no, filename.substring(index)); } else { proposal = String.format("%s-%d", filename, ++no); } remote = new Path(parent, proposal, upload.remote.getType()); } while(false); if(log.isInfoEnabled()) { log.info(String.format("Changed name from %s to %s", filename, remote.getName())); } upload.remote = remote; } } if(!duplicate) { normalized.add(new TransferItem(upload.remote, upload.local, upload.lockId, upload.checksum)); } } return normalized; }  }
UploadRootPathsNormalizer implements RootPathsNormalizer<List<TransferItem>> { @Override public List<TransferItem> normalize(final List<TransferItem> roots) { final List<TransferItem> normalized = new ArrayList<TransferItem>(); for(TransferItem upload : roots) { boolean duplicate = false; for(Iterator<TransferItem> iter = normalized.iterator(); iter.hasNext(); ) { TransferItem n = iter.next(); if(upload.local.isChild(n.local)) { duplicate = true; break; } if(n.local.isChild(upload.local)) { iter.remove(); } if(upload.remote.equals(n.remote)) { final Path parent = upload.remote.getParent(); final String filename = upload.remote.getName(); String proposal; int no = 0; int index = filename.lastIndexOf('.'); Path remote; do { if(index != -1 && index != 0) { proposal = String.format("%s-%d%s", filename.substring(0, index), ++no, filename.substring(index)); } else { proposal = String.format("%s-%d", filename, ++no); } remote = new Path(parent, proposal, upload.remote.getType()); } while(false); if(log.isInfoEnabled()) { log.info(String.format("Changed name from %s to %s", filename, remote.getName())); } upload.remote = remote; } } if(!duplicate) { normalized.add(new TransferItem(upload.remote, upload.local, upload.lockId, upload.checksum)); } } return normalized; }  @Override List<TransferItem> normalize(final List<TransferItem> roots); }
UploadRootPathsNormalizer implements RootPathsNormalizer<List<TransferItem>> { @Override public List<TransferItem> normalize(final List<TransferItem> roots) { final List<TransferItem> normalized = new ArrayList<TransferItem>(); for(TransferItem upload : roots) { boolean duplicate = false; for(Iterator<TransferItem> iter = normalized.iterator(); iter.hasNext(); ) { TransferItem n = iter.next(); if(upload.local.isChild(n.local)) { duplicate = true; break; } if(n.local.isChild(upload.local)) { iter.remove(); } if(upload.remote.equals(n.remote)) { final Path parent = upload.remote.getParent(); final String filename = upload.remote.getName(); String proposal; int no = 0; int index = filename.lastIndexOf('.'); Path remote; do { if(index != -1 && index != 0) { proposal = String.format("%s-%d%s", filename.substring(0, index), ++no, filename.substring(index)); } else { proposal = String.format("%s-%d", filename, ++no); } remote = new Path(parent, proposal, upload.remote.getType()); } while(false); if(log.isInfoEnabled()) { log.info(String.format("Changed name from %s to %s", filename, remote.getName())); } upload.remote = remote; } } if(!duplicate) { normalized.add(new TransferItem(upload.remote, upload.local, upload.lockId, upload.checksum)); } } return normalized; }  @Override List<TransferItem> normalize(final List<TransferItem> roots);  }