001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 */ 018package org.apache.commons.compress.archivers.sevenz; 019 020import java.util.Objects; 021 022/** 023 * Combines a SevenZMethod with configuration options for the method. 024 * 025 * <p>The exact type and interpretation of options depends on the 026 * method being configured. Currently supported are:</p> 027 * 028 * <table summary="Options"> 029 * <tr><th>Method</th><th>Option Type</th><th>Description</th></tr> 030 * <tr><td>BZIP2</td><td>Number</td><td>Block Size - an number between 1 and 9</td></tr> 031 * <tr><td>DEFLATE</td><td>Number</td><td>Compression Level - an number between 1 and 9</td></tr> 032 * <tr><td>LZMA2</td><td>Number</td><td>Dictionary Size - a number between 4096 and 768 MiB (768 << 20)</td></tr> 033 * <tr><td>LZMA2</td><td>org.tukaani.xz.LZMA2Options</td><td>Whole set of LZMA2 options.</td></tr> 034 * <tr><td>DELTA_FILTER</td><td>Number</td><td>Delta Distance - a number between 1 and 256</td></tr> 035 * </table> 036 * 037 * @Immutable 038 * @since 1.8 039 */ 040public class SevenZMethodConfiguration { 041 private final SevenZMethod method; 042 private final Object options; 043 044 /** 045 * Doesn't configure any additional options. 046 * @param method the method to use 047 */ 048 public SevenZMethodConfiguration(final SevenZMethod method) { 049 this(method, null); 050 } 051 052 /** 053 * Specifies and method plus configuration options. 054 * @param method the method to use 055 * @param options the options to use 056 * @throws IllegalArgumentException if the method doesn't understand the options specified. 057 */ 058 public SevenZMethodConfiguration(final SevenZMethod method, final Object options) { 059 this.method = method; 060 this.options = options; 061 if (options != null && !Coders.findByMethod(method).canAcceptOptions(options)) { 062 throw new IllegalArgumentException("The " + method + " method doesn't support options of type " 063 + options.getClass()); 064 } 065 } 066 067 /** 068 * The specified method. 069 * @return the method 070 */ 071 public SevenZMethod getMethod() { 072 return method; 073 } 074 075 /** 076 * The specified options. 077 * @return the options 078 */ 079 public Object getOptions() { 080 return options; 081 } 082 083 @Override 084 public int hashCode() { 085 return method == null ? 0 : method.hashCode(); 086 } 087 088 @Override 089 public boolean equals(Object obj) { 090 if (this == obj) { 091 return true; 092 } 093 if (obj == null || getClass() != obj.getClass()) { 094 return false; 095 } 096 final SevenZMethodConfiguration other = (SevenZMethodConfiguration) obj; 097 return Objects.equals(method, other.method) 098 && Objects.equals(options, other.options); 099 } 100}