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.Collections;
25  import java.util.List;
26  
27  import ca.uhn.hl7v2.model.Segment;
28  
29  public class SegmentComparison extends StructureComparison {
30      //~ Instance fields ------------------------------------------------------------------------------------------------
31  
32      private Boolean mySame;
33      private List<FieldComparison> myFieldComparisons;
34      private Segment myActualSegment;
35      private Segment myExpectSegment;
36      private String myName;
37  
38      //~ Constructors ---------------------------------------------------------------------------------------------------
39  
40      public SegmentComparison(String theName, List<FieldComparison> theFieldComparisons) {
41          myFieldComparisons = theFieldComparisons;
42          myName = theName;
43      }
44  
45      public SegmentComparison(String theName, Segment../../../ca/uhn/hl7v2/model/Segment.html#Segment">Segment theExpectSegment, Segment theActualSegment) {
46          myExpectSegment = theExpectSegment;
47          myActualSegment = theActualSegment;
48          myName = theName;
49      }
50  
51      //~ Methods --------------------------------------------------------------------------------------------------------
52  
53      @Override
54      public List<SegmentComparison> flattenMessage() {
55          return Collections.singletonList(this);
56      }
57  
58      public Segment getActualSegment() {
59          return myActualSegment;
60      }
61  
62      public Segment getExpectSegment() {
63          return myExpectSegment;
64      }
65  
66      public List<FieldComparison> getFieldComparisons() {
67          return myFieldComparisons;
68      }
69  
70      public String getName() {
71          return myName;
72      }
73  
74      public boolean isSame() {
75          if (mySame == null) {
76              if (myFieldComparisons != null) {
77                  mySame = true;
78  
79                  for (FieldComparison next : myFieldComparisons) {
80                      if (! next.isSame()) {
81                          mySame = false;
82  
83                          break;
84                      }
85                  }
86              } else {
87                  mySame = false;
88              }
89          }
90  
91          return mySame;
92      }
93  }