提交 1472ce13 编写于 作者: K Kohsuke Kawaguchi

added a convenience method that replaces just one item in the list

上级 4378e878
......@@ -118,6 +118,21 @@ public class PersistedList<T> implements Iterable<T> {
}
}
/**
* A convenience method to replace a single item.
*
* This method shouldn't be used when you are replacing a lot of stuff
* as copy-on-write semantics make this rather slow.
*/
public void replace(T from, T to) throws IOException {
List<T> copy = new ArrayList<T>(data.getView());
for (int i=0; i<copy.size(); i++) {
if (copy.get(i).equals(from))
copy.set(i,to);
}
data.replaceBy(copy);
}
public boolean remove(T o) throws IOException {
boolean b = data.remove(o);
if (b) onModified();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册