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 2940 2007-09-27 20:21:35Z 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: 2940 $
27   * 
28   */
29  public class GroupDefinition extends Definition implements DictionaryTokens {
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          objectType = OBJECT_TYPE_GENERIC_GROUP;
38      }
39      
40      /***
41       * Lists the optional elements that can appear in this group
42       * @return Returns the names optional elements.
43       */
44      public List getOptionalElements() {
45          return optionalElements;
46      }
47      
48      /***
49       * @param optionalElements The names of optional elements.
50       */
51      public void setOptionalElements(List optionalElements) {
52          this.optionalElements = optionalElements;
53      }
54      
55      /***
56       * @return Returns the names of required elements.
57       */
58      public List getRequiredElements() {
59          return requiredElements;
60      }
61      
62      /***
63       * @param requiredElements The names of required elements.
64       */
65      public void setRequiredElements(List requiredElements) {
66          this.requiredElements = requiredElements;
67      }
68      
69      /***
70       * 
71       * @param identifier
72       * @return Returns the required elements.
73       */
74      public boolean mustHaveElement(String identifier) {
75          return requiredElements.contains(identifier);
76      }
77      
78      /***
79       * 
80       * @param identifier
81       * @return Returns the possible elements.
82       */
83      public boolean canHaveElement(String identifier) {
84          boolean exists = false;
85          exists = requiredElements.contains(identifier);
86          if (exists)
87              return exists;
88          return optionalElements.contains(identifier);
89      }
90      
91      public boolean hasElement(String identifier) {
92          if (requiredElements.contains(identifier) || optionalElements.contains(identifier)) 
93              return true;
94          return false;
95      }
96  }