View Javadoc
1   /*
2    * MoneyWise: Finance Application
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * 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, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.moneywise.data.basic;
18  
19  /**
20   * Asset Direction.
21   */
22  public enum MoneyWiseAssetDirection {
23      /**
24       * To.
25       */
26      TO(1),
27  
28      /**
29       * From.
30       */
31      FROM(2);
32  
33      /**
34       * The String name.
35       */
36      private String theName;
37  
38      /**
39       * Class Id.
40       */
41      private final int theId;
42  
43      /**
44       * Constructor.
45       *
46       * @param uId the Id
47       */
48      MoneyWiseAssetDirection(final int uId) {
49          theId = uId;
50      }
51  
52      /**
53       * Obtain class Id.
54       *
55       * @return the Id
56       */
57      public int getId() {
58          return theId;
59      }
60  
61      @Override
62      public String toString() {
63          /* If we have not yet loaded the name */
64          if (theName == null) {
65              /* Load the name */
66              theName = MoneyWiseBasicResource.getKeyForAssetDirection(this).getValue();
67          }
68  
69          /* return the name */
70          return theName;
71      }
72  
73      /**
74       * Reverse.
75       *
76       * @return the reversed direction
77       */
78      public MoneyWiseAssetDirection reverse() {
79          return this == TO
80                  ? FROM
81                  : TO;
82      }
83  
84      /**
85       * Is this the from direction?
86       *
87       * @return true/false
88       */
89      public boolean isFrom() {
90          return this == FROM;
91      }
92  
93      /**
94       * Is this the to direction?
95       *
96       * @return true/false
97       */
98      public boolean isTo() {
99          return this == TO;
100     }
101 
102     /**
103      * get value from name.
104      *
105      * @param pName the name value
106      * @return the corresponding enum object
107      */
108     public static MoneyWiseAssetDirection fromName(final String pName) {
109         for (MoneyWiseAssetDirection myDir : values()) {
110             if (pName.equals(myDir.toString())) {
111                 return myDir;
112             }
113         }
114         return null;
115     }
116 }