コード例 #1
0
 long computeFieldSize(BaseType bt, boolean isAscii) throws Exception {
   long fieldsize = 0;
   // Figure out what this field is (e.g. primitive or not)
   // Somewhat convoluted.
   if (bt instanceof DConstructor) {
     // simple struct, seq, or grid => recurse
     fieldsize = computeSize((DConstructor) bt, isAscii);
   } else if (bt instanceof DArray) {
     SDArray da = (SDArray) bt;
     // Separate structure arrays from primitive arrays
     if (da.getContainerVar() instanceof DPrimitive) {
       fieldsize = computeArraySize(da);
     } else if (da.getContainerVar() instanceof DStructure) {
       fieldsize = computeSize((DStructure) da.getContainerVar(), isAscii); // recurse
     } else { // Some kind of problem
       throw new NoSuchTypeException("Computesize: unexpected type for " + bt.getLongName());
     }
   } else if (bt instanceof DPrimitive) {
     DPrimitive dp = (DPrimitive) bt;
     if (dp instanceof DString) {
       String v = ((DString) dp).getValue();
       fieldsize = (v == null ? 0 : v.length());
     } else {
       DataType dtype = DODSNetcdfFile.convertToNCType(bt);
       fieldsize = dtype.getSize();
     }
   } else { // Some kind of problem
     throw new NoSuchTypeException("Computesize: unknown type for " + bt.getLongName());
   }
   return fieldsize;
 }
コード例 #2
0
 // Recursively compute size of the dds to be returned
 private long computeSize(DConstructor ctor, boolean isAscii) throws Exception {
   long projectsize = 0; // accumulate size of projected variables
   long othersize = 0; // accumulate size of non-projected variables
   long fieldsize = 0;
   int projectedcount = 0;
   int fieldcount = 0;
   Enumeration vars = ctor.getVariables();
   while (vars.hasMoreElements()) {
     fieldcount++;
     BaseType field = (BaseType) vars.nextElement();
     fieldsize = computeFieldSize(field, isAscii);
     // accumulate the field sizes
     if (field.isProject()) {
       projectsize += fieldsize;
       projectedcount++;
     } else {
       othersize += fieldsize;
     }
   }
   // Cases to consider:
   // 1. If all of the fields of this ctor are projected,
   //    then return projectsize
   // 2. If none of the fields of this ctor are projected,
   //    then return othersize
   // 3. otherwise, at least one field, but not all, is projected,
   //    => return projectsize;
   if (projectedcount == fieldcount) return projectsize;
   else if (projectedcount == 0) return othersize;
   else {
     assert (projectedcount > 0 && projectedcount < fieldcount);
     return projectsize;
   }
 }
コード例 #3
0
 boolean containsChild(BaseType node, List<BaseType> list) {
   String nodename = node.getLongName();
   for (BaseType child : list) {
     String childname = child.getLongName();
     if (childname.startsWith(nodename)) return true;
   }
   return false;
 }
コード例 #4
0
 BaseType containsParent(BaseType node, List<BaseType> list) {
   String nodename = node.getLongName();
   for (BaseType parent : list) {
     String parentname = parent.getLongName();
     if (nodename.startsWith(parentname)) return parent;
   }
   return null;
 }
コード例 #5
0
 void gendimrange(List<BaseType> path, StringBuilder buf) {
   for (int i = 0; i < path.size(); i++) {
     BaseType bt = path.get(i);
     int rank = 0;
     if (bt.getParent() instanceof DArray) rank = ((DArray) (bt.getParent())).numDimensions();
     if (i > 0) buf.append('.');
     buf.append(bt.getEncodedName());
     for (int j = 0; j < rank; j++) {
       String dimprojection = dimrangeset[random.nextInt(dimrangeset.length)];
       buf.append(dimprojection);
     }
   }
 }
コード例 #6
0
  public boolean isMatch(Type type) {
    if (type instanceof GenericArrayType) {
      GenericArrayType aType = (GenericArrayType) type;

      return _componentType.equals(aType.getGenericComponentType());
    } else return false;
  }
コード例 #7
0
  public boolean equals(Object o) {
    if (o == this) return true;
    else if (o instanceof GenericArrayType) {
      GenericArrayType type = (GenericArrayType) o;

      return _componentType.equals(type.getGenericComponentType());
    } else return false;
  }
コード例 #8
0
 @Override
 public String getSimpleName() {
   return _componentType.getSimpleName() + "[]";
 }
コード例 #9
0
 public int hashCode() {
   return 17 + 37 * _componentType.hashCode();
 }
コード例 #10
0
 public Type getGenericComponentType() {
   return _componentType.toType();
 }