285 children.add(tn);
286 result = 0;
287 } else if (sortComparator == null) {
288 // consider inserting it at the end instead?
289 children.add(0, tn);
290 result = 0;
291 } else {
292 result = recursiveIns(0, children.size()-1, tn, tn.getDisplayName(),
293 sortComparator);
294 }
295
296 return new TreeModelEvent(
297 this, getNodePath(), new int[]{result}, new Object[]{tn});
298 }
299 }
300
301 // --------- internal methods ------------
302 private int recursiveIns(final int lPos, final int rPos,
303 final TT_TreeNode tn,
304 final String dispName,
305 final Comparator sortComparator) {
306 synchronized (children) { // should already be locked!
307 int diff = rPos-lPos;
308 int pos = (diff/2) + lPos;
309 String posStr = children.get(pos).getDisplayName();
310 int res = sortComparator.compare(dispName, posStr);
311 if (res == 0) {
312 children.set(pos, tn);
313 if (debug) {
314 Debug.println("Duplicate test, replaced - " + tn.getDisplayName());
315 //Exception e = new Exception(); e.printStackTrace(System.err);
316 }
317 return pos;
318 }
319
320 if (diff <= 0)
321 if (res < 0) {
322 children.add(lPos, tn);
323 return lPos;
324 } else if (res > 0) {
325 children.add(lPos+1, tn);
438 children.add(tn);
439 return 0;
440 }
441 else if (comp == null) {
442 children.add(tn);
443 return children.size()-1;
444 } else {
445 int result = recursiveIns(0, children.size()-1, tn,
446 tn.getDisplayName(), comp);
447 // Iterator<TT_TreeNode> it = children.iterator();
448 // while (it.hasNext())
449 // System.out.println(" " + it.next().getDisplayName());
450
451 return result;
452 }
453 }
454 }
455
456 private final ArrayList<TT_TreeNode> children = new ArrayList<TT_TreeNode>();
457 private TRT_TreeNode tn;
458 private Comparator comp;
459 private final AtomicBoolean isUpdated = new AtomicBoolean(false);
460 private boolean debug = Debug.getBoolean(TT_BasicNode.class);
461 }
|
285 children.add(tn);
286 result = 0;
287 } else if (sortComparator == null) {
288 // consider inserting it at the end instead?
289 children.add(0, tn);
290 result = 0;
291 } else {
292 result = recursiveIns(0, children.size()-1, tn, tn.getDisplayName(),
293 sortComparator);
294 }
295
296 return new TreeModelEvent(
297 this, getNodePath(), new int[]{result}, new Object[]{tn});
298 }
299 }
300
301 // --------- internal methods ------------
302 private int recursiveIns(final int lPos, final int rPos,
303 final TT_TreeNode tn,
304 final String dispName,
305 final Comparator<String> sortComparator) {
306 synchronized (children) { // should already be locked!
307 int diff = rPos-lPos;
308 int pos = (diff/2) + lPos;
309 String posStr = children.get(pos).getDisplayName();
310 int res = sortComparator.compare(dispName, posStr);
311 if (res == 0) {
312 children.set(pos, tn);
313 if (debug) {
314 Debug.println("Duplicate test, replaced - " + tn.getDisplayName());
315 //Exception e = new Exception(); e.printStackTrace(System.err);
316 }
317 return pos;
318 }
319
320 if (diff <= 0)
321 if (res < 0) {
322 children.add(lPos, tn);
323 return lPos;
324 } else if (res > 0) {
325 children.add(lPos+1, tn);
438 children.add(tn);
439 return 0;
440 }
441 else if (comp == null) {
442 children.add(tn);
443 return children.size()-1;
444 } else {
445 int result = recursiveIns(0, children.size()-1, tn,
446 tn.getDisplayName(), comp);
447 // Iterator<TT_TreeNode> it = children.iterator();
448 // while (it.hasNext())
449 // System.out.println(" " + it.next().getDisplayName());
450
451 return result;
452 }
453 }
454 }
455
456 private final ArrayList<TT_TreeNode> children = new ArrayList<TT_TreeNode>();
457 private TRT_TreeNode tn;
458 private Comparator<String> comp;
459 private final AtomicBoolean isUpdated = new AtomicBoolean(false);
460 private boolean debug = Debug.getBoolean(TT_BasicNode.class);
461 }
|