在WEBMETHODS中,元素可以在循环通过DocumentList时从DocumentList中删除吗?如果是,那么如何?如果为No,那么我们如何将DocumentList变量的值设置为null。
谢谢
无
发布于 2012-09-30 15:58:34
Tundra包含一个从文档列表(com.wm.data.IData[])中删除项目的服务:tundra.list.document:drop($list[], $index)。
$list是要删除的项目的文档列表(com.wm.data.IData[]) from$index是要删除的项目的从零开始的数组索引相关的Java代码如下:
public static final void drop(IData pipeline) throws ServiceException {
IDataCursor cursor = pipeline.getCursor();
try {
Object[] list = IDataUtil.getObjectArray(cursor, "$list");
String index = IDataUtil.getString(cursor, "$index");
if (index != null) IDataUtil.put(cursor, "$list", drop(list, index));
} finally {
cursor.destroy();
}
}
// returns a new array which contains all the elements from the given arrays
public static <T> T[] concatenate(T[] array, T[] items) {
if (array == null) return items;
if (items == null) return array;
java.util.List<T> list = new java.util.ArrayList<T>(array.length + items.length);
java.util.Collections.addAll(list, array);
java.util.Collections.addAll(list, items);
return list.toArray(java.util.Arrays.copyOf(array, 0));
}
// removes the element at the given index from the given list
public static <T> T[] drop(T[] array, String index) {
return drop(array, Integer.parseInt(index));
}
// removes the element at the given index from the given list
public static <T> T[] drop(T[] array, int index) {
if (array != null) {
// support reverse/tail indexing
if (index < 0) index += array.length;
if (index < 0 || array.length <= index) throw new ArrayIndexOutOfBoundsException(index);
T[] head = slice(array, 0, index);
T[] tail = slice(array, index + 1, array.length - index);
array = concatenate(head, tail);
}
return array;
}
// returns a new array which is a subset of elements from the given array
public static <T> T[] slice(T[] array, int index, int length) {
if (array == null || array.length == 0) return array;
// support reverse/tail length
if (length < 0) length = array.length + length;
// support reverse/tail indexing
if (index < 0) index += array.length;
// don't slice past the end of the array
if ((length += index) > array.length) length = array.length;
return java.util.Arrays.copyOfRange(array, index, length);
}但是,我同意MrJames的观点:最好也是最简单的方法是创建一个新的文档列表,并且只在循环步骤中使用pub.list:appendToDocumentList (如果使用Tundra,则使用tundra.list.document:append )将您想要的项目附加到新列表中。
https://stackoverflow.com/questions/9811770
复制相似问题