View Javadoc

1   // Copyright 2006-2007, by the California Institute of Technology.
2   // ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
3   // Any commercial use must be negotiated with the Office of Technology Transfer
4   // at the California Institute of Technology.
5   //
6   // This software is subject to U. S. export control laws and regulations
7   // (22 C.F.R. 120-130 and 15 C.F.R. 730-774). To the extent that the software
8   // is subject to U.S. export control laws and regulations, the recipient has
9   // the responsibility to obtain export licenses or other export authority as
10  // may be required before exporting such information to foreign countries or
11  // providing access to foreign nationals.
12  //
13  // $Id: GroupDefinition.java 2601 2007-04-12 18:34:25Z pramirez $
14  //
15  
16  package gov.nasa.pds.tools.dict;
17  
18  import java.util.List;
19  import java.util.ArrayList;
20  
21  /***
22   * This class models a group definition. Groups can only contain optional
23   * and required elements. This class will only contain the identifiers of these 
24   * elements.
25   * @author pramirez
26   * @version $Revision: 2601 $
27   * 
28   */
29  public class GroupDefinition extends Definition {
30      private List requiredElements;
31      private List optionalElements;
32      
33      public GroupDefinition(String identifier) {
34          super(identifier);
35          requiredElements = new ArrayList();
36          optionalElements = new ArrayList();
37      }
38      
39      /***
40       * Lists the optional elements that can appear in this group
41       * @return Returns the names optional elements.
42       */
43      public List getOptionalElements() {
44          return optionalElements;
45      }
46      
47      /***
48       * @param optionalElements The names of optional elements.
49       */
50      public void setOptionalElements(List optionalElements) {
51          this.optionalElements = optionalElements;
52      }
53      
54      /***
55       * @return Returns the names of required elements.
56       */
57      public List getRequiredElements() {
58          return requiredElements;
59      }
60      
61      /***
62       * @param requiredElements The names of required elements.
63       */
64      public void setRequiredElements(List requiredElements) {
65          this.requiredElements = requiredElements;
66      }
67      
68      /***
69       * 
70       * @param identifier
71       * @return Returns the required elements.
72       */
73      public boolean mustHaveElement(String identifier) {
74          return requiredElements.contains(identifier);
75      }
76      
77      /***
78       * 
79       * @param identifier
80       * @return Returns the possible elements.
81       */
82      public boolean canHaveElement(String identifier) {
83          boolean exists = false;
84          exists = requiredElements.contains(identifier);
85          if (exists)
86              return exists;
87          return optionalElements.contains(identifier);
88      }
89      
90      public boolean hasElement(String identifier) {
91          if (requiredElements.contains(identifier) || optionalElements.contains(identifier)) 
92              return true;
93          return false;
94      }
95  }