@Test public void testOneDot() { { TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1); String name = "hello.world"; assertEquals("h.world", abbreviator.abbreviate(name)); } { TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1); String name = "h.world"; assertEquals("h.world", abbreviator.abbreviate(name)); } { TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1); String name = ".world"; assertEquals(".world", abbreviator.abbreviate(name)); } }
public String abbreviate(String fqClassName) { StringBuilder buf = new StringBuilder(targetLength); if (fqClassName == null) { throw new IllegalArgumentException("Class name may not be null"); } int inLen = fqClassName.length(); if (inLen < targetLength) { return fqClassName; } int[] dotIndexesArray = new int[ClassicConstants.MAX_DOTS]; int[] lengthArray = new int[ClassicConstants.MAX_DOTS + 1]; int dotCount = computeDotIndexes(fqClassName, dotIndexesArray); if (dotCount == 0) { return fqClassName; } computeLengthArray(fqClassName, dotIndexesArray, lengthArray, dotCount); for (int i = 0; i <= dotCount; i++) { if (i == 0) { buf.append(fqClassName.substring(0, lengthArray[i] - 1)); } else { buf.append(fqClassName.substring(dotIndexesArray[i - 1], dotIndexesArray[i - 1] + lengthArray[i])); } } return buf.toString(); }
TargetLengthBasedClassNameAbbreviator implements Abbreviator { public String abbreviate(String fqClassName) { StringBuilder buf = new StringBuilder(targetLength); if (fqClassName == null) { throw new IllegalArgumentException("Class name may not be null"); } int inLen = fqClassName.length(); if (inLen < targetLength) { return fqClassName; } int[] dotIndexesArray = new int[ClassicConstants.MAX_DOTS]; int[] lengthArray = new int[ClassicConstants.MAX_DOTS + 1]; int dotCount = computeDotIndexes(fqClassName, dotIndexesArray); if (dotCount == 0) { return fqClassName; } computeLengthArray(fqClassName, dotIndexesArray, lengthArray, dotCount); for (int i = 0; i <= dotCount; i++) { if (i == 0) { buf.append(fqClassName.substring(0, lengthArray[i] - 1)); } else { buf.append(fqClassName.substring(dotIndexesArray[i - 1], dotIndexesArray[i - 1] + lengthArray[i])); } } return buf.toString(); } }
TargetLengthBasedClassNameAbbreviator implements Abbreviator { public String abbreviate(String fqClassName) { StringBuilder buf = new StringBuilder(targetLength); if (fqClassName == null) { throw new IllegalArgumentException("Class name may not be null"); } int inLen = fqClassName.length(); if (inLen < targetLength) { return fqClassName; } int[] dotIndexesArray = new int[ClassicConstants.MAX_DOTS]; int[] lengthArray = new int[ClassicConstants.MAX_DOTS + 1]; int dotCount = computeDotIndexes(fqClassName, dotIndexesArray); if (dotCount == 0) { return fqClassName; } computeLengthArray(fqClassName, dotIndexesArray, lengthArray, dotCount); for (int i = 0; i <= dotCount; i++) { if (i == 0) { buf.append(fqClassName.substring(0, lengthArray[i] - 1)); } else { buf.append(fqClassName.substring(dotIndexesArray[i - 1], dotIndexesArray[i - 1] + lengthArray[i])); } } return buf.toString(); } TargetLengthBasedClassNameAbbreviator(int targetLength); }
TargetLengthBasedClassNameAbbreviator implements Abbreviator { public String abbreviate(String fqClassName) { StringBuilder buf = new StringBuilder(targetLength); if (fqClassName == null) { throw new IllegalArgumentException("Class name may not be null"); } int inLen = fqClassName.length(); if (inLen < targetLength) { return fqClassName; } int[] dotIndexesArray = new int[ClassicConstants.MAX_DOTS]; int[] lengthArray = new int[ClassicConstants.MAX_DOTS + 1]; int dotCount = computeDotIndexes(fqClassName, dotIndexesArray); if (dotCount == 0) { return fqClassName; } computeLengthArray(fqClassName, dotIndexesArray, lengthArray, dotCount); for (int i = 0; i <= dotCount; i++) { if (i == 0) { buf.append(fqClassName.substring(0, lengthArray[i] - 1)); } else { buf.append(fqClassName.substring(dotIndexesArray[i - 1], dotIndexesArray[i - 1] + lengthArray[i])); } } return buf.toString(); } TargetLengthBasedClassNameAbbreviator(int targetLength); String abbreviate(String fqClassName); }
TargetLengthBasedClassNameAbbreviator implements Abbreviator { public String abbreviate(String fqClassName) { StringBuilder buf = new StringBuilder(targetLength); if (fqClassName == null) { throw new IllegalArgumentException("Class name may not be null"); } int inLen = fqClassName.length(); if (inLen < targetLength) { return fqClassName; } int[] dotIndexesArray = new int[ClassicConstants.MAX_DOTS]; int[] lengthArray = new int[ClassicConstants.MAX_DOTS + 1]; int dotCount = computeDotIndexes(fqClassName, dotIndexesArray); if (dotCount == 0) { return fqClassName; } computeLengthArray(fqClassName, dotIndexesArray, lengthArray, dotCount); for (int i = 0; i <= dotCount; i++) { if (i == 0) { buf.append(fqClassName.substring(0, lengthArray[i] - 1)); } else { buf.append(fqClassName.substring(dotIndexesArray[i - 1], dotIndexesArray[i - 1] + lengthArray[i])); } } return buf.toString(); } TargetLengthBasedClassNameAbbreviator(int targetLength); String abbreviate(String fqClassName);  }