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.quicken.file;
18  
19  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee;
20  import io.github.tonywasher.joceanus.moneywise.quicken.definitions.MoneyWiseQLineType;
21  import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
22  
23  import java.util.Objects;
24  
25  /**
26   * Class representing a Payee.
27   *
28   * @author Tony Washer
29   */
30  public class MoneyWiseQIFPayee
31          implements Comparable<MoneyWiseQIFPayee> {
32      /**
33       * Payee name.
34       */
35      private final String theName;
36  
37      /**
38       * Constructor.
39       *
40       * @param pPayee the Payee
41       */
42      public MoneyWiseQIFPayee(final MoneyWisePayee pPayee) {
43          /* Store data */
44          theName = pPayee.getName();
45      }
46  
47      /**
48       * Constructor.
49       *
50       * @param pPayee the Payee
51       */
52      public MoneyWiseQIFPayee(final String pPayee) {
53          /* Store data */
54          theName = pPayee;
55      }
56  
57      /**
58       * Obtain the Name.
59       *
60       * @return the Name
61       */
62      public String getName() {
63          return theName;
64      }
65  
66      @Override
67      public String toString() {
68          return getName();
69      }
70  
71      @Override
72      public boolean equals(final Object pThat) {
73          /* Handle trivial cases */
74          if (this == pThat) {
75              return true;
76          }
77          if (pThat == null) {
78              return false;
79          }
80  
81          /* Check class */
82          if (!getClass().equals(pThat.getClass())) {
83              return false;
84          }
85  
86          /* Cast correctly */
87          final MoneyWiseQIFPayee myPayee = (MoneyWiseQIFPayee) pThat;
88  
89          /* Check date */
90          return theName.equals(myPayee.getName());
91      }
92  
93      @Override
94      public int hashCode() {
95          return theName.hashCode();
96      }
97  
98      @Override
99      public int compareTo(final MoneyWiseQIFPayee pThat) {
100         return theName.compareTo(pThat.getName());
101     }
102 
103 
104     /**
105      * The Payee line.
106      *
107      * @param <X> the line type
108      */
109     public abstract static class MoneyWiseQIFPayeeLine<X extends MoneyWiseQLineType>
110             extends MoneyWiseQIFLine<X> {
111         /**
112          * The payee.
113          */
114         private final MoneyWiseQIFPayee thePayee;
115 
116         /**
117          * Constructor.
118          *
119          * @param pPayee the Payee
120          */
121         protected MoneyWiseQIFPayeeLine(final MoneyWiseQIFPayee pPayee) {
122             /* Store data */
123             thePayee = pPayee;
124         }
125 
126         @Override
127         public String toString() {
128             return thePayee.toString();
129         }
130 
131         /**
132          * Obtain payee.
133          *
134          * @return the payee
135          */
136         public MoneyWiseQIFPayee getPayee() {
137             return thePayee;
138         }
139 
140         @Override
141         protected void formatData(final OceanusDataFormatter pFormatter,
142                                   final StringBuilder pBuilder) {
143             /* Append the string data */
144             pBuilder.append(thePayee.getName());
145         }
146 
147         @Override
148         public boolean equals(final Object pThat) {
149             /* Handle trivial cases */
150             if (this == pThat) {
151                 return true;
152             }
153             if (pThat == null) {
154                 return false;
155             }
156 
157             /* Check class */
158             if (!getClass().equals(pThat.getClass())) {
159                 return false;
160             }
161 
162             /* Cast correctly */
163             final MoneyWiseQIFPayeeLine<?> myLine = (MoneyWiseQIFPayeeLine<?>) pThat;
164 
165             /* Check line type */
166             if (!getLineType().equals(myLine.getLineType())) {
167                 return false;
168             }
169 
170             /* Check value */
171             return thePayee.equals(myLine.getPayee());
172         }
173 
174         @Override
175         public int hashCode() {
176             return Objects.hash(getLineType(), thePayee);
177         }
178     }
179 }