1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * https://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.commons.compress.archivers.sevenz;
20
21 import java.util.Objects;
22
23 /**
24 * Combines a SevenZMethod with configuration options for the method.
25 *
26 * <p>
27 * The exact type and interpretation of options depends on the method being configured. Currently supported are:
28 * </p>
29 *
30 * <table>
31 * <caption>Options</caption>
32 * <tr>
33 * <th>Method</th>
34 * <th>Option Type</th>
35 * <th>Description</th>
36 * </tr>
37 * <tr>
38 * <td>BZIP2</td>
39 * <td>Number</td>
40 * <td>Block Size - an number between 1 and 9</td>
41 * </tr>
42 * <tr>
43 * <td>DEFLATE</td>
44 * <td>Number</td>
45 * <td>Compression Level - an number between 1 and 9</td>
46 * </tr>
47 * <tr>
48 * <td>LZMA2</td>
49 * <td>Number</td>
50 * <td>Dictionary Size - a number between 4096 and 768 MiB (768 << 20)</td>
51 * </tr>
52 * <tr>
53 * <td>LZMA2</td>
54 * <td>org.tukaani.xz.LZMA2Options</td>
55 * <td>Whole set of LZMA2 options.</td>
56 * </tr>
57 * <tr>
58 * <td>DELTA_FILTER</td>
59 * <td>Number</td>
60 * <td>Delta Distance - a number between 1 and 256</td>
61 * </tr>
62 * </table>
63 *
64 * @Immutable
65 * @since 1.8
66 */
67 public class SevenZMethodConfiguration {
68 private final SevenZMethod method;
69 private final Object options;
70
71 /**
72 * Doesn't configure any additional options.
73 *
74 * @param method the method to use
75 */
76 public SevenZMethodConfiguration(final SevenZMethod method) {
77 this(method, null);
78 }
79
80 /**
81 * Specifies and method plus configuration options.
82 *
83 * @param method the method to use
84 * @param options the options to use
85 * @throws IllegalArgumentException if the method doesn't understand the options specified.
86 */
87 public SevenZMethodConfiguration(final SevenZMethod method, final Object options) {
88 this.method = method;
89 this.options = options;
90 if (options != null && !Coders.findByMethod(method).isOptionInstance(options)) {
91 throw new IllegalArgumentException("The " + method + " method doesn't support options of type " + options.getClass());
92 }
93 }
94
95 @Override
96 public boolean equals(final Object obj) {
97 if (this == obj) {
98 return true;
99 }
100 if (obj == null || getClass() != obj.getClass()) {
101 return false;
102 }
103 final SevenZMethodConfiguration other = (SevenZMethodConfiguration) obj;
104 return Objects.equals(method, other.method) && Objects.equals(options, other.options);
105 }
106
107 /**
108 * The specified method.
109 *
110 * @return the method
111 */
112 public SevenZMethod getMethod() {
113 return method;
114 }
115
116 /**
117 * The specified options.
118 *
119 * @return the options
120 */
121 public Object getOptions() {
122 return options;
123 }
124
125 @Override
126 public int hashCode() {
127 return method == null ? 0 : method.hashCode();
128 }
129 }