Debian Codegraph @

plugins/org.eclipse.emf.gwt.common/src/org/eclipse/emf/common/notify/impl/NotificationImpl.java

raw
1 /**
2 * Copyright (c) 2002-2010 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v2.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v20.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 */
11 package org.eclipse.emf.common.notify.impl;
12
13
14 import java.util.List;
15
16 import org.eclipse.emf.common.notify.Notification;
17 import org.eclipse.emf.common.notify.NotificationChain;
18 import org.eclipse.emf.common.notify.Notifier;
19 import org.eclipse.emf.common.util.BasicEList;
20
21
22 /**
23 * An extensible notification implementation.
24 */
25 public class NotificationImpl implements Notification, NotificationChain
26 {
27 /**
28 * An {@link #primitiveType indicator} that the feature is not a primitive type.
29 * @see #primitiveType
30 */
31 public static final int PRIMITIVE_TYPE_OBJECT = -1;
32
33 /**
34 * An {@link #primitiveType indicator} that the feature is a <code>boolean</code>.
35 * @see #primitiveType
36 */
37 public static final int PRIMITIVE_TYPE_BOOLEAN = 0;
38
39 /**
40 * An {@link #primitiveType indicator} that the feature is a <code>byte</code>.
41 * @see #primitiveType
42 */
43 public static final int PRIMITIVE_TYPE_BYTE = 1;
44
45 /**
46 * An {@link #primitiveType indicator} that the feature is a <code>char</code>.
47 * @see #primitiveType
48 */
49 public static final int PRIMITIVE_TYPE_CHAR = 2;
50
51 /**
52 * An {@link #primitiveType indicator} that the feature is a <code>double</code>.
53 * @see #primitiveType
54 */
55 public static final int PRIMITIVE_TYPE_DOUBLE = 3;
56
57 /**
58 * An {@link #primitiveType indicator} that the feature is a <code>float</code>.
59 * @see #primitiveType
60 */
61 public static final int PRIMITIVE_TYPE_FLOAT = 4;
62
63 /**
64 * An {@link #primitiveType indicator} that the feature is a <code>int</code>.
65 * @see #primitiveType
66 */
67 public static final int PRIMITIVE_TYPE_INT = 5;
68
69 /**
70 * An {@link #primitiveType indicator} that the feature is a <code>long</code>.
71 * @see #primitiveType
72 */
73 public static final int PRIMITIVE_TYPE_LONG = 6;
74
75 /**
76 * An {@link #primitiveType indicator} that the feature is a <code>short</code>.
77 * @see #primitiveType
78 */
79 public static final int PRIMITIVE_TYPE_SHORT = 7;
80
81 /**
82 * A {@link #position position} value which indicates that {@link #isTouch} should return <code>false</code>.
83 * @see #primitiveType
84 */
85 protected static final int IS_SET_CHANGE_INDEX = NO_INDEX - 1;
86
87 /**
88 * The type of the feature.
89 * @see #PRIMITIVE_TYPE_OBJECT
90 * @see #PRIMITIVE_TYPE_BOOLEAN
91 * @see #PRIMITIVE_TYPE_BYTE
92 * @see #PRIMITIVE_TYPE_CHAR
93 * @see #PRIMITIVE_TYPE_DOUBLE
94 * @see #PRIMITIVE_TYPE_FLOAT
95 * @see #PRIMITIVE_TYPE_INT
96 * @see #PRIMITIVE_TYPE_LONG
97 * @see #PRIMITIVE_TYPE_SHORT
98 */
99 protected int primitiveType;
100
101 /**
102 * The type of the change.
103 * @see #getEventType()
104 */
105 protected int eventType;
106
107 /**
108 * The old value for the case of {@link #PRIMITIVE_TYPE_OBJECT}.
109 * @see #getOldValue()
110 */
111 protected Object oldValue;
112
113 /**
114 * The new value for the case of {@link #PRIMITIVE_TYPE_OBJECT}.
115 * @see #getNewValue()
116 */
117 protected Object newValue;
118
119 /**
120 * The old value for the case of
121 * {@link #PRIMITIVE_TYPE_BOOLEAN},
122 * {@link #PRIMITIVE_TYPE_BYTE},
123 * {@link #PRIMITIVE_TYPE_CHAR},
124 * {@link #PRIMITIVE_TYPE_INT},
125 * {@link #PRIMITIVE_TYPE_LONG},
126 * and {@link #PRIMITIVE_TYPE_SHORT}.
127 * @see #getOldValue()
128 * @see #getOldBooleanValue()
129 * @see #getOldByteValue()
130 * @see #getOldCharValue()
131 * @see #getOldIntValue()
132 * @see #getOldLongValue()
133 * @see #getOldShortValue()
134 */
135 protected long oldSimplePrimitiveValue;
136
137 /**
138 * The new value for the case of
139 * {@link #PRIMITIVE_TYPE_BOOLEAN},
140 * {@link #PRIMITIVE_TYPE_BYTE},
141 * {@link #PRIMITIVE_TYPE_CHAR},
142 * {@link #PRIMITIVE_TYPE_INT},
143 * {@link #PRIMITIVE_TYPE_LONG},
144 * and {@link #PRIMITIVE_TYPE_SHORT}.
145 * @see #getNewValue()
146 * @see #getNewBooleanValue()
147 * @see #getNewByteValue()
148 * @see #getNewCharValue()
149 * @see #getNewIntValue()
150 * @see #getNewLongValue()
151 * @see #getNewShortValue()
152 */
153 protected long newSimplePrimitiveValue;
154
155 /**
156 * The old value for the case of
157 * {@link #PRIMITIVE_TYPE_DOUBLE},
158 * and {@link #PRIMITIVE_TYPE_FLOAT}.
159 * @see #getOldValue()
160 * @see #getOldDoubleValue()
161 * @see #getOldFloatValue()
162 */
163 protected double oldIEEEPrimitiveValue;
164
165 /**
166 * The old value for the case of
167 * {@link #PRIMITIVE_TYPE_DOUBLE},
168 * and {@link #PRIMITIVE_TYPE_FLOAT}.
169 * @see #getOldValue()
170 * @see #getOldDoubleValue()
171 * @see #getOldFloatValue()
172 */
173 protected double newIEEEPrimitiveValue;
174
175 /**
176 * The position.
177 * @see #getPosition()
178 */
179 protected int position;
180
181 /**
182 * The internal chain.
183 */
184 protected NotificationChain next;
185
186 /**
187 * Creates an instance.
188 * @param eventType the type of the change.
189 * @param oldValue the old value before the change.
190 * @param newValue the new value after the change.
191 */
192 public NotificationImpl(int eventType, Object oldValue, Object newValue)
193 {
194 this(eventType, oldValue, newValue, NO_INDEX);
195 }
196
197 /**
198 * Creates an instance.
199 * @param eventType the type of the change.
200 * @param oldValue the old value before the change.
201 * @param newValue the new value after the change.
202 * @param isSetChange the indication of whether the state has changed.
203 */
204 public NotificationImpl(int eventType, Object oldValue, Object newValue, boolean isSetChange)
205 {
206 this(eventType, oldValue, newValue, isSetChange ? IS_SET_CHANGE_INDEX : NO_INDEX);
207 }
208
209 /**
210 * Creates an instance.
211 * @param eventType the type of the change.
212 * @param oldValue the old value before the change.
213 * @param newValue the new value after the change.
214 */
215 public NotificationImpl(int eventType, Object oldValue, Object newValue, int position)
216 {
217 this.eventType = eventType;
218 this.oldValue = oldValue;
219 this.newValue = newValue;
220 this.position = position;
221 this.primitiveType = PRIMITIVE_TYPE_OBJECT;
222 }
223
224 /**
225 * Creates an instance.
226 * @param eventType the type of the change.
227 * @param oldValue the old value before the change.
228 * @param newValue the new value after the change.
229 * @param wasSet whether the feature was set before the change.
230 */
231 public NotificationImpl(int eventType, Object oldValue, Object newValue, int position, boolean wasSet)
232 {
233 this.eventType = eventType;
234 this.oldValue = oldValue;
235 this.newValue = newValue;
236 this.position = position;
237 this.primitiveType = PRIMITIVE_TYPE_OBJECT;
238 if (!wasSet)
239 {
240 this.position = IS_SET_CHANGE_INDEX - position - 1;
241 }
242 }
243
244 /**
245 * Creates an instance.
246 * @param eventType the type of the change.
247 * @param oldBooleanValue the old value before the change.
248 * @param newBooleanValue the new value after the change.
249 * @param isSetChange the indication of whether the state has changed.
250 */
251 public NotificationImpl(int eventType, boolean oldBooleanValue, boolean newBooleanValue, boolean isSetChange)
252 {
253 this(eventType, oldBooleanValue, newBooleanValue);
254 if (isSetChange)
255 {
256 this.position = IS_SET_CHANGE_INDEX;
257 }
258 }
259
260 /**
261 * Creates an instance.
262 * @param eventType the type of the change.
263 * @param oldBooleanValue the old value before the change.
264 * @param newBooleanValue the new value after the change.
265 */
266 public NotificationImpl(int eventType, boolean oldBooleanValue, boolean newBooleanValue)
267 {
268 this.eventType = eventType;
269 this.oldSimplePrimitiveValue = oldBooleanValue ? 1 : 0;
270 this.newSimplePrimitiveValue = newBooleanValue ? 1 : 0;
271 this.position = NO_INDEX;
272 this.primitiveType = PRIMITIVE_TYPE_BOOLEAN;
273 }
274
275 /**
276 * Creates an instance.
277 * @param eventType the type of the change.
278 * @param oldByteValue the old value before the change.
279 * @param newByteValue the new value after the change.
280 * @param isSetChange the indication of whether the state has changed.
281 */
282 public NotificationImpl(int eventType, byte oldByteValue, byte newByteValue, boolean isSetChange)
283 {
284 this(eventType, oldByteValue, newByteValue);
285 if (isSetChange)
286 {
287 this.position = IS_SET_CHANGE_INDEX;
288 }
289 }
290
291 /**
292 * Creates an instance.
293 * @param eventType the type of the change.
294 * @param oldByteValue the old value before the change.
295 * @param newByteValue the new value after the change.
296 */
297 public NotificationImpl(int eventType, byte oldByteValue, byte newByteValue)
298 {
299 this.eventType = eventType;
300 this.oldSimplePrimitiveValue = oldByteValue;
301 this.newSimplePrimitiveValue = newByteValue;
302 this.position = Notification.NO_INDEX;
303 this.primitiveType = PRIMITIVE_TYPE_BYTE;
304 }
305
306 /**
307 * Creates an instance.
308 * @param eventType the type of the change.
309 * @param oldCharValue the old value before the change.
310 * @param newCharValue the new value after the change.
311 * @param isSetChange the indication of whether the state has changed.
312 */
313 public NotificationImpl(int eventType, char oldCharValue, char newCharValue, boolean isSetChange)
314 {
315 this(eventType, oldCharValue, newCharValue);
316 if (isSetChange)
317 {
318 this.position = IS_SET_CHANGE_INDEX;
319 }
320 }
321
322 /**
323 * Creates an instance.
324 * @param eventType the type of the change.
325 * @param oldCharValue the old value before the change.
326 * @param newCharValue the new value after the change.
327 */
328 public NotificationImpl(int eventType, char oldCharValue, char newCharValue)
329 {
330 this.eventType = eventType;
331 this.oldSimplePrimitiveValue = oldCharValue;
332 this.newSimplePrimitiveValue = newCharValue;
333 this.position = Notification.NO_INDEX;
334 this.primitiveType = PRIMITIVE_TYPE_CHAR;
335 }
336
337 /**
338 * Creates an instance.
339 * @param eventType the type of the change.
340 * @param oldDoubleValue the old value before the change.
341 * @param newDoubleValue the new value after the change.
342 * @param isSetChange the indication of whether the state has changed.
343 */
344 public NotificationImpl(int eventType, double oldDoubleValue, double newDoubleValue, boolean isSetChange)
345 {
346 this(eventType, oldDoubleValue, newDoubleValue);
347 if (isSetChange)
348 {
349 this.position = IS_SET_CHANGE_INDEX;
350 }
351 }
352
353 /**
354 * Creates an instance.
355 * @param eventType the type of the change.
356 * @param oldDoubleValue the old value before the change.
357 * @param newDoubleValue the new value after the change.
358 */
359 public NotificationImpl(int eventType, double oldDoubleValue, double newDoubleValue)
360 {
361 this.eventType = eventType;
362 this.oldIEEEPrimitiveValue = oldDoubleValue;
363 this.newIEEEPrimitiveValue = newDoubleValue;
364 this.position = Notification.NO_INDEX;
365 this.primitiveType = PRIMITIVE_TYPE_DOUBLE;
366 }
367
368 /**
369 * Creates an instance.
370 * @param eventType the type of the change.
371 * @param oldFloatValue the old value before the change.
372 * @param newFloatValue the new value after the change.
373 * @param isSetChange the indication of whether the state has changed.
374 */
375 public NotificationImpl(int eventType, float oldFloatValue, float newFloatValue, boolean isSetChange)
376 {
377 this(eventType, oldFloatValue, newFloatValue);
378 if (isSetChange)
379 {
380 this.position = IS_SET_CHANGE_INDEX;
381 }
382 }
383
384 /**
385 * Creates an instance.
386 * @param eventType the type of the change.
387 * @param oldFloatValue the old value before the change.
388 * @param newFloatValue the new value after the change.
389 */
390 public NotificationImpl(int eventType, float oldFloatValue, float newFloatValue)
391 {
392 this.eventType = eventType;
393 this.oldIEEEPrimitiveValue = oldFloatValue;
394 this.newIEEEPrimitiveValue = newFloatValue;
395 this.position = Notification.NO_INDEX;
396 this.primitiveType = PRIMITIVE_TYPE_FLOAT;
397 }
398
399 /**
400 * Creates an instance.
401 * @param eventType the type of the change.
402 * @param oldIntValue the old value before the change.
403 * @param newIntValue the new value after the change.
404 * @param isSetChange the indication of whether the state has changed.
405 */
406 public NotificationImpl(int eventType, int oldIntValue, int newIntValue, boolean isSetChange)
407 {
408 this(eventType, oldIntValue, newIntValue);
409 if (isSetChange)
410 {
411 this.position = IS_SET_CHANGE_INDEX;
412 }
413 }
414
415 /**
416 * Creates an instance.
417 * @param eventType the type of the change.
418 * @param oldIntValue the old value before the change.
419 * @param newIntValue the new value after the change.
420 */
421 public NotificationImpl(int eventType, int oldIntValue, int newIntValue)
422 {
423 this.eventType = eventType;
424 this.oldSimplePrimitiveValue = oldIntValue;
425 this.newSimplePrimitiveValue = newIntValue;
426 this.position = Notification.NO_INDEX;
427 this.primitiveType = PRIMITIVE_TYPE_INT;
428 }
429
430 /**
431 * Creates an instance.
432 * @param eventType the type of the change.
433 * @param oldLongValue the old value before the change.
434 * @param newLongValue the new value after the change.
435 * @param isSetChange the indication of whether the state has changed.
436 */
437 public NotificationImpl(int eventType, long oldLongValue, long newLongValue, boolean isSetChange)
438 {
439 this(eventType, oldLongValue, newLongValue);
440 if (isSetChange)
441 {
442 this.position = IS_SET_CHANGE_INDEX;
443 }
444 }
445
446 /**
447 * Creates an instance.
448 * @param eventType the type of the change.
449 * @param oldLongValue the old value before the change.
450 * @param newLongValue the new value after the change.
451 */
452 public NotificationImpl(int eventType, long oldLongValue, long newLongValue)
453 {
454 this.eventType = eventType;
455 this.oldSimplePrimitiveValue = oldLongValue;
456 this.newSimplePrimitiveValue = newLongValue;
457 this.position = Notification.NO_INDEX;
458 this.primitiveType = PRIMITIVE_TYPE_LONG;
459 }
460
461 /**
462 * Creates an instance.
463 * @param eventType the type of the change.
464 * @param oldShortValue the old value before the change.
465 * @param newShortValue the new value after the change.
466 * @param isSetChange the indication of whether the state has changed.
467 */
468 public NotificationImpl(int eventType, short oldShortValue, short newShortValue, boolean isSetChange)
469 {
470 this(eventType, oldShortValue, newShortValue);
471 if (isSetChange)
472 {
473 this.position = IS_SET_CHANGE_INDEX;
474 }
475 }
476
477 /**
478 * Creates an instance.
479 * @param eventType the type of the change.
480 * @param oldShortValue the old value before the change.
481 * @param newShortValue the new value after the change.
482 */
483 public NotificationImpl(int eventType, short oldShortValue, short newShortValue)
484 {
485 this.eventType = eventType;
486 this.oldSimplePrimitiveValue = oldShortValue;
487 this.newSimplePrimitiveValue = newShortValue;
488 this.position = Notification.NO_INDEX;
489 this.primitiveType = PRIMITIVE_TYPE_SHORT;
490 }
491
492 public Object getNotifier()
493 {
494 return null;
495 }
496
497 public int getEventType()
498 {
499 return eventType;
500 }
501
502 public Object getFeature()
503 {
504 return null;
505 }
506
507 public int getFeatureID(Class<?> expectedClass)
508 {
509 return NO_FEATURE_ID;
510 }
511
512 public Object getOldValue()
513 {
514 if (oldValue == null)
515 {
516 switch (primitiveType)
517 {
518 case PRIMITIVE_TYPE_BOOLEAN:
519 oldValue = getOldBooleanValue() ? Boolean.TRUE : Boolean.FALSE;
520 break;
521 case PRIMITIVE_TYPE_BYTE:
522 oldValue = getOldByteValue();
523 break;
524 case PRIMITIVE_TYPE_CHAR:
525 oldValue = getOldCharValue();
526 break;
527 case PRIMITIVE_TYPE_DOUBLE:
528 oldValue = getOldDoubleValue();
529 break;
530 case PRIMITIVE_TYPE_FLOAT:
531 oldValue = getOldFloatValue();
532 break;
533 case PRIMITIVE_TYPE_LONG:
534 oldValue = getOldLongValue();
535 break;
536 case PRIMITIVE_TYPE_INT:
537 oldValue = getOldIntValue();
538 break;
539 case PRIMITIVE_TYPE_SHORT:
540 oldValue = getOldShortValue();
541 break;
542 }
543 }
544 return oldValue;
545 }
546
547 public Object getNewValue()
548 {
549 if (newValue == null)
550 {
551 switch (primitiveType)
552 {
553 case PRIMITIVE_TYPE_BOOLEAN:
554 newValue = getNewBooleanValue() ? Boolean.TRUE : Boolean.FALSE;
555 break;
556 case PRIMITIVE_TYPE_BYTE:
557 newValue = getNewByteValue();
558 break;
559 case PRIMITIVE_TYPE_CHAR:
560 newValue = getNewCharValue();
561 break;
562 case PRIMITIVE_TYPE_DOUBLE:
563 newValue = getNewDoubleValue();
564 break;
565 case PRIMITIVE_TYPE_FLOAT:
566 newValue = getNewFloatValue();
567 break;
568 case PRIMITIVE_TYPE_LONG:
569 newValue = getNewLongValue();
570 break;
571 case PRIMITIVE_TYPE_INT:
572 newValue = getNewIntValue();
573 break;
574 case PRIMITIVE_TYPE_SHORT:
575 newValue = getNewShortValue();
576 break;
577 }
578 }
579 return newValue;
580 }
581
582 public boolean isTouch()
583 {
584 switch (eventType)
585 {
586 case Notification.RESOLVE:
587 case Notification.REMOVING_ADAPTER:
588 {
589 return true;
590 }
591 case Notification.ADD:
592 case Notification.ADD_MANY:
593 case Notification.REMOVE:
594 case Notification.REMOVE_MANY:
595 {
596 return false;
597 }
598 case Notification.MOVE:
599 {
600 return (Integer)getOldValue() == position;
601 }
602 case Notification.SET:
603 case Notification.UNSET:
604 {
605 if (position == IS_SET_CHANGE_INDEX)
606 {
607 return false;
608 }
609 else
610 {
611 switch (primitiveType)
612 {
613 case PRIMITIVE_TYPE_BOOLEAN:
614 case PRIMITIVE_TYPE_BYTE:
615 case PRIMITIVE_TYPE_CHAR:
616 case PRIMITIVE_TYPE_LONG:
617 case PRIMITIVE_TYPE_INT:
618 case PRIMITIVE_TYPE_SHORT:
619 {
620 return oldSimplePrimitiveValue == newSimplePrimitiveValue;
621 }
622 case PRIMITIVE_TYPE_DOUBLE:
623 case PRIMITIVE_TYPE_FLOAT:
624 {
625 return oldIEEEPrimitiveValue == newIEEEPrimitiveValue;
626 }
627 default:
628 {
629 return oldValue == null ? newValue == null : oldValue.equals(newValue);
630 }
631 }
632 }
633 }
634 default:
635 {
636 return false;
637 }
638 }
639 }
640
641 public boolean isReset()
642 {
643 switch (eventType)
644 {
645 case Notification.SET:
646 Object defaultValue = getFeatureDefaultValue();
647 switch (primitiveType)
648 {
649 case PRIMITIVE_TYPE_BOOLEAN:
650 return defaultValue != null && (Boolean)defaultValue == (newSimplePrimitiveValue != 0);
651 case PRIMITIVE_TYPE_BYTE:
652 return defaultValue != null && (Byte)defaultValue == (byte)newSimplePrimitiveValue;
653 case PRIMITIVE_TYPE_CHAR:
654 return defaultValue != null && (Character)defaultValue == (char)newSimplePrimitiveValue;
655 case PRIMITIVE_TYPE_LONG:
656 return defaultValue != null && (Long)defaultValue == newSimplePrimitiveValue;
657 case PRIMITIVE_TYPE_INT:
658 return defaultValue != null && (Integer)defaultValue == (int)newSimplePrimitiveValue;
659 case PRIMITIVE_TYPE_SHORT:
660 return defaultValue != null && (Short)defaultValue == (short)newSimplePrimitiveValue;
661 case PRIMITIVE_TYPE_DOUBLE:
662 return defaultValue != null && (Double)defaultValue == newIEEEPrimitiveValue;
663 case PRIMITIVE_TYPE_FLOAT:
664 return defaultValue != null && (Float)defaultValue == (float)newIEEEPrimitiveValue;
665 default:
666 return defaultValue == null ? newValue == null : defaultValue.equals(newValue);
667 }
668 case Notification.UNSET:
669 return true;
670 default:
671 return false;
672 }
673 }
674
675 public boolean wasSet()
676 {
677 switch (eventType)
678 {
679 case Notification.SET:
680 {
681 if (isFeatureUnsettable())
682 {
683 return position != IS_SET_CHANGE_INDEX;
684 }
685 break;
686 }
687 case Notification.UNSET:
688 {
689 if (isFeatureUnsettable())
690 {
691 return position == IS_SET_CHANGE_INDEX;
692 }
693 break;
694 }
695 case Notification.ADD:
696 case Notification.ADD_MANY:
697 case Notification.REMOVE:
698 case Notification.REMOVE_MANY:
699 case Notification.MOVE:
700 {
701 return position > IS_SET_CHANGE_INDEX;
702 }
703 default:
704 {
705 return false;
706 }
707 }
708
709 Object defaultValue = getFeatureDefaultValue();
710 switch (primitiveType)
711 {
712 case PRIMITIVE_TYPE_BOOLEAN:
713 return defaultValue != null && (Boolean)defaultValue != (oldSimplePrimitiveValue != 0);
714 case PRIMITIVE_TYPE_BYTE:
715 return defaultValue != null && (Byte)defaultValue != (byte)oldSimplePrimitiveValue;
716 case PRIMITIVE_TYPE_CHAR:
717 return defaultValue != null && (Character)defaultValue != (char)oldSimplePrimitiveValue;
718 case PRIMITIVE_TYPE_LONG:
719 return defaultValue != null && (Long)defaultValue != oldSimplePrimitiveValue;
720 case PRIMITIVE_TYPE_INT:
721 return defaultValue != null && (Integer)defaultValue != (int)oldSimplePrimitiveValue;
722 case PRIMITIVE_TYPE_SHORT:
723 return defaultValue != null && (Short)defaultValue != (short)oldSimplePrimitiveValue;
724 case PRIMITIVE_TYPE_DOUBLE:
725 return defaultValue != null && (Double)defaultValue != oldIEEEPrimitiveValue;
726 case PRIMITIVE_TYPE_FLOAT:
727 return defaultValue != null && (Float)defaultValue != (float)oldIEEEPrimitiveValue;
728 default:
729 return defaultValue == null ? oldValue != null : !defaultValue.equals(oldValue);
730 }
731 }
732
733 protected boolean isFeatureUnsettable()
734 {
735 return false;
736 }
737
738 protected Object getFeatureDefaultValue()
739 {
740 return null;
741 }
742
743 public int getPosition()
744 {
745 return position < 0 ? position < IS_SET_CHANGE_INDEX ? IS_SET_CHANGE_INDEX - position - 1 : NO_INDEX : position;
746 }
747
748 public boolean merge(Notification notification)
749 {
750 switch (eventType)
751 {
752 case Notification.SET:
753 case Notification.UNSET:
754 {
755 int notificationEventType = notification.getEventType();
756 switch (notificationEventType)
757 {
758 case Notification.SET:
759 case Notification.UNSET:
760 {
761 Object notificationNotifier = notification.getNotifier();
762 if (notificationNotifier == getNotifier() && getFeatureID(null) == notification.getFeatureID(null))
763 {
764 newValue = notification.getNewValue();
765 if (notification.getEventType() == Notification.SET)
766 {
767 eventType = Notification.SET;
768 }
769 return true;
770 }
771 }
772 }
773 }
774 case Notification.REMOVE:
775 {
776 int notificationEventType = notification.getEventType();
777 switch (notificationEventType)
778 {
779 case Notification.REMOVE:
780 {
781 Object notificationNotifier = notification.getNotifier();
782 if (notificationNotifier == getNotifier() && getFeatureID(null) == notification.getFeatureID(null))
783 {
784 boolean originalWasSet = wasSet();
785 int originalPosition = getPosition();
786 int notificationPosition = notification.getPosition();
787
788 eventType = Notification.REMOVE_MANY;
789 BasicEList<Object> removedValues = new BasicEList<Object>(2);
790 if (originalPosition <= notificationPosition)
791 {
792 removedValues.add(oldValue);
793 removedValues.add(notification.getOldValue());
794 newValue = new int [] { position = originalPosition, notificationPosition + 1 };
795 }
796 else
797 {
798 removedValues.add(notification.getOldValue());
799 removedValues.add(oldValue);
800 newValue = new int [] { position = notificationPosition, originalPosition };
801 }
802 oldValue = removedValues;
803
804 if (!originalWasSet)
805 {
806 position = IS_SET_CHANGE_INDEX - position - 1;
807 }
808
809 return true;
810 }
811 break;
812 }
813 }
814 break;
815 }
816 case Notification.REMOVE_MANY:
817 {
818 int notificationEventType = notification.getEventType();
819 switch (notificationEventType)
820 {
821 case Notification.REMOVE:
822 {
823 Object notificationNotifier = notification.getNotifier();
824 if (notificationNotifier == getNotifier() && getFeatureID(null) == notification.getFeatureID(null))
825 {
826 boolean originalWasSet = wasSet();
827 int notificationPosition = notification.getPosition();
828
829 int [] positions = (int [])newValue;
830 int [] newPositions = new int [positions.length + 1];
831
832 int index = 0;
833 while (index < positions.length)
834 {
835 int oldPosition = positions[index];
836 if (oldPosition <= notificationPosition)
837 {
838 newPositions[index++] = oldPosition;
839 ++notificationPosition;
840 }
841 else
842 {
843 break;
844 }
845 }
846
847 @SuppressWarnings("unchecked") List<Object> list = (List<Object>)oldValue;
848 list.add(index, notification.getOldValue());
849 newPositions[index] = notificationPosition;
850
851 while (++index < newPositions.length)
852 {
853 newPositions[index] = positions[index - 1];
854 }
855
856 newValue = newPositions;
857
858 if (!originalWasSet)
859 {
860 position = IS_SET_CHANGE_INDEX - newPositions[0];
861 }
862
863 return true;
864 }
865 break;
866 }
867 }
868 break;
869 }
870 }
871
872 return false;
873 }
874
875 public boolean getOldBooleanValue()
876 {
877 if (primitiveType != PRIMITIVE_TYPE_BOOLEAN) throw new IllegalStateException();
878 return oldSimplePrimitiveValue != 0;
879 }
880
881 public boolean getNewBooleanValue()
882 {
883 if (primitiveType != PRIMITIVE_TYPE_BOOLEAN) throw new IllegalStateException();
884 return newSimplePrimitiveValue != 0;
885 }
886
887 public byte getOldByteValue()
888 {
889 if (primitiveType != PRIMITIVE_TYPE_BYTE) throw new IllegalStateException();
890 return (byte)oldSimplePrimitiveValue;
891 }
892
893 public byte getNewByteValue()
894 {
895 if (primitiveType != PRIMITIVE_TYPE_BYTE) throw new IllegalStateException();
896 return (byte)newSimplePrimitiveValue;
897 }
898
899 public char getOldCharValue()
900 {
901 if (primitiveType != PRIMITIVE_TYPE_CHAR) throw new IllegalStateException();
902 return (char)oldSimplePrimitiveValue;
903 }
904
905 public char getNewCharValue()
906 {
907 if (primitiveType != PRIMITIVE_TYPE_CHAR) throw new IllegalStateException();
908 return (char)newSimplePrimitiveValue;
909 }
910
911 public double getOldDoubleValue()
912 {
913 if (primitiveType != PRIMITIVE_TYPE_DOUBLE) throw new IllegalStateException();
914 return oldIEEEPrimitiveValue;
915 }
916
917 public double getNewDoubleValue()
918 {
919 if (primitiveType != PRIMITIVE_TYPE_DOUBLE) throw new IllegalStateException();
920 return newIEEEPrimitiveValue;
921 }
922
923 public float getOldFloatValue()
924 {
925 if (primitiveType != PRIMITIVE_TYPE_FLOAT) throw new IllegalStateException();
926 return (float)oldIEEEPrimitiveValue;
927 }
928
929 public float getNewFloatValue()
930 {
931 if (primitiveType != PRIMITIVE_TYPE_FLOAT) throw new IllegalStateException();
932 return (float)newIEEEPrimitiveValue;
933 }
934
935 public int getOldIntValue()
936 {
937 if (primitiveType != PRIMITIVE_TYPE_INT) throw new IllegalStateException();
938 return (int)oldSimplePrimitiveValue;
939 }
940
941 public int getNewIntValue()
942 {
943 if (primitiveType != PRIMITIVE_TYPE_INT) throw new IllegalStateException();
944 return (int)newSimplePrimitiveValue;
945 }
946
947 public long getOldLongValue()
948 {
949 if (primitiveType != PRIMITIVE_TYPE_LONG) throw new IllegalStateException();
950 return oldSimplePrimitiveValue;
951 }
952
953 public long getNewLongValue()
954 {
955 if (primitiveType != PRIMITIVE_TYPE_LONG) throw new IllegalStateException();
956 return newSimplePrimitiveValue;
957 }
958
959 public short getOldShortValue()
960 {
961 if (primitiveType != PRIMITIVE_TYPE_SHORT) throw new IllegalStateException();
962 return (short)oldSimplePrimitiveValue;
963 }
964
965 public short getNewShortValue()
966 {
967 if (primitiveType != PRIMITIVE_TYPE_SHORT) throw new IllegalStateException();
968 return (short)newSimplePrimitiveValue;
969 }
970
971 public String getOldStringValue()
972 {
973 return oldValue == null ? null : oldValue.toString();
974 }
975
976 public String getNewStringValue()
977 {
978 return newValue == null ? null : newValue.toString();
979 }
980
981 /**
982 * Adds or merges a new notification.
983 * @param newNotification a notification.
984 * @return <code>true</code> when the notification is added and <code>false</code> when it is merged.
985 */
986 public boolean add(Notification newNotification)
987 {
988 if (newNotification == null)
989 {
990 return false;
991 }
992 else
993 {
994 if (merge(newNotification))
995 {
996 return false;
997 }
998
999 if (next == null)
1000 {
1001 if (newNotification instanceof NotificationImpl)
1002 {
1003 next = (NotificationImpl)newNotification;
1004 return true;
1005 }
1006 else
1007 {
1008 next = new NotificationChainImpl();
1009 return next.add(newNotification);
1010 }
1011 }
1012 else
1013 {
1014 return next.add(newNotification);
1015 }
1016 }
1017 }
1018
1019 /*
1020 * Javadoc copied from interface.
1021 */
1022 public void dispatch()
1023 {
1024 Object notifier = getNotifier();
1025 if (notifier != null && getEventType() != -1)
1026 {
1027 ((Notifier)notifier).eNotify(this);
1028 }
1029
1030 if (next != null)
1031 {
1032 next.dispatch();
1033 }
1034 }
1035
1036 @Override
1037 public String toString()
1038 {
1039 StringBuffer result = new StringBuffer(super.toString());
1040 result.append(" (eventType: ");
1041 switch (eventType)
1042 {
1043 case Notification.SET:
1044 {
1045 result.append("SET");
1046 break;
1047 }
1048 case Notification.UNSET:
1049 {
1050 result.append("UNSET");
1051 break;
1052 }
1053 case Notification.ADD:
1054 {
1055 result.append("ADD");
1056 break;
1057 }
1058 case Notification.ADD_MANY:
1059 {
1060 result.append("ADD_MANY");
1061 break;
1062 }
1063 case Notification.REMOVE:
1064 {
1065 result.append("REMOVE");
1066 break;
1067 }
1068 case Notification.REMOVE_MANY:
1069 {
1070 result.append("REMOVE_MANY");
1071 break;
1072 }
1073 case Notification.MOVE:
1074 {
1075 result.append("MOVE");
1076 break;
1077 }
1078 case Notification.REMOVING_ADAPTER:
1079 {
1080 result.append("REMOVING_ADAPTER");
1081 break;
1082 }
1083 case Notification.RESOLVE:
1084 {
1085 result.append("RESOLVE");
1086 break;
1087 }
1088 default:
1089 {
1090 result.append(eventType);
1091 break;
1092 }
1093 }
1094 if (isTouch())
1095 {
1096 result.append(", touch: true");
1097 }
1098 result.append(", position: ");
1099 result.append(getPosition());
1100 result.append(", notifier: ");
1101 result.append(getNotifier());
1102 result.append(", feature: ");
1103 result.append(getFeature());
1104 result.append(", oldValue: ");
1105 result.append(getOldValue());
1106 result.append(", newValue: ");
1107 if (eventType == Notification.REMOVE_MANY && newValue instanceof int [])
1108 {
1109 int [] positions = (int [])newValue;
1110 result.append("[");
1111 for (int i = 0; i < positions.length; )
1112 {
1113 result.append(positions[i]);
1114 if (++i < positions.length)
1115 {
1116 result.append(", ");
1117 }
1118 }
1119 result.append("]");
1120 }
1121 else
1122 {
1123 result.append(getNewValue());
1124 }
1125
1126 result.append(", isTouch: ");
1127 result.append(isTouch());
1128 result.append(", wasSet: ");
1129 result.append(wasSet());
1130 result.append(")");
1131
1132 return result.toString();
1133 }
1134 }