SevenZMethodConfiguration.java

  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. import java.util.Objects;

  19. /**
  20.  * Combines a SevenZMethod with configuration options for the method.
  21.  *
  22.  * <p>
  23.  * The exact type and interpretation of options depends on the method being configured. Currently supported are:
  24.  * </p>
  25.  *
  26.  * <table>
  27.  * <caption>Options</caption>
  28.  * <tr>
  29.  * <th>Method</th>
  30.  * <th>Option Type</th>
  31.  * <th>Description</th>
  32.  * </tr>
  33.  * <tr>
  34.  * <td>BZIP2</td>
  35.  * <td>Number</td>
  36.  * <td>Block Size - an number between 1 and 9</td>
  37.  * </tr>
  38.  * <tr>
  39.  * <td>DEFLATE</td>
  40.  * <td>Number</td>
  41.  * <td>Compression Level - an number between 1 and 9</td>
  42.  * </tr>
  43.  * <tr>
  44.  * <td>LZMA2</td>
  45.  * <td>Number</td>
  46.  * <td>Dictionary Size - a number between 4096 and 768 MiB (768 &lt;&lt; 20)</td>
  47.  * </tr>
  48.  * <tr>
  49.  * <td>LZMA2</td>
  50.  * <td>org.tukaani.xz.LZMA2Options</td>
  51.  * <td>Whole set of LZMA2 options.</td>
  52.  * </tr>
  53.  * <tr>
  54.  * <td>DELTA_FILTER</td>
  55.  * <td>Number</td>
  56.  * <td>Delta Distance - a number between 1 and 256</td>
  57.  * </tr>
  58.  * </table>
  59.  *
  60.  * @Immutable
  61.  * @since 1.8
  62.  */
  63. public class SevenZMethodConfiguration {
  64.     private final SevenZMethod method;
  65.     private final Object options;

  66.     /**
  67.      * Doesn't configure any additional options.
  68.      *
  69.      * @param method the method to use
  70.      */
  71.     public SevenZMethodConfiguration(final SevenZMethod method) {
  72.         this(method, null);
  73.     }

  74.     /**
  75.      * Specifies and method plus configuration options.
  76.      *
  77.      * @param method  the method to use
  78.      * @param options the options to use
  79.      * @throws IllegalArgumentException if the method doesn't understand the options specified.
  80.      */
  81.     public SevenZMethodConfiguration(final SevenZMethod method, final Object options) {
  82.         this.method = method;
  83.         this.options = options;
  84.         if (options != null && !Coders.findByMethod(method).isOptionInstance(options)) {
  85.             throw new IllegalArgumentException("The " + method + " method doesn't support options of type " + options.getClass());
  86.         }
  87.     }

  88.     @Override
  89.     public boolean equals(final Object obj) {
  90.         if (this == obj) {
  91.             return true;
  92.         }
  93.         if (obj == null || getClass() != obj.getClass()) {
  94.             return false;
  95.         }
  96.         final SevenZMethodConfiguration other = (SevenZMethodConfiguration) obj;
  97.         return Objects.equals(method, other.method) && Objects.equals(options, other.options);
  98.     }

  99.     /**
  100.      * The specified method.
  101.      *
  102.      * @return the method
  103.      */
  104.     public SevenZMethod getMethod() {
  105.         return method;
  106.     }

  107.     /**
  108.      * The specified options.
  109.      *
  110.      * @return the options
  111.      */
  112.     public Object getOptions() {
  113.         return options;
  114.     }

  115.     @Override
  116.     public int hashCode() {
  117.         return method == null ? 0 : method.hashCode();
  118.     }
  119. }