@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Arrays.hashCode(contentHash); result = prime * result + ((contentType == null) ? 0 : contentType.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; }
@Override public String toString() { final StringBuilder buf = new StringBuilder(); buf.append(ID).append(':'); switch(contentItem.getContentType()) { case MISC: buf.append(ContentType.MISC.toString()); break; case MODULE: buf.append(ContentType.MODULE.toString()); break; case BUNDLE: buf.append(ContentType.BUNDLE.toString()); break; default: throw new IllegalStateException(PatchLogger.ROOT_LOGGER.unsupportedContentType(contentItem.getContentType().name())); } return buf.append(':').append(contentItem.getRelativePath()).toString(); } }
public static ModificationCondition fromString(String condition) throws PatchingException { assert condition != null : "condition is null"; if(condition.startsWith(ExistsCondition.ID)) { String str = condition.substring(ExistsCondition.ID.length() + 1); int i = str.indexOf(':'); if(i < 0) { throw PatchLogger.ROOT_LOGGER.contentItemTypeMissing(condition); } final String typeStr = str.substring(0, i); final ContentType type = ContentType.valueOf(typeStr); str = str.substring(i + 1); ContentItem item; switch(type) { case MISC: final String[] s = str.split("/"); final int length = s.length; final String name = s[length - 1]; final String[] itemPath = Arrays.copyOf(s, length - 1); item = new MiscContentItem(name, itemPath, null); break; case MODULE: case BUNDLE: default: throw new PatchingException(PatchLogger.ROOT_LOGGER.unsupportedContentType(type.name())); } return ModificationCondition.Factory.exists(item); } throw PatchLogger.ROOT_LOGGER.unrecognizedConditionFormat(condition); }
File modTrgDir = new File(targetPatchDir, targetElementId); final ContentType contentType = mod.getItem().getContentType(); if(ContentType.MISC.equals(contentType)) { modSrcDir = new File(modSrcDir, Constants.MISC); modTrgDir = new File(modTrgDir, Constants.MISC); } else { final String slot; if (contentType.equals(ContentType.MODULE)) { modSrcDir = new File(modSrcDir, Constants.MODULES); modTrgDir = new File(modTrgDir, Constants.MODULES); slot = ((ModuleItem)mod.getItem()).getSlot(); } else if (contentType.equals(ContentType.BUNDLE)) { modSrcDir = new File(modSrcDir, Constants.BUNDLES); modTrgDir = new File(modTrgDir, Constants.BUNDLES);
static int hashCode(final ContentItem item) { final ContentType type = item.getContentType(); switch (type) { case MODULE: case BUNDLE: final ModuleItem module = (ModuleItem) item; final String[] path = module.getName().split("\\."); return hashCode(type.toString(), module.getSlot(), path); case MISC: final MiscContentItem misc = (MiscContentItem) item; return hashCode(type.toString(), misc.getName(), misc.getPath()); default: throw new IllegalStateException(); } }
File modTrgDir = new File(targetPatchDir, targetElementId); final ContentType contentType = mod.getItem().getContentType(); if(ContentType.MISC.equals(contentType)) { modSrcDir = new File(modSrcDir, Constants.MISC); modTrgDir = new File(modTrgDir, Constants.MISC); } else { final String slot; if (contentType.equals(ContentType.MODULE)) { modSrcDir = new File(modSrcDir, Constants.MODULES); modTrgDir = new File(modTrgDir, Constants.MODULES); slot = ((ModuleItem)mod.getItem()).getSlot(); } else if (contentType.equals(ContentType.BUNDLE)) { modSrcDir = new File(modSrcDir, Constants.BUNDLES); modTrgDir = new File(modTrgDir, Constants.BUNDLES);
static int hashCode(final ContentItem item) { final ContentType type = item.getContentType(); switch (type) { case MODULE: case BUNDLE: final ModuleItem module = (ModuleItem) item; final String[] path = module.getName().split("\\."); return hashCode(type.toString(), module.getSlot(), path); case MISC: final MiscContentItem misc = (MiscContentItem) item; return hashCode(type.toString(), misc.getName(), misc.getPath()); default: throw new IllegalStateException(); } }
modType = ModificationType.ADD; } else { // remove cancels add if(cp1Mod.getItem().getContentType().equals(ContentType.MODULE)) { if (cp2Item.getContentType().equals(ContentType.MODULE)) { final ModuleItem module = (ModuleItem) cp2Item; if(cp2Type.equals(ModificationType.REMOVE)) { elementBuilder.addModule(module.getName(), module.getSlot(), module.getContentHash()); } else if (cp2Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Item; elementBuilder.addFile(misc.getName(), Arrays.asList(misc.getPath()), misc.getContentHash(), if (cp1Item.getContentType().equals(ContentType.MODULE)) { final ModuleItem module = (ModuleItem) cp2Mod.getItem(); elementBuilder.removeModule(module.getName(), module.getSlot(), cp1Mod.getTargetHash()); } else if (cp1Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Mod.getItem(); elementBuilder.removeFile(misc.getName(), Arrays.asList(misc.getPath()), cp1Mod.getTargetHash(), if (cp1Item.getContentType().equals(ContentType.MODULE)) { final ModuleItem module = (ModuleItem) cp2Mod.getItem(); elementBuilder.modifyModule(module.getName(), module.getSlot(), cp1Mod.getTargetHash(), module.getContentHash()); } else if (cp1Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Mod.getItem(); elementBuilder.modifyFile(misc.getName(), Arrays.asList(misc.getPath()), cp1Mod.getTargetHash(),
@Override public String toString() { final StringBuilder buf = new StringBuilder(); buf.append(ID).append(':'); switch(contentItem.getContentType()) { case MISC: buf.append(ContentType.MISC.toString()); break; case MODULE: buf.append(ContentType.MODULE.toString()); break; case BUNDLE: buf.append(ContentType.BUNDLE.toString()); break; default: throw new IllegalStateException(PatchLogger.ROOT_LOGGER.unsupportedContentType(contentItem.getContentType().name())); } return buf.append(':').append(contentItem.getRelativePath()).toString(); } }
public static ModificationCondition fromString(String condition) throws PatchingException { assert condition != null : "condition is null"; if(condition.startsWith(ExistsCondition.ID)) { String str = condition.substring(ExistsCondition.ID.length() + 1); int i = str.indexOf(':'); if(i < 0) { throw PatchLogger.ROOT_LOGGER.contentItemTypeMissing(condition); } final String typeStr = str.substring(0, i); final ContentType type = ContentType.valueOf(typeStr); str = str.substring(i + 1); ContentItem item; switch(type) { case MISC: final String[] s = str.split("/"); final int length = s.length; final String name = s[length - 1]; final String[] itemPath = Arrays.copyOf(s, length - 1); item = new MiscContentItem(name, itemPath, null); break; case MODULE: case BUNDLE: default: throw new PatchingException(PatchLogger.ROOT_LOGGER.unsupportedContentType(type.name())); } return ModificationCondition.Factory.exists(item); } throw PatchLogger.ROOT_LOGGER.unrecognizedConditionFormat(condition); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Arrays.hashCode(contentHash); result = prime * result + ((contentType == null) ? 0 : contentType.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; }
modType = ModificationType.ADD; } else { // remove cancels add if(cp1Mod.getItem().getContentType().equals(ContentType.MODULE)) { if (cp2Item.getContentType().equals(ContentType.MODULE)) { final ModuleItem module = (ModuleItem) cp2Item; if(cp2Type.equals(ModificationType.REMOVE)) { elementBuilder.addModule(module.getName(), module.getSlot(), module.getContentHash()); } else if (cp2Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Item; elementBuilder.addFile(misc.getName(), Arrays.asList(misc.getPath()), misc.getContentHash(), if (cp1Item.getContentType().equals(ContentType.MODULE)) { final ModuleItem module = (ModuleItem) cp2Mod.getItem(); elementBuilder.removeModule(module.getName(), module.getSlot(), cp1Mod.getTargetHash()); } else if (cp1Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Mod.getItem(); elementBuilder.removeFile(misc.getName(), Arrays.asList(misc.getPath()), cp1Mod.getTargetHash(), if (cp1Item.getContentType().equals(ContentType.MODULE)) { final ModuleItem module = (ModuleItem) cp2Mod.getItem(); elementBuilder.modifyModule(module.getName(), module.getSlot(), cp1Mod.getTargetHash(), module.getContentHash()); } else if (cp1Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Mod.getItem(); elementBuilder.modifyFile(misc.getName(), Arrays.asList(misc.getPath()), cp1Mod.getTargetHash(),
private Integer getKey(ContentItem item) { final int prime = 31; int result = 1; result = prime * result + item.getContentType().hashCode(); result = prime * result + item.getRelativePath().hashCode(); return result; } }
final ContentItem item = mod.getItem(); assertEquals(0, mod.getTargetHash().length); if(ContentType.MODULE.equals(item.getContentType())) { Assert.assertArrayEquals(moduleHash("cp2"), item.getContentHash()); } else if(ContentType.MISC.equals(item.getContentType())) { Assert.assertArrayEquals(miscHash("cp2"), item.getContentHash()); } else {
private Integer getKey(ContentItem item) { final int prime = 31; int result = 1; result = prime * result + item.getContentType().hashCode(); result = prime * result + item.getRelativePath().hashCode(); return result; } }
final ContentItem item = mod.getItem(); assertEquals(0, item.getContentHash().length); if(ContentType.MODULE.equals(item.getContentType())) { Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash()); } else if(ContentType.MISC.equals(item.getContentType())) { Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash()); } else {
assertEquals(ModificationType.MODIFY, mod.getType()); final ContentItem item = mod.getItem(); if(ContentType.MODULE.equals(item.getContentType())) { Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash()); Assert.assertArrayEquals(moduleHash("cp2"), item.getContentHash()); } else if(ContentType.MISC.equals(item.getContentType())) { Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash()); Assert.assertArrayEquals(miscHash("cp2"), item.getContentHash());
assertEquals(ModificationType.MODIFY, mod.getType()); final ContentItem item = mod.getItem(); if(ContentType.MODULE.equals(item.getContentType())) { Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash()); Assert.assertArrayEquals(moduleHash("cp2"), item.getContentHash()); } else if(ContentType.MISC.equals(item.getContentType())) { Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash()); Assert.assertArrayEquals(miscHash("cp2"), item.getContentHash());