com.google.api.client.util.Sets Java Examples

The following examples show how to use com.google.api.client.util.Sets. 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: EmailUtils.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * Parse and return a set of valid email addresses
 * @param emails comma separated list of emails
 * @return
 */
public static Set<String> getValidEmailAddresses(String emails) {
  Set<String> validEmailAddresses = new HashSet<>();
  List<String> invalidEmailAddresses = new ArrayList<>();
  if (StringUtils.isBlank(emails)) {
    return Sets.newHashSet();
  } else {
    String[] emailArr = emails.split(",");
    for (String email : emailArr) {
      email = email.trim();
      if (isValidEmailAddress(email)) {
        validEmailAddresses.add(email);
      } else {
        invalidEmailAddresses.add(email);
      }
    }
  }
  if (invalidEmailAddresses.size() > 0) {
    LOG.warn("Found invalid email addresses, please verify the email addresses: {}", invalidEmailAddresses);
  }
  return validEmailAddresses;
}
 
Example #2
Source File: AppEngineDataStoreFactory.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> keySet() throws IOException {
  lock.lock();
  try {
    // NOTE: not possible with memcache
    Set<String> result = Sets.newHashSet();
    for (Entity entity : query(true)) {
      result.add(entity.getKey().getName());
    }
    return Collections.unmodifiableSet(result);
  } finally {
    lock.unlock();
  }
}
 
Example #3
Source File: JsonParser.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
/**
 * Finds the {@link Field} on the given {@link Class} that has the {@link JsonPolymorphicTypeMap}
 * annotation, or {@code null} if there is none.
 *
 * <p>The class must contain exactly zero or one {@link JsonPolymorphicTypeMap} annotation.
 *
 * @param key The {@link Class} to search in, or {@code null}
 * @return The {@link Field} with the {@link JsonPolymorphicTypeMap} annotation, or {@code null}
 *     either if there is none or if the key is {@code null}
 */
private static Field getCachedTypemapFieldFor(Class<?> key) {
  if (key == null) {
    return null;
  }
  lock.lock();
  try {
    // Must use containsKey because we do store null values for when the class has no
    // JsonPolymorphicTypeMap field.
    if (cachedTypemapFields.containsKey(key)) {
      return cachedTypemapFields.get(key);
    }
    // Find the field that determines the type and cache it.
    Field value = null;
    Collection<FieldInfo> fieldInfos = ClassInfo.of(key).getFieldInfos();
    for (FieldInfo fieldInfo : fieldInfos) {
      Field field = fieldInfo.getField();
      JsonPolymorphicTypeMap typemapAnnotation =
          field.getAnnotation(JsonPolymorphicTypeMap.class);
      if (typemapAnnotation != null) {
        Preconditions.checkArgument(
            value == null,
            "Class contains more than one field with @JsonPolymorphicTypeMap annotation: %s",
            key);
        Preconditions.checkArgument(
            Data.isPrimitive(field.getType()),
            "Field which has the @JsonPolymorphicTypeMap, %s, is not a supported type: %s",
            key,
            field.getType());
        value = field;
        // Check for duplicate typeDef keys
        TypeDef[] typeDefs = typemapAnnotation.typeDefinitions();
        HashSet<String> typeDefKeys = Sets.newHashSet();
        Preconditions.checkArgument(
            typeDefs.length > 0, "@JsonPolymorphicTypeMap must have at least one @TypeDef");
        for (TypeDef typeDef : typeDefs) {
          Preconditions.checkArgument(
              typeDefKeys.add(typeDef.key()),
              "Class contains two @TypeDef annotations with identical key: %s",
              typeDef.key());
        }
      }
    }
    cachedTypemapFields.put(key, value);
    return value;
  } finally {
    lock.unlock();
  }
}