Jörn Kottmann wrote:
> Hello,
> 
> how can I get the size of an array type ?
> 
> I have a fs where fs.getType().isArray() == true.
> Now I woud like to know the size of the array.
> 
> Thanks,
> Jörn

Good question.  Looks like there is no elegant way
of doing this.  There's an interface called CommonArrayFS
that defines the size() method, but ArrayFS doesn't
extend it.  So here's what you can do, but don't
tell anyone ;-)

  public static final int getArrayLength(FeatureStructure fs) {
    // Check that FS is not null and is array FS
    if ((fs != null) && fs.getType().isArray()) {
      // Acquire low-level CAS
      LowLevelCAS llc = fs.getCAS().getLowLevelCAS();
      // Use low-level method to retrieve array size
      return llc.ll_getArraySize(llc.ll_getFSRef(fs));
    }
    throw new IllegalArgumentException((fs == null) ? "<null>" : fs.toString());
  }

Note that I haven't tested this code, so it
may be buggy...

Does anybody know why ArrayFS does not extend
CommonArrayFS?  Anything riding on that?  If
nobody screams, I'll open a Jira issue and fix
this for the next release.  Then you can get
the array length with

((CommonArrayFS) fs).size();

--Thilo

Reply via email to