View Javadoc
1   package com.soebes.maven.plugins.iterator;
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.util.Objects;
23  import java.util.Properties;
24  
25  /**
26   * Container for items with properties.
27   * 
28   * @author Karl-Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
29   */
30  public class ItemWithProperties
31  {
32      private String name;
33  
34      private Properties properties;
35  
36      public static final Properties NO_PROPERTIES = new Properties();
37  
38      public static final String NO_NAME = "";
39  
40      public ItemWithProperties()
41      {
42          this( NO_NAME, NO_PROPERTIES );
43      }
44  
45      /**
46       * @param name name of the item.
47       * @param properties The object which contains the properties. If you don't have properties simply give
48       *            {@link #NO_PROPERTIES} as parameter.
49       */
50      public ItemWithProperties( String name, Properties properties )
51      {
52          super();
53          this.name = Objects.requireNonNull( name, "name is not allowed to be null." );
54          this.properties = Objects.requireNonNull( properties, "properties is not allowed to be null." );
55      }
56  
57      public String getName()
58      {
59          return name;
60      }
61  
62      public void setName( String name )
63      {
64          this.name = Objects.requireNonNull( name, "name is not allowed to be null." );
65      }
66  
67      public Properties getProperties()
68      {
69          return properties;
70      }
71  
72      public void setProperties( Properties properties )
73      {
74          this.properties = Objects.requireNonNull( properties, "properties is not allowed to be null." );
75      }
76  
77      public boolean hasProperties()
78      {
79          if ( properties == NO_PROPERTIES )
80          {
81              return false;
82          }
83          else
84          {
85              return true;
86          }
87      }
88  
89      public boolean hasName()
90      {
91          if ( name == NO_NAME )
92          {
93              return false;
94          }
95          else
96          {
97              return true;
98          }
99      }
100 
101     @Override
102     public int hashCode()
103     {
104         final int prime = 31;
105         int result = 1;
106         result = prime * result + ( ( name == null ) ? 0 : name.hashCode() );
107         result = prime * result + ( ( properties == null ) ? 0 : properties.hashCode() );
108         return result;
109     }
110 
111     @Override
112     public boolean equals( Object obj )
113     {
114         if ( this == obj )
115             return true;
116         if ( obj == null )
117             return false;
118         if ( getClass() != obj.getClass() )
119             return false;
120         ItemWithProperties other = (ItemWithProperties) obj;
121         if ( name == null )
122         {
123             if ( other.name != null )
124                 return false;
125         }
126         else if ( !name.equals( other.name ) )
127             return false;
128         if ( properties == null )
129         {
130             if ( other.properties != null )
131                 return false;
132         }
133         else if ( !properties.equals( other.properties ) )
134             return false;
135         return true;
136     }
137 
138 }