Java Code Examples for java.util.EnumMap#size()

The following examples show how to use java.util.EnumMap#size() . 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: PropertyValues.java    From jboss-logmanager-ext with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a map into a string that can be parsed by {@link #stringToMap(String)}. The kwy will be the
 * {@linkplain Enum#name() enum name}.
 *
 * @param map the map to convert to a string
 * @param <K> the type of the key
 *
 * @return a string value for that map that can be used for configuration properties
 *
 * @see #escapeKey(StringBuilder, String)
 * @see #escapeValue(StringBuilder, String)
 */
public static <K extends Enum<K>> String mapToString(final EnumMap<K, String> map) {
    if (map == null || map.isEmpty()) {
        return null;
    }
    final StringBuilder sb = new StringBuilder(map.size() * 32);
    final Iterator<Map.Entry<K, String>> iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
        final Map.Entry<K, String> entry = iterator.next();
        sb.append(entry.getKey().name());
        sb.append('=');
        escapeValue(sb, entry.getValue());
        if (iterator.hasNext()) {
            sb.append(',');
        }
    }
    return sb.toString();
}
 
Example 2
Source File: ThingSearchRoute.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private Route thingSearchParameterOptionalImpl(final ThingSearchParameter[] values,
        final EnumMap<ThingSearchParameter, Optional<String>> accumulator,
        final Function<EnumMap<ThingSearchParameter, Optional<String>>, Route> inner) {

    if (accumulator.size() >= values.length) {
        return inner.apply(accumulator);
    } else {
        final ThingSearchParameter parameter = values[accumulator.size()];
        return parameterOptional(parameter.toString(), parameterValueOptional -> {
            accumulator.put(parameter, parameterValueOptional);
            return thingSearchParameterOptionalImpl(values, accumulator, inner);
        });
    }
}
 
Example 3
Source File: ImmutableEnumMap.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static <K extends Enum<K>, V> ImmutableMap<K, V> asImmutable(EnumMap<K, V> map) {
switch (map.size()) {
  case 0:
    return ImmutableMap.of();
  case 1:
    Entry<K, V> entry = Iterables.getOnlyElement(map.entrySet());
    return ImmutableMap.of(entry.getKey(), entry.getValue());
  default:
    return new ImmutableEnumMap<K, V>(map);
}
     }
 
Example 4
Source File: ImmutableEnumMap.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static <K extends Enum<K>, V> ImmutableMap<K, V> asImmutable(EnumMap<K, V> map) {
switch (map.size()) {
  case 0:
    return ImmutableMap.of();
  case 1:
    Entry<K, V> entry = Iterables.getOnlyElement(map.entrySet());
    return ImmutableMap.of(entry.getKey(), entry.getValue());
  default:
    return new ImmutableEnumMap<K, V>(map);
}
     }
 
Example 5
Source File: ImmutableEnumMap.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static <K extends Enum<K>, V> ImmutableMap<K, V> asImmutable(EnumMap<K, V> map) {
switch (map.size()) {
  case 0:
    return ImmutableMap.of();
  case 1:
    Entry<K, V> entry = Iterables.getOnlyElement(map.entrySet());
    return ImmutableMap.of(entry.getKey(), entry.getValue());
  default:
    return new ImmutableEnumMap<K, V>(map);
}
     }
 
Example 6
Source File: ImmutableEnumMap.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static <K extends Enum<K>, V> ImmutableMap<K, V> asImmutable(EnumMap<K, V> map) {
switch (map.size()) {
  case 0:
    return ImmutableMap.of();
  case 1:
    Entry<K, V> entry = Iterables.getOnlyElement(map.entrySet());
    return ImmutableMap.of(entry.getKey(), entry.getValue());
  default:
    return new ImmutableEnumMap<K, V>(map);
}
     }
 
Example 7
Source File: ImmutableEnumMap.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static <K extends Enum<K>, V> ImmutableMap<K, V> asImmutable(EnumMap<K, V> map) {
  switch (map.size()) {
    case 0:
      return ImmutableMap.of();
    case 1:
      Entry<K, V> entry = Iterables.getOnlyElement(map.entrySet());
      return ImmutableMap.of(entry.getKey(), entry.getValue());
    default:
      return new ImmutableEnumMap<K, V>(map);
  }
}
 
Example 8
Source File: UniqueServiceFilter.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<TrustedServiceWrapper> filter(List<TrustedServiceWrapper> trustServices) {
	TrustedServiceWrapper selectedTrustedService = null;

	if (Utils.collectionSize(trustServices) == 1) {
		selectedTrustedService = trustServices.get(0);
	} else if (Utils.isCollectionNotEmpty(trustServices)) {
		LOG.info("More than one selected trust services");

		EnumMap<CertificateQualification, List<String>> qualificationResults = new EnumMap<>(
				CertificateQualification.class);
		for (TrustedServiceWrapper trustService : trustServices) {
			CertificateQualificationCalculation calculator = new CertificateQualificationCalculation(endEntityCert, trustService);
			CertificateQualification certQualification = calculator.getQualification();
			if (!qualificationResults.containsKey(certQualification)) {
				qualificationResults.put(certQualification, trustService.getServiceNames());
			}
		}

		if (qualificationResults.size() > 1) {
			LOG.warn("Unable to select the trust service ! Several possible conclusions {}", qualificationResults);
		} else {
			LOG.info("All trust services conclude with the same result");
			selectedTrustedService = trustServices.get(0);
		}
	}

	if (selectedTrustedService != null) {
		return Collections.singletonList(selectedTrustedService);
	} else {
		return Collections.emptyList();
	}
}
 
Example 9
Source File: QueryHints.java    From Carbonado with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new QueryHints object without the given hint.
 */
public QueryHints without(QueryHint hint) {
    if (hint == null || mMap == null || !mMap.containsKey(hint)) {
        return this;
    }
    EnumMap<QueryHint, Object> map = mMap.clone();
    map.remove(hint);
    if (map.size() == 0) {
        map = null;
    }
    return new QueryHints(map);
}