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  package org.efaps.admin.event;
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  import java.util.Set;
26  
27  import org.apache.commons.lang3.builder.ToStringBuilder;
28  
29  /**
30   * Class witch is used for getting the Return of the Events.
31   *
32   * @author The eFaps Team
33   * @version $Id$
34   */
35  public class Return
36  {
37      /**
38       * Enumeration for the kind of returned values.
39       */
40      public enum ReturnValues
41      {
42          /** Used to return the instance after creating a new one.*/
43          INSTANCE,
44          /** Used to return code sniplett that will be represented as is. */
45          SNIPLETT,
46          /** Used to return a Map of Values. */
47          VALUES,
48          /** Used to return <i>true</i>. */
49          TRUE;
50      }
51  
52      /**
53       * Map with all returned values.
54       */
55      private final Map<Return.ReturnValues, Object> map = new HashMap<Return.ReturnValues, Object>();
56  
57      /**
58       *
59       * @param _key  searched key
60       * @return found object or <code>null</code> if not found
61       */
62      public Object get(final Return.ReturnValues _key)
63      {
64          return this.map.get(_key);
65      }
66  
67      /**
68       *
69       * @param _key      key to set
70       * @param _value    value to set
71       */
72      public Return put(final Return.ReturnValues _key,
73                        final Object _value)
74      {
75          this.map.put(_key, _value);
76          return this;
77      }
78  
79      /**
80       *
81       * @return set of all values depending on the {@link ReturnValues}
82       */
83      public Set<Map.Entry<Return.ReturnValues, Object>> entrySet()
84      {
85          return this.map.entrySet();
86      }
87  
88      /**
89       *
90       * @return <i>true</i> if the {@link #map} of returned value is empty;
91       *         otherwise <i>false</i>
92       * @see #map
93       */
94      public boolean isEmpty()
95      {
96          return this.map.isEmpty();
97      }
98  
99      /**
100      *
101      * @param _key  searched key
102      * @return <i>true</i> if the <code>_key</code> is defined in the
103      *         {@link #map}; otherwise <i>false</i>
104      * @see #map
105      */
106     public boolean contains(final Return.ReturnValues _key)
107     {
108         return this.map.containsKey(_key);
109     }
110 
111     /**
112      * Returns a string representation of this parameter instance.
113      *
114      * @return string representation of this parameter instance.
115      */
116     @Override
117     public String toString()
118     {
119         return new ToStringBuilder(this)
120             .appendSuper(super.toString())
121             .append("map", this.map.toString())
122             .toString();
123     }
124 }