View Javadoc

1   /**
2    *
3    * The contents of this file are subject to the Mozilla Public License Version 1.1
4    * (the "License"); you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at http://www.mozilla.org/MPL
6    * Software distributed under the License is distributed on an "AS IS" basis,
7    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
8    * specific language governing rights and limitations under the License.
9    *
10   * The Initial Developer of the Original Code is University Health Network. Copyright (C)
11   * 2001.  All Rights Reserved.
12   *
13   * Alternatively, the contents of this file may be used under the terms of the
14   * GNU General Public License (the  "GPL"), in which case the provisions of the GPL are
15   * applicable instead of those above.  If you wish to allow use of your version of this
16   * file only under the terms of the GPL and not to allow others to use your version
17   * of this file under the MPL, indicate your decision by deleting  the provisions above
18   * and replace  them with the notice and other provisions required by the GPL License.
19   * If you do not delete the provisions above, a recipient may use your version of
20   * this file under either the MPL or the GPL.
21   */
22  package ca.uhn.hl7v2.testpanel.util.compare;
23  
24  import java.util.List;
25  
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import ca.uhn.hl7v2.model.Type;
30  
31  public class FieldComparison {
32      private static final Logger ourLog = LoggerFactory.getLogger(FieldComparison.class);
33  
34      private Boolean mySame;
35      private List<Type> myDiffFields1;
36      private List<Type> myDiffFields2;
37      private List<Type> mySameFields;
38      private String myFieldName;
39  
40      //~ Constructors ---------------------------------------------------------------------------------------------------
41  
42      public FieldComparison(String theFieldName, List<Type> theSameFields, List<Type> theDiffFields1,
43                             List<Type> theDiffFields2) {
44          myFieldName = theFieldName;
45          mySameFields = theSameFields;
46          myDiffFields1 = theDiffFields1;
47          myDiffFields2 = theDiffFields2;
48          
49          if (ourLog.isInfoEnabled()) {
50          	if (!isSame()) {
51          		ourLog.debug("New field comparison found with difference");
52          	}
53          }
54      }
55  
56      //~ Methods --------------------------------------------------------------------------------------------------------
57  
58      public List<Type> getDiffFieldsActual() {
59          return myDiffFields2;
60      }
61  
62      public List<Type> getDiffFieldsExpected() {
63          return myDiffFields1;
64      }
65  
66      private int getFieldCount() {
67          return mySameFields.size();
68      }
69  
70      public String getFieldName() {
71          return myFieldName;
72      }
73  
74      public List<Type> getSameFields() {
75          return mySameFields;
76      }
77  
78      public boolean isSame() {
79          if (mySame == null) {
80              mySame = true;
81  
82              for (int i = 0; i < getFieldCount(); i++) {
83                  if (myDiffFields1.get(i) != null) {
84                      mySame = false;
85  
86                      break;
87                  }
88              }
89          }
90  
91          return mySame;
92      }
93  }