mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 04:42:06 +01:00
Make AlgorithmSuite members final and remove setters
This commit is contained in:
parent
11ad6361f8
commit
fedf7c0cf8
2 changed files with 3 additions and 116 deletions
|
@ -15,7 +15,6 @@
|
|||
*/
|
||||
package org.pgpainless.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
|
@ -45,9 +44,9 @@ public class AlgorithmSuite {
|
|||
CompressionAlgorithm.UNCOMPRESSED)
|
||||
);
|
||||
|
||||
private Set<SymmetricKeyAlgorithm> symmetricKeyAlgorithms;
|
||||
private Set<HashAlgorithm> hashAlgorithms;
|
||||
private Set<CompressionAlgorithm> compressionAlgorithms;
|
||||
private final Set<SymmetricKeyAlgorithm> symmetricKeyAlgorithms;
|
||||
private final Set<HashAlgorithm> hashAlgorithms;
|
||||
private final Set<CompressionAlgorithm> compressionAlgorithms;
|
||||
|
||||
public AlgorithmSuite(List<SymmetricKeyAlgorithm> symmetricKeyAlgorithms,
|
||||
List<HashAlgorithm> hashAlgorithms,
|
||||
|
@ -57,57 +56,18 @@ public class AlgorithmSuite {
|
|||
this.compressionAlgorithms = Collections.unmodifiableSet(new LinkedHashSet<>(compressionAlgorithms));
|
||||
}
|
||||
|
||||
public void setSymmetricKeyAlgorithms(List<SymmetricKeyAlgorithm> symmetricKeyAlgorithms) {
|
||||
this.symmetricKeyAlgorithms = Collections.unmodifiableSet(new LinkedHashSet<>(symmetricKeyAlgorithms));
|
||||
}
|
||||
|
||||
public Set<SymmetricKeyAlgorithm> getSymmetricKeyAlgorithms() {
|
||||
return new LinkedHashSet<>(symmetricKeyAlgorithms);
|
||||
}
|
||||
|
||||
public int[] getSymmetricKeyAlgorithmIds() {
|
||||
int[] array = new int[symmetricKeyAlgorithms.size()];
|
||||
List<SymmetricKeyAlgorithm> list = new ArrayList<>(getSymmetricKeyAlgorithms());
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = list.get(i).getAlgorithmId();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void setHashAlgorithms(List<HashAlgorithm> hashAlgorithms) {
|
||||
this.hashAlgorithms = Collections.unmodifiableSet(new LinkedHashSet<>(hashAlgorithms));
|
||||
}
|
||||
|
||||
public Set<HashAlgorithm> getHashAlgorithms() {
|
||||
return new LinkedHashSet<>(hashAlgorithms);
|
||||
}
|
||||
|
||||
public int[] getHashAlgorithmIds() {
|
||||
int[] array = new int[hashAlgorithms.size()];
|
||||
List<HashAlgorithm> list = new ArrayList<>(getHashAlgorithms());
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = list.get(i).getAlgorithmId();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void setCompressionAlgorithms(List<CompressionAlgorithm> compressionAlgorithms) {
|
||||
this.compressionAlgorithms = Collections.unmodifiableSet(new LinkedHashSet<>(compressionAlgorithms));
|
||||
}
|
||||
|
||||
public Set<CompressionAlgorithm> getCompressionAlgorithms() {
|
||||
return new LinkedHashSet<>(compressionAlgorithms);
|
||||
}
|
||||
|
||||
public int[] getCompressionAlgorithmIds() {
|
||||
int[] array = new int[compressionAlgorithms.size()];
|
||||
List<CompressionAlgorithm> list = new ArrayList<>(getCompressionAlgorithms());
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = list.get(i).getAlgorithmId();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static AlgorithmSuite getDefaultAlgorithmSuite() {
|
||||
return defaultAlgorithmSuite;
|
||||
}
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright 2021 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pgpainless.algorithm;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AlgorithmSuiteTest {
|
||||
|
||||
private AlgorithmSuite suite;
|
||||
|
||||
@BeforeEach
|
||||
public void resetEmptyAlgorithmSuite() {
|
||||
suite = new AlgorithmSuite(
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSymmetricAlgorithmsTest() {
|
||||
List<SymmetricKeyAlgorithm> algorithmList = Arrays.asList(
|
||||
SymmetricKeyAlgorithm.AES_128, SymmetricKeyAlgorithm.AES_192, SymmetricKeyAlgorithm.AES_256
|
||||
);
|
||||
|
||||
suite.setSymmetricKeyAlgorithms(algorithmList);
|
||||
|
||||
assertEquals(algorithmList, new ArrayList<>(suite.getSymmetricKeyAlgorithms()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHashAlgorithmsTest() {
|
||||
List<HashAlgorithm> algorithmList = Arrays.asList(
|
||||
HashAlgorithm.SHA256, HashAlgorithm.SHA384, HashAlgorithm.SHA512
|
||||
);
|
||||
|
||||
suite.setHashAlgorithms(algorithmList);
|
||||
|
||||
assertEquals(algorithmList, new ArrayList<>(suite.getHashAlgorithms()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCompressionAlgorithmsTest() {
|
||||
List<CompressionAlgorithm> algorithmList = Arrays.asList(
|
||||
CompressionAlgorithm.ZLIB, CompressionAlgorithm.ZIP, CompressionAlgorithm.BZIP2
|
||||
);
|
||||
|
||||
suite.setCompressionAlgorithms(algorithmList);
|
||||
|
||||
assertEquals(algorithmList, new ArrayList<>(suite.getCompressionAlgorithms()));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue