org.apache.uima.jcas.cas.LongArray Java Examples

The following examples show how to use org.apache.uima.jcas.cas.LongArray. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public TOP createArray(TypeImpl array_type, int arrayLength) {
    TypeImpl_array tia = (TypeImpl_array) array_type;
    TypeImpl componentType = tia.getComponentType();
    if (componentType.isPrimitive()) {
      checkArrayPreconditions(arrayLength);
      switch (componentType.getCode()) {
      case intTypeCode: return new IntegerArray(array_type, this, arrayLength);
      case floatTypeCode: return new FloatArray(array_type, this, arrayLength);
      case booleanTypeCode: return new BooleanArray(array_type, this, arrayLength);
      case byteTypeCode: return new ByteArray(array_type, this, arrayLength);
      case shortTypeCode: return new ShortArray(array_type, this, arrayLength);
      case longTypeCode: return new LongArray(array_type, this, arrayLength);
      case doubleTypeCode: return new DoubleArray(array_type, this, arrayLength);
      case stringTypeCode: return new StringArray(array_type, this, arrayLength);
      default: throw Misc.internalError();
      }
    }
//    return (TOP) createArrayFS(/* array_type, */ arrayLength);  // for backwards compat w/ v2, don't create typed arrays
    if (IS_DISABLE_SUBTYPE_FSARRAY_CREATION) {
      return (TOP) createArrayFS(arrayLength);
    } else {
      return (TOP) createArrayFS(array_type, arrayLength);
    }
  }
 
Example #2
Source File: NewFeatureUtils.java    From baleen with Apache License 2.0 5 votes vote down vote up
private static LongArray getLongArray(JCas jCas, Collection<?> list) {
  final LongArray a = new LongArray(jCas, list.size());
  int i = 0;
  for (final Object s : list) {
    a.set(i++, ((Number) s).longValue());
  }
  return a;
}
 
Example #3
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public LongArray emptyLongArray() {
    if (null == svd.emptyLongArray) {
      svd.emptyLongArray = new LongArray(this.getJCas(), 0);
    }
    return svd.emptyLongArray;
  }
 
Example #4
Source File: FeatureStructureImplC.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private boolean isOkArray(TypeImpl range, Object v) {
    if (v == null) {
      return true;
    }
    
    
    final int rangeTypeCode = range.getCode();

    /* The assignment is stricter than the Java rules - must match */
    switch (rangeTypeCode) {
    case TypeSystemConstants.booleanArrayTypeCode:
      return v instanceof BooleanArray;
    case TypeSystemConstants.byteArrayTypeCode:
    return v instanceof ByteArray;
    case TypeSystemConstants.shortArrayTypeCode:
      return v instanceof ShortArray;
    case TypeSystemConstants.intArrayTypeCode:
      return v instanceof IntegerArray;
    case TypeSystemConstants.floatArrayTypeCode:
      return v instanceof FloatArray;
    case TypeSystemConstants.longArrayTypeCode:
      return v instanceof LongArray;
    case TypeSystemConstants.doubleArrayTypeCode:
      return v instanceof DoubleArray;
    case TypeSystemConstants.stringArrayTypeCode:
      return v instanceof StringArray;
//    case TypeSystemConstants.javaObjectArrayTypeCode:
//      return v instanceof JavaObjectArray;
    case TypeSystemConstants.fsArrayTypeCode:
      return v instanceof FSArray;
    }
    
    // it is possible that the array has a special type code corresponding to a type "someUserType"[]
    //   meaning an array of some user type.  UIMA implements these as instances of FSArray (I think)
    
    if (!(v instanceof FSArray)) { return false; }
    
    return true;
  }
 
Example #5
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static LongArray createLongArray(JCas aJCas, Collection<Long> aCollection) {
  return fillArray(new LongArray(aJCas, aCollection.size()), aCollection);
}
 
Example #6
Source File: CasComparer.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param fs1
 * @param fs2
 * @param visited when called for sorting FSs, is sortCompareSeen(cleared); 
 *                when called for comparing for equality, holds FSs already compared in other views
 * @return
 */
private int compare1(TOP fs1, TOP fs2, Set<TOP> visited) {
  if (!isSortUse) {  // only do null check for non- sort use
    if (fs1 == null && fs2 == null) {
      return 0;
    }
    if (fs1 == null) return chkEqual(-1, "fs1 was null and fs2 was not");
    if (fs2 == null) return chkEqual(1,  "fs2 was null and fs1 was not");
  }
  
  boolean wasPresent1 = !visited.add(fs1);
  boolean wasPresent2 = !visited.add(fs2);
  
  if (wasPresent1 && wasPresent2) {
    return 0;  // already checked and found equal
  }
  
  if (!wasPresent1 && !wasPresent2) {
    int r;
    TypeImpl t1, t2;
    if (0 != (r = compStr((t1 = (TypeImpl) fs1.getType()).getName(), (t2 = (TypeImpl) fs2.getType()).getName()))) {
      return chkEqual(r, "Types of FSs are different: Type1 = %s, Type2 = %s", t1, t2);
    }
    // types are the same
    
    if (CAS.TYPE_NAME_SOFA.equals(t1.getName())) {
      if (isSortUse) {
        return Integer.compare(((Sofa)fs1).getSofaNum(), ((Sofa)fs2).getSofaNum());
      }
      return 0;  // skip comparing sofa so this routine can be used for cas copier testing
    }

    if (t1.isArray()) {
      final int len1 = ((CommonArrayFS)fs1).size();
      if (0 != (r = Integer.compare(len1, ((CommonArrayFS)fs2).size()))) {
        return r;
      }
      
      SlotKind kind = t1.getComponentSlotKind();
      
      switch(kind) {
      case Slot_BooleanRef: return compareAllArrayElements(len1, i -> Boolean.compare(((BooleanArray  )fs1).get(i), ((BooleanArray)fs2).get(i)), "Miscompare Boolean Arrays %n%s%n%s", fs1, fs2);
      case Slot_ByteRef:    return compareAllArrayElements(len1, i -> Byte   .compare(((ByteArray     )fs1).get(i), ((ByteArray   )fs2).get(i)), "Miscompare Byte Arrays %n%s%n%s"   , fs1, fs2);
      case Slot_ShortRef:   return compareAllArrayElements(len1, i -> Short  .compare(((ShortArray    )fs1).get(i), ((ShortArray  )fs2).get(i)), "Miscompare Short Arrays %n%s%n%s"  , fs1, fs2);
      case Slot_Int:     return compareAllArrayElements   (len1, i -> Integer.compare(((IntegerArray  )fs1).get(i), ((IntegerArray)fs2).get(i)), "Miscompare Integer Arrays %n%s%n%s", fs1, fs2);
      case Slot_LongRef:    return compareAllArrayElements(len1, i -> Long   .compare(((LongArray     )fs1).get(i), ((LongArray   )fs2).get(i)), "Miscompare Long Arrays %n%s%n%s", fs1, fs2);
      case Slot_Float:   return compareAllArrayElements   (len1, i -> Integer.compare(Float.floatToRawIntBits   (((FloatArray )fs1).get(i)), 
                                                                                      Float.floatToRawIntBits   (((FloatArray )fs2).get(i))),    "Miscompare Float Arrays %n%s%n%s", fs1, fs2);
      case Slot_DoubleRef:  return compareAllArrayElements(len1, i -> Long   .compare(Double.doubleToRawLongBits(((DoubleArray)fs1).get(i)), 
                                                                                      Double.doubleToRawLongBits(((DoubleArray)fs2).get(i))),    "Miscompare Double Arrays %n%s%n%s", fs1, fs2);
      case Slot_HeapRef: return    compareAllArrayElements(len1, i ->        compare1((TOP)((FSArray<?>       )fs1).get(i), (TOP)((FSArray<?> )fs2).get(i), visited), "Miscompare FS Arrays %n%s%n%s", fs1, fs2);
      case Slot_StrRef:  return    compareAllArrayElements(len1, i -> Misc.compareStrings(((StringArray   )fs1).get(i), ((StringArray )fs2).get(i)), "Miscompare String Arrays %n%s%n%s", fs1, fs2);
      default: 
        Misc.internalError(); return 0;  // only to avoid a compile error
      }        
    }
    
    ts = fs1.getCAS().getTypeSystem();
    return compareFeatures(fs1, fs2, t1.getFeatureImpls(), t2.getFeatureImpls(), visited);           
  }
  
  // getting here: one was already traversed, the other not.  Possible use case:
  //   fs1 is a list with a loop; fs2 is a list without a loop
  //   arbitrarily return the one with a loop first
  
  if (fs1 instanceof EmptyList) { 
    return 0;  // allow different or shared EmptyList instances to compare equal
    // because some deserializers or user code can create them as shared or not
  }
  if (wasPresent1) {
    return chkEqual(-1, "First element had a ref loop %s%n, second didn't so far %s", fs1, fs2);
  }
  return chkEqual(-1, "Second element had a ref loop %s%n, first didn't so far %s", fs2, fs1);
  
}
 
Example #7
Source File: CAS.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/** 
 * @return a lazily created shared (for this CAS) 0-length array
 */
default LongArray emptyLongArray() {
  return ((CASImpl)getLowLevelCAS()).emptyLongArray();
}
 
Example #8
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void ll_setLongArrayValue(int fsRef, int position, long value) {
  ((LongArray) getFsFromId_checked(fsRef)).set(position, value);
}
 
Example #9
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public long ll_getLongArrayValue(int fsRef, int position) {
  return ((LongArray) getFsFromId_checked(fsRef)).get(position);
}
 
Example #10
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public LongArrayFS createLongArrayFS(int length) throws CASRuntimeException {
  checkArrayPreconditions(length);
  return new LongArray(this.getJCas(), length);
}
 
Example #11
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static LongArray fillArray(LongArray aArray, long... aValues) {
  return (LongArray) fillArrayFS(aArray, aValues);
}
 
Example #12
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static LongArray fillArray(LongArray aArray, Iterable<Long> aValues) {
  return (LongArray) fillArrayFS(aArray, aValues);
}
 
Example #13
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static LongArray createLongArray(JCas aJCas, long... aArray) {
  return fillArray(new LongArray(aJCas, aArray.length), aArray);
}
 
Example #14
Source File: JCas.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve a lazily-created constant from the cas which holds a 0-length instance. 
 * Since this can be a common value, we
 * avoid creating multiple copies of it. All uses can use the same value because it is not
 * updatable (it has no subfields). This is initialized lazily on first reference, and reset when
 * the CAS is reset.
 * @return 0-length instance of a LongArray
 */
default LongArray emptyLongArray() {
  return this.getCas().emptyLongArray();
}
 
Example #15
Source File: Root.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** getter for arrayLong - gets 
 * @generated
 * @return value of the feature 
 */
public LongArray getArrayLong() { return (LongArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_arrayLong)));}
 
Example #16
Source File: Root.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** setter for arrayLong - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setArrayLong(LongArray v) {
  _setFeatureValueNcWj(wrapGetIntCatchException(_FH_arrayLong), v);
}
 
Example #17
Source File: Root.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** indexed getter for arrayLong - gets an indexed value - 
 * @generated
 * @param i index in the array to get
 * @return value of the element at index i 
 */
public long getArrayLong(int i) {
   return ((LongArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_arrayLong)))).get(i);}
 
Example #18
Source File: Root.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** indexed setter for arrayLong - sets an indexed value - 
 * @generated
 * @param i index in the array to set
 * @param v value to set into the array 
 */
public void setArrayLong(int i, long v) {
  ((LongArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_arrayLong)))).set(i, v);
}