1   /*
2    * Copyright 2003 - 2013 The eFaps Team
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Revision:        $Rev$
17   * Last Changed:    $Date$
18   * Last Changed By: $Author$
19   */
20  
21  
22  package org.efaps.update;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  
28  /**
29   * Represent an Install or Update Profile.
30   * Implemented to have the change to make this
31   * thing bigger in the future.
32   *
33   * @author The eFaps Team
34   * @version $Id$
35   */
36  public final class Profile
37  {
38      /**
39       * Default Profile.
40       */
41      private static final Profile DEFAULT = new Profile("eFaps");
42  
43      /**
44       * The mapping of all names to their Profiles.
45       */
46      private static final Map<String, Profile> NAME2PROFILE = new  HashMap<String, Profile>();
47  
48      /**
49       * Name of the Profile.
50       */
51      private final String name;
52  
53      /**
54       * @param _name the name of the Profile
55       */
56      private Profile(final String _name)
57      {
58          this.name = _name;
59      }
60  
61      /**
62       * Getter method for the instance variable {@link #name}.
63       *
64       * @return value of instance variable {@link #name}
65       */
66      public String getName()
67      {
68          return this.name;
69      }
70  
71      @Override
72      public String toString()
73      {
74          return this.name;
75      }
76  
77      @Override
78      public int hashCode()
79      {
80          return this.name.hashCode();
81      }
82  
83      @Override
84      public boolean equals(final Object _object)
85      {
86          boolean ret;
87          if (_object instanceof Profile) {
88              ret = this.name.equals(((Profile) _object).getName());
89          } else {
90              ret = false;
91          }
92          return ret;
93      }
94  
95      /**
96       * @return default Profile
97       */
98      public static Profile getDefaultProfile()
99      {
100         return Profile.DEFAULT;
101     }
102 
103     /**
104      * @param _name name of a profile
105      * @return the profile for the given name
106      */
107     public static Profile getProfile(final String _name)
108     {
109         final Profile ret;
110         if (Profile.NAME2PROFILE.containsKey(_name)) {
111             ret = Profile.NAME2PROFILE.get(_name);
112         } else {
113             ret = new Profile(_name);
114         }
115         return ret;
116     }
117 }