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