protected void initChildren()

in uimaj-tools/src/main/java/org/apache/uima/tools/cvd/FSNode.java [221:361]


  protected void initChildren() {
    if (this.children != null) {
      return;
    }
    if ((this.nodeClass != STD_FS) && (this.nodeClass != ARRAY_FS)) {
      return;
    }
    // only FSs or Arrays have children
    if (this.fs == null) {
      return;
    }

    TypeImpl type = getType();
    // CASImpl cas = this.fSTreeModel.getCas();
    if (type.isArray()) {
      int arrayLength = ((CommonArrayFS) fs).size();
      // if (arrayLength > 20) {
      // arrayLength = 20;
      // }

      // FSNode node = null;
      // int arrayPos = cas.getArrayStartAddress((int) this.addr);
      // int nodeClass1;
      // if (cas.isIntArrayType(type)) {
      // nodeClass1 = FSNode.INT_FS;
      // } else if (cas.isFloatArrayType(type)) {
      // nodeClass1 = FSNode.FLOAT_FS;
      // } else if (cas.isStringArrayType(type)) {
      // nodeClass1 = FSNode.STRING_FS;
      // } else if (cas.isByteArrayType(type)) {
      // nodeClass1 = FSNode.BYTE_FS;
      // } else if (cas.isBooleanArrayType(type)) {
      // nodeClass1 = FSNode.BOOL_FS;
      // } else if (cas.isShortArrayType(type)) {
      // nodeClass1 = FSNode.SHORT_FS;
      // } else if (cas.isLongArrayType(type)) {
      // nodeClass1 = FSNode.LONG_FS;
      // } else if (cas.isDoubleArrayType(type)) {
      // nodeClass1 = FSNode.DOUBLE_FS;
      // } else {
      // nodeClass1 = FSNode.STD_FS;
      // }
      List<FSNode> arrayNodes = new ArrayList<>(arrayLength);
      SlotKind kind = type.getComponentSlotKind();
      int nc = k2nc(kind);
      switch (kind) {
        case Slot_Int: {
          int[] a = ((IntegerArray) fs)._getTheArray();
          makeNodes(arrayNodes, arrayLength, i -> new FSNode(this.fSTreeModel, nc, null, a[i], i));
          break;
        }
        case Slot_Float: {
          float[] a = ((FloatArray) fs)._getTheArray();
          makeNodes(arrayNodes, arrayLength,
                  i -> new FSNode(this.fSTreeModel, nc, null, CASImpl.float2int(a[i]), i));
          break;
        }
        case Slot_StrRef: {
          String[] a = ((StringArray) fs)._getTheArray();
          makeNodes(arrayNodes, arrayLength, i -> new FSNode(this.fSTreeModel, nc, a[i], 0, i));
          break;
        }
        case Slot_HeapRef: {
          TOP[] a = ((FSArray) fs)._getTheArray();
          makeNodes(arrayNodes, arrayLength, i -> new FSNode(this.fSTreeModel, nc, a[i], 0, i));
          break;
        }
        case Slot_BooleanRef: {
          boolean[] a = ((BooleanArray) fs)._getTheArray();
          makeNodes(arrayNodes, arrayLength,
                  i -> new FSNode(this.fSTreeModel, nc, null, a[i] ? 1 : 0, i));
          break;
        }
        case Slot_ByteRef: {
          byte[] a = ((ByteArray) fs)._getTheArray();
          makeNodes(arrayNodes, arrayLength, i -> new FSNode(this.fSTreeModel, nc, null, a[i], i));
          break;
        }
        case Slot_ShortRef: {
          short[] a = ((ShortArray) fs)._getTheArray();
          makeNodes(arrayNodes, arrayLength, i -> new FSNode(this.fSTreeModel, nc, null, a[i], i));
          break;
        }
        case Slot_LongRef: {
          long[] a = ((LongArray) fs)._getTheArray();
          makeNodes(arrayNodes, arrayLength, i -> new FSNode(this.fSTreeModel, nc, null, a[i], i));
          break;
        }
        case Slot_DoubleRef: {
          double[] a = ((DoubleArray) fs)._getTheArray();
          makeNodes(arrayNodes, arrayLength,
                  i -> new FSNode(this.fSTreeModel, nc, null, CASImpl.double2long(a[i]), i));
          break;
        }
        default:
          Misc.internalError();
      } // end of switch

      this.children = FSTreeModel.createArrayChildren(0, arrayLength, arrayNodes, this.fSTreeModel);
    } else {
      this.children = new ArrayList<>(type.getNumberOfFeatures());
      FeatureImpl[] feats = type.getFeatureImpls();
      for (FeatureImpl f : feats) {
        SlotKind kind = f.getSlotKind();
        int nc = k2nc(kind);
        switch (kind) {
          case Slot_Boolean:
            children.add(new FSNode(this.fSTreeModel, nc, null, fs.getBooleanValue(f) ? 1 : 0, f));
            break;
          case Slot_Byte:
            children.add(new FSNode(this.fSTreeModel, nc, null, fs.getByteValue(f), f));
            break;
          case Slot_Short:
            children.add(new FSNode(this.fSTreeModel, nc, null, fs.getShortValue(f), f));
            break;
          case Slot_Int:
            children.add(new FSNode(this.fSTreeModel, nc, null, fs.getIntValue(f), f));
            break;
          case Slot_Float:
            children.add(new FSNode(this.fSTreeModel, nc, null,
                    CASImpl.float2int(fs.getFloatValue(f)), f));
            break;
          case Slot_LongRef:
            children.add(new FSNode(this.fSTreeModel, nc, null, fs.getLongValue(f), f));
            break;
          case Slot_DoubleRef:
            children.add(new FSNode(this.fSTreeModel, nc, null,
                    CASImpl.double2long(fs.getDoubleValue(f)), f));
            break;
          case Slot_StrRef:
            children.add(new FSNode(this.fSTreeModel, nc, fs.getStringValue(f), 0, f));
            break;
          case Slot_HeapRef:
            children.add(new FSNode(this.fSTreeModel, nc, fs.getFeatureValue(f), 0, f));
            break;
          default:
            Misc.internalError();
        } // end of switch
      }
    }
  }