diff options
| author | J08nY | 2024-03-22 23:58:55 +0100 |
|---|---|---|
| committer | J08nY | 2024-03-25 14:52:43 +0100 |
| commit | 73af477a8774e1ede5dd8de6491eb353dc0b12bd (patch) | |
| tree | 2d4e3b19bc5fb55308b886032312be76341736d4 /src/cz/crcs/ectester/standalone/consts/Ident.java | |
| parent | 64b95fa059295e1dc23371c849f2302c1c18f5b4 (diff) | |
| download | ECTester-73af477a8774e1ede5dd8de6491eb353dc0b12bd.tar.gz ECTester-73af477a8774e1ede5dd8de6491eb353dc0b12bd.tar.zst ECTester-73af477a8774e1ede5dd8de6491eb353dc0b12bd.zip | |
Basic Gradle setup.
Diffstat (limited to 'src/cz/crcs/ectester/standalone/consts/Ident.java')
| -rw-r--r-- | src/cz/crcs/ectester/standalone/consts/Ident.java | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/src/cz/crcs/ectester/standalone/consts/Ident.java b/src/cz/crcs/ectester/standalone/consts/Ident.java deleted file mode 100644 index fcc811d..0000000 --- a/src/cz/crcs/ectester/standalone/consts/Ident.java +++ /dev/null @@ -1,88 +0,0 @@ -package cz.crcs.ectester.standalone.consts; - -import java.security.NoSuchAlgorithmException; -import java.security.Provider; -import java.util.*; -import java.util.function.BiFunction; - -public abstract class Ident { - Set<String> idents; - String name; - - public Ident(String name, String... aliases) { - this.name = name; - this.idents = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); - this.idents.add(name); - this.idents.addAll(Arrays.asList(aliases)); - } - - public String getName() { - return name; - } - - public Set<String> getIdents() { - return Collections.unmodifiableSet(idents); - } - - public boolean contains(String other) { - return name.equals(other) || idents.contains(other); - } - - public boolean containsAny(List<String> others) { - for(String other : others) { - if(name.equals(other) || idents.contains(other)) { - return true; - } - } - return false; - } - - <T> T getInstance(BiFunction<String, Provider, T> getter, Provider provider) throws NoSuchAlgorithmException { - T instance = null; - try { - instance = getter.apply(name, provider); - } catch (Exception ignored) { - ignored.printStackTrace(); - } - - if (instance == null) { - for (String alias : idents) { - try { - instance = getter.apply(alias, provider); - if (instance != null) { - break; - } - } catch (Exception ignored) { - ignored.printStackTrace(); - } - } - } - - if (instance == null) { - throw new NoSuchAlgorithmException(name); - } - return instance; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof Ident)) { - return false; - } - Ident other = (Ident) obj; - return idents.equals(other.getIdents()); - } - - @Override - public int hashCode() { - return idents.hashCode() + 37; - } - - @Override - public String toString() { - return "(" + String.join(" | ", idents) + ")"; - } -} |
