public static HashAlgorithm fromName(String algorithmName) { HashAlgorithm match = Arrays.stream(HashAlgorithm.values()) .filter(algo -> algorithmName.equalsIgnoreCase(algo.name)) .findAny() .orElse(null); if (match == null) { throw new IllegalArgumentException("No algorithm matches " + algorithmName); } else { return match; } } }
/** * Returns an array of {@link AllowableValue} elements for each {@link HashAlgorithm}. The * complete {@code description} is built from the digest length, safety warnings, etc. See * {@link HashAlgorithm#buildAllowableValueDescription()}. * * @return an ordered {@code AllowableValue[]} containing the values */ public static AllowableValue[] buildHashAlgorithmAllowableValues() { final HashAlgorithm[] hashAlgorithms = HashAlgorithm.values(); List<AllowableValue> allowableValues = new ArrayList<>(hashAlgorithms.length); for (HashAlgorithm algorithm : hashAlgorithms) { allowableValues.add(new AllowableValue(algorithm.getName(), algorithm.getName(), algorithm.buildAllowableValueDescription())); } return allowableValues.toArray(new AllowableValue[0]); }
public static HashAlgorithm fromName(String algorithmName) { HashAlgorithm match = Arrays.stream(HashAlgorithm.values()) .filter(algo -> algorithmName.equalsIgnoreCase(algo.name)) .findAny() .orElse(null); if (match == null) { throw new IllegalArgumentException("No algorithm matches " + algorithmName); } else { return match; } } }
/** * Returns an array of {@link AllowableValue} elements for each {@link HashAlgorithm}. The * complete {@code description} is built from the digest length, safety warnings, etc. See * {@link HashAlgorithm#buildAllowableValueDescription()}. * * @return an ordered {@code AllowableValue[]} containing the values */ public static AllowableValue[] buildHashAlgorithmAllowableValues() { final HashAlgorithm[] hashAlgorithms = HashAlgorithm.values(); List<AllowableValue> allowableValues = new ArrayList<>(hashAlgorithms.length); for (HashAlgorithm algorithm : hashAlgorithms) { allowableValues.add(new AllowableValue(algorithm.getName(), algorithm.getName(), algorithm.buildAllowableValueDescription())); } return allowableValues.toArray(new AllowableValue[0]); }