/** * Convert the internal dCache code for a checksum type to the * corresponding ChecksumType object. * @throws IllegalArgumentException if the code does not correspond to a * checksum type. */ public static final ChecksumType getChecksumType(int i) { for (ChecksumType type: ChecksumType.values()) { if (type.type == i) { return type; } } throw new IllegalArgumentException("Unknown checksum type: " + i); }
public static final boolean isValid(String s) { return Arrays.stream(ChecksumType.values()) .map(ChecksumType::getName) .anyMatch(x -> x.equalsIgnoreCase(s)); }
/** * Convert a String containing the dCache internal canonical name for * this checksum type to the corresponding value. The case of the name * is ignored. * @throws IllegalArgumentException if the name is unknown */ public static final ChecksumType getChecksumType(String s) { for (ChecksumType type: ChecksumType.values()) { if (type.name.equalsIgnoreCase(s) || String.valueOf(type.type).equals(s)) { return type; } } throw new IllegalArgumentException("Unknown checksum type: " + s); }