下面列出了java.util.EnumMap#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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();
}
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);
});
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
@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();
}
}
/**
* 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);
}