View Javadoc

1   package fr.in2p3.jsaga.impl.attributes;
2   
3   import org.ogf.saga.error.*;
4   
5   /* ***************************************************
6   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
7   * ***             http://cc.in2p3.fr/             ***
8   * ***************************************************
9   * File:   DefaultAttributeVector
10  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
11  * Date:   12 juin 2007
12  * ***************************************************
13  * Description:                                      */
14  /**
15   * This class is a friend of AbstractAttributesImpl
16   */
17  public class DefaultAttributeVector extends DefaultAttributeAbstract implements AttributeVector {
18      private String[] m_values;
19  
20      /** constructor for friend classes */
21      DefaultAttributeVector(String key, boolean isSupported, boolean isReadOnly, String[] values) {
22          super(key, isSupported, isReadOnly);
23          m_values = values;
24      }
25      /** constructor */
26      public DefaultAttributeVector(String key, String[] values) {
27          super(key);
28          m_values = values;
29      }
30  
31      /** clone */
32      public DefaultAttributeVector clone() throws CloneNotSupportedException {
33          DefaultAttributeVector clone = (DefaultAttributeVector) super.clone();
34          clone.m_values = new String[m_values.length];
35          System.arraycopy(m_values, 0, clone.m_values, 0, m_values.length);
36          return clone;
37      }
38  
39      public void setValues(String[] values) throws NotImplementedException, IncorrectStateException, PermissionDeniedException {
40          this.checkSupported();
41          this.checkWritable();
42          m_values = values;
43      }
44      
45      public String[] getValues() throws NotImplementedException, IncorrectStateException {
46          this.checkSupported();
47          return m_values;
48      }
49  
50      public boolean equals(Object o) {
51          if (!(o instanceof DefaultAttributeVector)) {
52              return false;
53          }
54          DefaultAttributeVector attribute = (DefaultAttributeVector) o;
55          if (!super.getKey().equals(attribute.getKey())) {
56              return false;
57          }
58          if (m_values==null) {
59              return (attribute.m_values==null);
60          }
61          if (attribute.m_values==null) {
62              return (m_values==null);
63          }
64          if (m_values.length != attribute.m_values.length) {
65              return false;
66          }
67          for (int i=0; i<m_values.length; i++) {
68              String v1 = m_values[i];
69              String v2 = attribute.m_values[i];
70              if (v1==null) {
71                  if (v2 != null) {
72                      return false;
73                  }
74              } else {
75                  if (!v1.equals(v2)) {
76                      return false;
77                  }
78              }
79          }
80          return true;
81      }
82  }