public float getFloatValue(Feature feat) throws CASRuntimeException { final TypeSystemImpl ts = this.getCASImpl().getTypeSystemImpl(); if (!ts.subsumes(feat.getDomain(), getType())) { throwUndefinedFeatureExc(feat, getType()); } if (!ts.subsumes(feat.getRange(), ts.getType(CAS.TYPE_NAME_FLOAT))) { throwIllegalRangeExc(feat, ts.getType(CAS.TYPE_NAME_FLOAT)); } final int featCode = ((FeatureImpl) feat).getCode(); return this.getCASImpl().getFloatValue(this.getAddress(), featCode); }
public Object clone() throws CASRuntimeException { if (getType().getName().equals(CAS.TYPE_NAME_SOFA)) { throw new CASRuntimeException(CASRuntimeException.CANNOT_CLONE_SOFA); } CASImpl casImpl = this.getCASImpl(); FeatureStructure newFS = getCAS().createFS(getType()); casImpl.copyFeatures(((FeatureStructureImpl) newFS).getAddress(), this.getAddress()); return newFS; }
private final void getPrintRefs(PrintReferences printRefs) { getPrintRefs(printRefs, this.getAddress()); }
public void prettyPrint(int indent, int incr, StringBuffer buf, boolean useShortNames, String s) { PrintReferences printRefs = new PrintReferences(); getPrintRefs(printRefs); prettyPrint(indent, incr, buf, useShortNames, s, printRefs); }
public int getavoidcollisionTypeCode() { return this.getCASImpl().getHeapValue(this.getAddress()); }
private static int[] getAddresses(FeatureStructureImpl[] annotations) { int[] result = new int[annotations.length]; for (int i = 0; i < annotations.length; i++) { result[i] = annotations[i].getAddress(); } return result; }
public void prettyPrint(int indent, int incr, StringBuffer buf, boolean useShortNames, String s, PrintReferences printRefs) { final Type stringType = this.getCASImpl().getTypeSystem().getType(CAS.TYPE_NAME_STRING); final int printInfo = printRefs.printInfo(this.getAddress()); if (printInfo != PrintReferences.NO_LABEL) { buf.append(printRefs.getLabel(this.getAddress())); if (printInfo == PrintReferences.JUST_LABEL) { buf.append('\n'); buf.append(getType().getShortName()); } else { buf.append(getType().getName()); LowLevelTypeSystem llts = this.getCASImpl().ll_getTypeSystem(); final int typeClass = this.getCASImpl().ll_getTypeClass(llts.ll_getCodeForType(this.getType())); final int arrayLen = getCASImpl().ll_getArraySize(this.getAddress()); StringUtils.printSpaces(indent, buf); buf.append("Array length: " + arrayLen + "\n"); String element = this.getCASImpl().ll_getStringArrayValue(this.getAddress(), i); buf.append("\"" + element + "\""); final int arrayLen = getCASImpl().ll_getArraySize(this.getAddress()); StringUtils.printSpaces(indent, buf); buf.append("Array length: " + arrayLen + "\n"); int element = this.getCASImpl().ll_getIntArrayValue(this.getAddress(), i); buf.append(element);
public void setFeatureValue(Feature feat, FeatureStructure fs) { final int valueAddr = this.getCASImpl().ll_getFSRef(fs); final int featCode = ((FeatureImpl) feat).getCode(); final int rangeType = this.getCASImpl().getTypeSystemImpl().range(featCode); if (valueAddr == CASImpl.NULL) { setNullValue(featCode, rangeType); return; } final int thisType = this.getCASImpl().getHeapValue(this.getAddress()); final int valueType = this.getCASImpl().getHeapValue(valueAddr); if (!this.getCASImpl().getTypeSystemImpl().isApprop(thisType, featCode)) { CASRuntimeException e = new CASRuntimeException(CASRuntimeException.INAPPROP_TYPE, new String[] { feat.getName(), this.getType().getName() }); throw e; } if (!this.getCASImpl().getTypeSystemImpl().subsumes(rangeType, valueType)) { CASRuntimeException e = new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, new String[] { feat.getName(), feat.getRange().getName(), fs.getType().getName() }); throw e; } // keys are not fsRefs this.getCASImpl().setFeatureValueNoIndexCorruptionCheck(this.getAddress(), featCode, valueAddr); }
void traceFSfs(FeatureStructureImpl fs) { StringBuilder b = svd.traceFScreationSb; svd.traceFSid = fs.getAddress(); b.append("c:").append(String.format("%-3d", getCasId())); String viewName = fs.getCAS().getViewName(); if (null == viewName) { viewName = "base"; } b.append(" v:").append(MiscImpl.elide(viewName, 8)); b.append(" i:").append(String.format("%-5s", fs.getAddress())); b.append(" t:").append(MiscImpl.elide(fs.getType().getShortName(), 10)); }
/****************************************** * DEBUGGING and TRACING * ******************************************/ void traceFSCreate(FeatureStructureImpl fs) { StringBuilder b = svd.traceFScreationSb; if (b.length() > 0) { traceFSflush(); } traceFSfs(fs); svd.traceFSisCreate = true; if (fs.getType().isArray()) { int arraySize = ll_getArraySize(fs.getAddress()); b.append(" l:").append(arraySize); } if (fs.getAddress() > 190000 && fs.getAddress() < 200000 && fs.getType().getShortName().equals("Passage")) { traceOut.println("Passage callback: " + MiscImpl.getCallers(3, 10)); } }
@Override public final int ll_getFSRef(FeatureStructure fsImpl) { if (null == fsImpl) { return NULL; } final FeatureStructureImpl fsi = (FeatureStructureImpl) fsImpl; if (this != fsi.getCASImpl()) { if (this.getBaseCAS() != fsi.getCASImpl().getBaseCAS()) { // https://issues.apache.org/jira/browse/UIMA-3429 throw new CASRuntimeException(CASRuntimeException.DEREF_FS_OTHER_CAS, new Object[] {fsi.toString(), this.toString() } ); } } return fsi.getAddress(); }
public boolean match(FeatureStructure fs) { compile(((FeatureStructureImpl) fs).getCAS().getTypeSystem()); final FeatureStructureImpl fsi = (FeatureStructureImpl) fs; final int typeCode = fsi.getCASImpl().getHeapValue(fsi.getAddress()); TypeSystemImpl tsi = (TypeSystemImpl) this.ts; for (int i = 0; i < typeSet.size(); i++) { if (tsi.subsumes(typeSet.get(i), typeCode)) { return true; } } return false; }
public FeatureStructure getFeatureValue(Feature feat) throws CASRuntimeException { final TypeSystemImpl ts = this.getCASImpl().getTypeSystemImpl(); // final int featCode = ts.getFeatureCode(feat.getName()); final int featCode = ((FeatureImpl) feat).getCode(); // assert(featCode > 0); if (!ts.isApprop(this.getCASImpl().getHeapValue(this.getAddress()), featCode)) { CASRuntimeException e = new CASRuntimeException(CASRuntimeException.INAPPROP_FEAT, new String[] { feat.getName(), this.getType().getName() }); throw e; } // Check that feature value is not primitive. final int rangeTypeCode = ts.ll_getRangeType(featCode); if (!this.getCASImpl().ll_isRefType(rangeTypeCode)) { CASRuntimeException e = new CASRuntimeException(CASRuntimeException.PRIMITIVE_VAL_FEAT, new String[] { feat.getName() }); throw e; } final int valAddr = this.getCASImpl().getFeatureValue(this.getAddress(), featCode); // assert(valAddr > 0); return this.getCASImpl().createFS(valAddr); }
private final void getPrintRefs(PrintReferences printRefs, int ref) { boolean seenBefore = printRefs.addReference(ref); if (seenBefore) { return; } LowLevelCAS llcas = this.getCASImpl().getLowLevelCAS(); LowLevelTypeSystem llts = llcas.ll_getTypeSystem(); final int typeCode; try { typeCode = llcas.ll_getFSRefType(ref, true); } catch (LowLevelException e) { return; // can't find ref, may be invalid or null } int[] feats = llts.ll_getAppropriateFeatures(typeCode); for (int i = 0; i < feats.length; i++) { if (llcas.ll_isRefType(llts.ll_getRangeType(feats[i]))) { int valRef = llcas.ll_getRefValue(ref, feats[i]); if (valRef != LowLevelCAS.NULL_FS_REF) { getPrintRefs(printRefs, valRef); } } } }
public static int getAddr(FeatureStructure aFS) { return ((FeatureStructureImpl) aFS).getAddress(); }
public boolean isNew(FeatureStructure fs) { //check if same CAS instance //TODO: define a CASRuntimeException if (!isValid || ((FeatureStructureImpl) fs).getCASImpl() != this.cas) { CASRuntimeException e = new CASRuntimeException( CASRuntimeException.CAS_MISMATCH, new String[] { "FS and Marker are not from the same CAS." }); throw e; } return isNew( ((FeatureStructureImpl) fs).getAddress()); }
int arraySize = this.ll_getArraySize(fs.getAddress()); ByteBuffer buf = null; Type type = fs.getType(); if (type.getName().equals(CAS.TYPE_NAME_STRING_ARRAY)) { StringBuffer sb = new StringBuffer(); return bis; } else if (type.getName().equals(CAS.TYPE_NAME_INTEGER_ARRAY)) { arrayStart = getArrayStartAddress(fs.getAddress()); buf = ByteBuffer.allocate(arraySize * 4); IntBuffer intbuf = buf.asIntBuffer(); return bis; } else if (type.getName().equals(CAS.TYPE_NAME_FLOAT_ARRAY)) { arrayStart = getArrayStartAddress(fs.getAddress()); buf = ByteBuffer.allocate(arraySize * 4); FloatBuffer floatbuf = buf.asFloatBuffer(); } else if (type.getName().equals(CAS.TYPE_NAME_BOOLEAN_ARRAY) || type.getName().equals(CAS.TYPE_NAME_BYTE_ARRAY)) { arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())]; buf = ByteBuffer.allocate(arraySize); buf.put(this.getByteHeap().heap, arrayStart, arraySize); return bis; } else if (type.getName().equals(CAS.TYPE_NAME_SHORT_ARRAY)) { arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())]; buf = ByteBuffer.allocate(arraySize * 2); ShortBuffer shortbuf = buf.asShortBuffer();
public boolean getBooleanValue(Feature feat) throws CASRuntimeException { final TypeSystemImpl ts = this.getCASImpl().getTypeSystemImpl(); if (!ts.subsumes(feat.getDomain(), getType())) { throwUndefinedFeatureExc(feat, getType()); } if (!ts.subsumes(feat.getRange(), ts.getType(CAS.TYPE_NAME_BOOLEAN))) { throwIllegalRangeExc(feat, ts.getType(CAS.TYPE_NAME_BOOLEAN)); } final int featCode = ((FeatureImpl) feat).getCode(); return this.getCASImpl().getBooleanValue(this.getAddress(), featCode); }
void registerView(SofaFS aSofa) { this.mySofaRef = ((FeatureStructureImpl) aSofa).getAddress(); }
public boolean isModified(FeatureStructure fs) { if (!isValid || ((FeatureStructureImpl) fs).getCASImpl() != this.cas) { CASRuntimeException e = new CASRuntimeException( CASRuntimeException.CAS_MISMATCH, new String[] { "FS and Marker are not from the same CAS." }); throw e; } int addr = ((FeatureStructureImpl) fs).getAddress(); return isModified(addr); }