View Javadoc
1   package org.apache.maven.doxia.wrapper;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.Serializable;
23  import java.util.Objects;
24  
25  import static org.codehaus.plexus.util.StringUtils.isNotEmpty;
26  
27  /**
28   * Abstract wrapper for Doxia converter.
29   *
30   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
31   */
32  abstract class AbstractWrapper
33      implements Serializable
34  {
35      public static final String AUTO_FORMAT = "auto";
36  
37      private String format;
38  
39      private String[] supportedFormat;
40  
41      /**
42       * @param format could be null.
43       * @param supportedFormat not null.
44       * @throws IllegalArgumentException if supportedFormat is null.
45       */
46      AbstractWrapper( String format, String[] supportedFormat )
47      {
48          this.format = ( isNotEmpty( format ) ? format : AUTO_FORMAT );
49          if ( supportedFormat == null )
50          {
51              throw new IllegalArgumentException( "supportedFormat is required" );
52          }
53          this.supportedFormat = supportedFormat;
54      }
55  
56      /**
57       * @return the wanted format.
58       */
59      public String getFormat()
60      {
61          return this.format;
62      }
63  
64      /**
65       * @param format The wanted format.
66       */
67      void setFormat( String format )
68      {
69          this.format = format;
70      }
71  
72      /**
73       * @return the supportedFormat
74       */
75      public String[] getSupportedFormat()
76      {
77          return supportedFormat;
78      }
79  
80      /**
81       * @param supportedFormat the supportedFormat to set
82       */
83      void setSupportedFormat( String[] supportedFormat )
84      {
85          this.supportedFormat = supportedFormat;
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public boolean equals( Object other )
91      {
92          if ( this == other )
93          {
94              return true;
95          }
96          if ( other == null || getClass() != other.getClass() )
97          {
98              return false;
99          }
100 
101         AbstractWrapper that = (AbstractWrapper) other;
102         return Objects.equals( getFormat(), that.getFormat() );
103     }
104 
105     /** {@inheritDoc} */
106     @Override
107     public int hashCode()
108     {
109         return Objects.hash( getFormat() );
110     }
111 
112     /** {@inheritDoc} */
113     @Override
114     public String toString()
115     {
116         return "format = '" + getFormat() + "'";
117     }
118 }