diff --git a/pgpainless-core/src/main/java/org/pgpainless/algorithm/AlgorithmSuite.java b/pgpainless-core/src/main/java/org/pgpainless/algorithm/AlgorithmSuite.java index 3cce51f3..e5f8e2c4 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/algorithm/AlgorithmSuite.java +++ b/pgpainless-core/src/main/java/org/pgpainless/algorithm/AlgorithmSuite.java @@ -18,7 +18,9 @@ package org.pgpainless.algorithm; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; public class AlgorithmSuite { @@ -39,62 +41,65 @@ public class AlgorithmSuite { CompressionAlgorithm.UNCOMPRESSED) ); - private List symmetricKeyAlgorithms; - private List hashAlgorithms; - private List compressionAlgorithms; + private Set symmetricKeyAlgorithms; + private Set hashAlgorithms; + private Set compressionAlgorithms; public AlgorithmSuite(List symmetricKeyAlgorithms, List hashAlgorithms, List compressionAlgorithms) { - this.symmetricKeyAlgorithms = Collections.unmodifiableList(symmetricKeyAlgorithms); - this.hashAlgorithms = Collections.unmodifiableList(hashAlgorithms); - this.compressionAlgorithms = Collections.unmodifiableList(compressionAlgorithms); + this.symmetricKeyAlgorithms = Collections.unmodifiableSet(new LinkedHashSet<>(symmetricKeyAlgorithms)); + this.hashAlgorithms = Collections.unmodifiableSet(new LinkedHashSet<>(hashAlgorithms)); + this.compressionAlgorithms = Collections.unmodifiableSet(new LinkedHashSet<>(compressionAlgorithms)); } public void setSymmetricKeyAlgorithms(List symmetricKeyAlgorithms) { - this.symmetricKeyAlgorithms = symmetricKeyAlgorithms; + this.symmetricKeyAlgorithms = Collections.unmodifiableSet(new LinkedHashSet<>(symmetricKeyAlgorithms)); } - public List getSymmetricKeyAlgorithms() { - return new ArrayList<>(symmetricKeyAlgorithms); + public Set getSymmetricKeyAlgorithms() { + return new LinkedHashSet<>(symmetricKeyAlgorithms); } public int[] getSymmetricKeyAlgorithmIds() { int[] array = new int[symmetricKeyAlgorithms.size()]; + List list = new ArrayList<>(symmetricKeyAlgorithms); for (int i = 0; i < array.length; i++) { - array[i] = symmetricKeyAlgorithms.get(i).getAlgorithmId(); + array[i] = list.get(i).getAlgorithmId(); } return array; } public void setHashAlgorithms(List hashAlgorithms) { - this.hashAlgorithms = hashAlgorithms; + this.hashAlgorithms = Collections.unmodifiableSet(new LinkedHashSet<>(hashAlgorithms)); } - public List getHashAlgorithms() { - return hashAlgorithms; + public Set getHashAlgorithms() { + return new LinkedHashSet<>(hashAlgorithms); } public int[] getHashAlgorithmIds() { int[] array = new int[hashAlgorithms.size()]; + List list = new ArrayList<>(hashAlgorithms); for (int i = 0; i < array.length; i++) { - array[i] = hashAlgorithms.get(i).getAlgorithmId(); + array[i] = list.get(i).getAlgorithmId(); } return array; } public void setCompressionAlgorithms(List compressionAlgorithms) { - this.compressionAlgorithms = compressionAlgorithms; + this.compressionAlgorithms = Collections.unmodifiableSet(new LinkedHashSet<>(compressionAlgorithms)); } - public List getCompressionAlgorithms() { - return compressionAlgorithms; + public Set getCompressionAlgorithms() { + return new LinkedHashSet<>(compressionAlgorithms); } public int[] getCompressionAlgorithmIds() { int[] array = new int[compressionAlgorithms.size()]; + List list = new ArrayList<>(compressionAlgorithms); for (int i = 0; i < array.length; i++) { - array[i] = compressionAlgorithms.get(i).getAlgorithmId(); + array[i] = list.get(i).getAlgorithmId(); } return array; }