public int updateFsList(int addr, List<String> stringValues, IntVector fsAddresses) throws SAXException {
int first = addr;
int currLength = this.getLength(this.neFsListType, addr);
boolean foundCycle = false;
IntRedBlackTree visited = new IntRedBlackTree();
int curNode = addr;
int prevNode = 0;
//if (currLength != stringValues.size() ) {
// first = createFsList(stringValues, fsAddresses);
int i=0;
if (currLength < stringValues.size() ) {
while (cas.getHeapValue(curNode) == neFsListType) {
if (!visited.put(curNode, curNode)) {
foundCycle = true;
break;
}
int value = Integer.parseInt(stringValues.get(i++));
cas.setFeatureValue(curNode,fsHeadFeat, value);
fsAddresses.add(curNode);
prevNode = curNode;
curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(fsTailFeat));
}
//add nodes for remaining values
if (i < stringValues.size()) {
int emptyListFs = curNode;
//check that first is estringlisttype
while (i < stringValues.size()) {
int newNode = cas.ll_createFS(neFsListType);
int value = Integer.parseInt((String) stringValues.get(i++));
cas.setFeatureValue(newNode,fsHeadFeat, value);
fsAddresses.add(newNode);
cas.setFeatureValue(newNode, fsTailFeat, emptyListFs);
cas.setFeatureValue(prevNode, fsTailFeat, newNode);
prevNode = newNode;
}
}
} else if (currLength > stringValues.size()) {
while (cas.getHeapValue(curNode) == neFsListType && i < stringValues.size()) {
if (!visited.put(curNode, curNode)) {
foundCycle = true;
break;
}
int value = Integer.parseInt((String) stringValues.get(i++));
fsAddresses.add(curNode);
cas.setFeatureValue(curNode,fsHeadFeat, value);
curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(fsTailFeat));
}
int finalNode = curNode;
//loop till we get a FS that is of type eStringListType
while (cas.getHeapValue(curNode) == neFsListType) {
if (!visited.put(curNode, curNode)) {
foundCycle = true;
break;
//TODO throw exc
}
curNode = cas.getHeapValue(curNode + cas.getFeatureOffset(fsTailFeat));
}
//set the tail feature to eStringListType fs
cas.setFeatureValue(finalNode, fsTailFeat, curNode);
} else {
while (cas.getHeapValue(curNode) == neFsListType) {
if (!visited.put(curNode, curNode)) {
foundCycle = true;
break;
}
int value = Integer.parseInt((String) stringValues.get(i++));
cas.setFeatureValue(curNode,fsHeadFeat, value);