private static int getAndCheckFirstDot(String namespace) throws InvalidNamespaceException { int firstDot = namespace.indexOf('.'); if (firstDot == 0) { throw new InvalidNamespaceException(namespace, "The first character shall not be a dot"); } if (firstDot < 0) { return namespace.length(); } if (firstDot == namespace.length() - 1) { throw new InvalidNamespaceException(namespace, "The last character shall not be the first " + "dot"); } return firstDot; }
private int getAndCheckFirstDot(String namespace) throws InvalidNamespaceException { int firstDot = namespace.indexOf('.'); if (firstDot == 0) { throw new InvalidNamespaceException(namespace, "The first character shall not be a dot"); } if (firstDot < 0) { return namespace.length(); } if (firstDot == namespace.length() - 1) { throw new InvalidNamespaceException(namespace, "The last character shall not be the first " + "dot"); } return firstDot; } }
public static String getCollection(String namespace) throws InvalidNamespaceException { int firstDotIndex = getAndCheckFirstDot(namespace); if (firstDotIndex == namespace.length()) { //if there is no dot throw new InvalidNamespaceException( //then there throw InvalidNamespaceException namespace, "Does not have collection part" ); } return namespace.substring(firstDotIndex + 1); }
@Nonnull protected String getCollection(String namespace) throws InvalidNamespaceException { int firstDotIndex = getAndCheckFirstDot(namespace); if (firstDotIndex == namespace.length()) { //if there is no dot throw new InvalidNamespaceException( //then there throw InvalidNamespaceException namespace, "Does not have collection part" ); } return namespace.substring(firstDotIndex + 1); }