1 package nom.tam.fits.compression.provider;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 import nom.tam.fits.header.Compression;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 @SuppressWarnings("javadoc")
60 public class CompressorControlNameComputer {
61
62 private static final String COMPRESSOR_CLASS_SUFFIX = "Compressor";
63
64 private static String standardizeBaseType(String simpleName) {
65 return Character.toUpperCase(simpleName.charAt(0)) + simpleName.substring(1).toLowerCase();
66 }
67
68 private static String standardizeCompressionAlgorithm(String compressionAlgorithm) {
69 if (Compression.ZCMPTYPE_RICE_1.equalsIgnoreCase(compressionAlgorithm) ||
70 Compression.ZCMPTYPE_RICE_ONE.equalsIgnoreCase(compressionAlgorithm)) {
71 return "Rice";
72 }
73 if (Compression.ZCMPTYPE_PLIO_1.equalsIgnoreCase(compressionAlgorithm)) {
74 return "PLIO";
75 }
76 if (Compression.ZCMPTYPE_HCOMPRESS_1.equalsIgnoreCase(compressionAlgorithm)) {
77 return "H";
78 }
79 if (Compression.ZCMPTYPE_GZIP_2.equalsIgnoreCase(compressionAlgorithm)) {
80 return "GZip2";
81 }
82 if (Compression.ZCMPTYPE_GZIP_1.equalsIgnoreCase(compressionAlgorithm)) {
83 return "GZip";
84 }
85 if (Compression.ZCMPTYPE_NOCOMPRESS.equalsIgnoreCase(compressionAlgorithm)) {
86 return "NoCompress";
87 }
88 return "Unknown";
89 }
90
91 private static String standardizeQuantAlgorithm(String quantAlgorithm) {
92 if (quantAlgorithm != null) {
93 if (Compression.ZQUANTIZ_NO_DITHER.equalsIgnoreCase(quantAlgorithm) ||
94 Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_1.equalsIgnoreCase(quantAlgorithm) ||
95 Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_2.equalsIgnoreCase(quantAlgorithm)) {
96 return "Quant";
97 }
98 return "Unknown";
99 }
100 return "";
101 }
102
103 public CompressorControlNameComputer() {
104 super();
105 }
106
107 public String createCompressorClassName(String quantAlgorithm, String compressionAlgorithm, Class<?> baseType) {
108 StringBuilder className = new StringBuilder();
109 className.append(standardizeBaseType(baseType.getSimpleName()));
110 if (className.indexOf(Float.class.getSimpleName()) < 0 && className.indexOf(Double.class.getSimpleName()) < 0) {
111 className.append(standardizeQuantAlgorithm(quantAlgorithm));
112 }
113 className.append(standardizeCompressionAlgorithm(compressionAlgorithm));
114 className.append(COMPRESSOR_CLASS_SUFFIX);
115 return className.toString();
116 }
117 }