1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 04:42:06 +01:00

AlgorithmSuite: Use LinkedHashSet instead of List

This commit is contained in:
Paul Schaub 2021-05-25 12:27:21 +02:00
parent 1550e4ff4e
commit 821a49576f

View file

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