@Test public void testExtractPackagePrefix() { assertEquals("", ClassName.extractPackagePrefix("org.apache.ant.subpkg.sub2", 0)); assertEquals("org", ClassName.extractPackagePrefix("org", 1)); assertEquals("org.apache.ant", ClassName.extractPackagePrefix("org.apache.ant.subpkg.sub2", 3)); assertEquals("org.apache.ant.subpkg.sub2", ClassName.extractPackagePrefix("org.apache.ant.subpkg.sub2", 5)); assertEquals("org.apache.ant.subpkg.sub2", ClassName.extractPackagePrefix("org.apache.ant.subpkg.sub2", 6)); }
public static String extractPackagePrefix(String packageName, int count) { int dotsSeen = 0; int prefixLength = 0; while (dotsSeen < count) { int p = packageName.indexOf('.', prefixLength); if (p < 0) { return packageName; } prefixLength = p + 1; dotsSeen++; } if (prefixLength == 0) { return ""; } return packageName.substring(0, prefixLength - 1); }
ClassName { public static String extractPackagePrefix(String packageName, int count) { int dotsSeen = 0; int prefixLength = 0; while (dotsSeen < count) { int p = packageName.indexOf('.', prefixLength); if (p < 0) { return packageName; } prefixLength = p + 1; dotsSeen++; } if (prefixLength == 0) { return ""; } return packageName.substring(0, prefixLength - 1); } }
ClassName { public static String extractPackagePrefix(String packageName, int count) { int dotsSeen = 0; int prefixLength = 0; while (dotsSeen < count) { int p = packageName.indexOf('.', prefixLength); if (p < 0) { return packageName; } prefixLength = p + 1; dotsSeen++; } if (prefixLength == 0) { return ""; } return packageName.substring(0, prefixLength - 1); }  }
ClassName { public static String extractPackagePrefix(String packageName, int count) { int dotsSeen = 0; int prefixLength = 0; while (dotsSeen < count) { int p = packageName.indexOf('.', prefixLength); if (p < 0) { return packageName; } prefixLength = p + 1; dotsSeen++; } if (prefixLength == 0) { return ""; } return packageName.substring(0, prefixLength - 1); }  static boolean isMathClass(@SlashedClassName String className); static void assertIsDotted(@DottedClassName String className); static void assertIsSlashed(@SlashedClassName String className); static String toSignature(@SlashedClassName String className); static @CheckForNull String getPrimitiveType(@SlashedClassName String cls); static @CheckForNull @SlashedClassName String fromFieldSignature(String signature); @SlashedClassName @SuppressFBWarnings("TQ_EXPLICIT_UNKNOWN_SOURCE_VALUE_REACHES_ALWAYS_SINK") static String toSlashedClassName(@SlashedClassName(when = When.UNKNOWN) String className); @DottedClassName @SuppressFBWarnings("TQ_EXPLICIT_UNKNOWN_SOURCE_VALUE_REACHES_NEVER_SINK") static String toDottedClassName(@SlashedClassName(when = When.UNKNOWN) String className); static @DottedClassName String extractPackageName(@DottedClassName String className); static String extractSimpleName(@DottedClassName String className); static boolean isValidClassName(String className); static boolean isLocalOrAnonymous(String className); static boolean isAnonymous(String className); static @SlashedClassName String extractClassName(String originalName); static String extractPackagePrefix(String packageName, int count); static boolean matchedPrefixes(String[] classSearchStrings, @DottedClassName String className); static @SlashedClassName String toSlashedClassName(Class<?> class1); }
ClassName { public static String extractPackagePrefix(String packageName, int count) { int dotsSeen = 0; int prefixLength = 0; while (dotsSeen < count) { int p = packageName.indexOf('.', prefixLength); if (p < 0) { return packageName; } prefixLength = p + 1; dotsSeen++; } if (prefixLength == 0) { return ""; } return packageName.substring(0, prefixLength - 1); }  static boolean isMathClass(@SlashedClassName String className); static void assertIsDotted(@DottedClassName String className); static void assertIsSlashed(@SlashedClassName String className); static String toSignature(@SlashedClassName String className); static @CheckForNull String getPrimitiveType(@SlashedClassName String cls); static @CheckForNull @SlashedClassName String fromFieldSignature(String signature); @SlashedClassName @SuppressFBWarnings("TQ_EXPLICIT_UNKNOWN_SOURCE_VALUE_REACHES_ALWAYS_SINK") static String toSlashedClassName(@SlashedClassName(when = When.UNKNOWN) String className); @DottedClassName @SuppressFBWarnings("TQ_EXPLICIT_UNKNOWN_SOURCE_VALUE_REACHES_NEVER_SINK") static String toDottedClassName(@SlashedClassName(when = When.UNKNOWN) String className); static @DottedClassName String extractPackageName(@DottedClassName String className); static String extractSimpleName(@DottedClassName String className); static boolean isValidClassName(String className); static boolean isLocalOrAnonymous(String className); static boolean isAnonymous(String className); static @SlashedClassName String extractClassName(String originalName); static String extractPackagePrefix(String packageName, int count); static boolean matchedPrefixes(String[] classSearchStrings, @DottedClassName String className); static @SlashedClassName String toSlashedClassName(Class<?> class1);  }