Java Code Examples for org.apache.commons.lang3.ArrayUtils#lastIndexOf()

The following examples show how to use org.apache.commons.lang3.ArrayUtils#lastIndexOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmtpMail.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
private boolean verifyAddress(InternetAddress addr) {
    log.debug("verifyAddress called ...");
    boolean retval = true;
    String domain = addr.getAddress();
    int domainStart = domain.indexOf('@');
    if (domainStart > -1 && domainStart + 1 < domain.length()) {
        domain = domain.substring(domainStart + 1);

    }
    if (log.isDebugEnabled()) {
        log.debug("Restricted domains: " +
                StringUtils.join(restrictedDomains, " | "));
        log.debug("disallowedDomains domains: " +
                StringUtils.join(disallowedDomains, " | "));
    }
    if (restrictedDomains != null && restrictedDomains.length > 0) {
        if (ArrayUtils.lastIndexOf(restrictedDomains, domain) == -1) {
            log.warn("Address " + addr.getAddress() +
                    " not in restricted domains list");
            retval = false;
        }
    }

    if (retval &&  disallowedDomains != null && disallowedDomains.length > 0) {
        if (ArrayUtils.lastIndexOf(disallowedDomains, domain) > -1) {
            log.warn("Address " + addr.getAddress() + " in disallowed domains list");
            retval = false;
        }
    }
    log.debug("verifyAddress returning: " + retval);
    return retval;
}
 
Example 2
Source File: TableName.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @param fullName byte array to look into
 * @param offset within said array
 * @param length within said array
 * @throws IllegalArgumentException if fullName equals old root or old meta.
 */
public static TableName valueOf(byte[] fullName, int offset, int length)
    throws IllegalArgumentException {
  Preconditions.checkArgument(offset >= 0, "offset must be non-negative but was %s", offset);
  Preconditions.checkArgument(offset < fullName.length, "offset (%s) must be < array length (%s)",
      offset, fullName.length);
  Preconditions.checkArgument(length <= fullName.length,
      "length (%s) must be <= array length (%s)", length, fullName.length);
  for (TableName tn : tableCache) {
    final byte[] tnName = tn.getName();
    if (Bytes.equals(tnName, 0, tnName.length, fullName, offset, length)) {
      return tn;
    }
  }

  int namespaceDelimIndex = ArrayUtils.lastIndexOf(fullName, (byte) NAMESPACE_DELIM,
      offset + length - 1);

  if (namespaceDelimIndex < offset) {
    return createTableNameIfNecessary(
        ByteBuffer.wrap(NamespaceDescriptor.DEFAULT_NAMESPACE_NAME),
        ByteBuffer.wrap(fullName, offset, length));
  } else {
    return createTableNameIfNecessary(
        ByteBuffer.wrap(fullName, offset, namespaceDelimIndex),
        ByteBuffer.wrap(fullName, namespaceDelimIndex + 1, length - (namespaceDelimIndex + 1)));
  }
}
 
Example 3
Source File: PlanSelectionFuseCostBasedV2.java    From systemds with Apache License 2.0 4 votes vote down vote up
private static long getNumSkipPlans(boolean[] plan) {
	int pos = ArrayUtils.lastIndexOf(plan, true);
	return UtilFunctions.pow(2, plan.length-pos-1);
}
 
Example 4
Source File: PlanSelectionFuseCostBasedV2.java    From systemds with Apache License 2.0 4 votes vote down vote up
private static long getNumSkipPlans(boolean[] plan) {
	int pos = ArrayUtils.lastIndexOf(plan, true);
	return UtilFunctions.pow(2, plan.length-pos-1);
}
 
Example 5
Source File: TableName.java    From hbase with Apache License 2.0 3 votes vote down vote up
/**
 * Check passed byte array, "tableName", is legal user-space table name.
 * @return Returns passed <code>tableName</code> param
 * @throws IllegalArgumentException if passed a tableName is null or
 * is made of other than 'word' characters or underscores: i.e.
 * <code>[\p{IsAlphabetic}\p{Digit}.-:]</code>. The ':' is used to delimit the namespace
 * from the table name and can be used for nothing else.
 *
 * Namespace names can only contain 'word' characters
 * <code>[\p{IsAlphabetic}\p{Digit}]</code> or '_'
 *
 * Qualifier names can only contain 'word' characters
 * <code>[\p{IsAlphabetic}\p{Digit}]</code> or '_', '.' or '-'.
 * The name may not start with '.' or '-'.
 *
 * Valid fully qualified table names:
 * foo:bar, namespace=&gt;foo, table=&gt;bar
 * org:foo.bar, namespace=org, table=&gt;foo.bar
 */
public static byte [] isLegalFullyQualifiedTableName(final byte[] tableName) {
  if (tableName == null || tableName.length <= 0) {
    throw new IllegalArgumentException("Name is null or empty");
  }

  int namespaceDelimIndex = ArrayUtils.lastIndexOf(tableName, (byte) NAMESPACE_DELIM);
  if (namespaceDelimIndex < 0){
    isLegalTableQualifierName(tableName);
  } else {
    isLegalNamespaceName(tableName, 0, namespaceDelimIndex);
    isLegalTableQualifierName(tableName, namespaceDelimIndex + 1, tableName.length);
  }
  return tableName;
}