Index: /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskSymbolBucketedMap.java
===================================================================
--- /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskSymbolBucketedMap.java	(revision 2128)
+++ /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskSymbolBucketedMap.java	(revision 2129)
@@ -78,4 +78,84 @@
     /**
      * <p>
+     * the id of the default event bucket
+     * </p>
+     */
+    private static final int DEFAULT_EVENT_BUCKET_ID = 4;
+    
+    /**
+     * <p>
+     * the id of the default sequence bucket
+     * </p>
+     */
+    private static final int DEFAULT_SEQUENCE_BUCKET_ID = 0;
+    
+    /**
+     * <p>
+     * the id of the default selection bucket
+     * </p>
+     */
+    private static final int DEFAULT_SELECTION_BUCKET_ID = 1;
+    
+    /**
+     * <p>
+     * the id of the default iteration bucket
+     * </p>
+     */
+    private static final int DEFAULT_ITERATION_BUCKET_ID = 2;
+    
+    /**
+     * <p>
+     * the id of the default optional bucket
+     * </p>
+     */
+    private static final int DEFAULT_OPTIONAL_BUCKET_ID = 3;
+    
+    /**
+     * <p>
+     * the default bucket search order for events
+     * </p>
+     */
+    private static final int[] DEFAULT_EVENT_BUCKET_SEARCH_ORDER = new int[]
+        { DEFAULT_EVENT_BUCKET_ID, DEFAULT_ITERATION_BUCKET_ID, DEFAULT_OPTIONAL_BUCKET_ID,
+          DEFAULT_SELECTION_BUCKET_ID };
+    
+    /**
+     * <p>
+     * the default bucket search order for sequences
+     * </p>
+     */
+    private static final int[] DEFAULT_SEQUENCE_BUCKET_SEARCH_ORDER = new int[]
+        { DEFAULT_SEQUENCE_BUCKET_ID, DEFAULT_ITERATION_BUCKET_ID, DEFAULT_OPTIONAL_BUCKET_ID,
+          DEFAULT_SELECTION_BUCKET_ID };
+    
+    /**
+     * <p>
+     * the default bucket search order for selection
+     * </p>
+     */
+    private static final int[] DEFAULT_SELECTION_BUCKET_SEARCH_ORDER = new int[]
+        { DEFAULT_SELECTION_BUCKET_ID, DEFAULT_EVENT_BUCKET_ID, DEFAULT_ITERATION_BUCKET_ID,
+          DEFAULT_OPTIONAL_BUCKET_ID, DEFAULT_SEQUENCE_BUCKET_ID };
+    
+    /**
+     * <p>
+     * the default bucket search order for iterations
+     * </p>
+     */
+    private static final int[] DEFAULT_ITERATION_BUCKET_SEARCH_ORDER = new int[]
+        { DEFAULT_ITERATION_BUCKET_ID, DEFAULT_OPTIONAL_BUCKET_ID, DEFAULT_SELECTION_BUCKET_ID,
+          DEFAULT_EVENT_BUCKET_ID, DEFAULT_SEQUENCE_BUCKET_ID };
+    
+    /**
+     * <p>
+     * the default bucket search order for optional
+     * </p>
+     */
+    private static final int[] DEFAULT_OPTIONAL_BUCKET_SEARCH_ORDER = new int[]
+        { DEFAULT_OPTIONAL_BUCKET_ID, DEFAULT_EVENT_BUCKET_ID, DEFAULT_ITERATION_BUCKET_ID,
+          DEFAULT_SELECTION_BUCKET_ID, DEFAULT_SEQUENCE_BUCKET_ID };
+    
+    /**
+     * <p>
      * Comparator to be used for comparing the task instances with each other
      * </p>
@@ -106,4 +186,15 @@
      */
     private int defaultBucket = 0;
+    
+    /**
+     * <p>
+     * the adjustable bucket search order for events. This array is initialized for reuse as
+     * otherwise for any lookup of a bucket search order for an individual event, this array would
+     * be recreated.
+     * </p>
+     */
+    private final int[] ADJUSTABLE_EVENT_SPECIFIC_BUCKET_SEARCH_ORDER = new int[]
+        { 0, 0, DEFAULT_ITERATION_BUCKET_ID, DEFAULT_OPTIONAL_BUCKET_ID, DEFAULT_EVENT_BUCKET_ID,
+          DEFAULT_SELECTION_BUCKET_ID };
     
     /**
@@ -408,26 +499,31 @@
             // selections, and finally the rest.
             
-            if (task.getInstances().iterator().hasNext()) {
-                Event event =
-                    ((IEventTaskInstance) ((IEventTask) task).getInstances().iterator().next()).getEvent();
+            Collection<ITaskInstance> instances = task.getInstances();
+            
+            if (instances.size() > 0) {
+                Event event = ((IEventTaskInstance) instances.iterator().next()).getEvent();
                 
-                return new int[] { event.getTarget().hashCode() + event.getType().getName().hashCode(),
-                                   event.getType().getName().hashCode(), 2, 3, 4, 1 };
+                ADJUSTABLE_EVENT_SPECIFIC_BUCKET_SEARCH_ORDER[0] =
+                    event.getTarget().hashCode() + event.getType().getName().hashCode();
+                ADJUSTABLE_EVENT_SPECIFIC_BUCKET_SEARCH_ORDER[1] =
+                    event.getType().getName().hashCode();
+                
+                return ADJUSTABLE_EVENT_SPECIFIC_BUCKET_SEARCH_ORDER;
             }
             else {
-                return new int[] { 4, 2, 3, 1 };
+                return DEFAULT_EVENT_BUCKET_SEARCH_ORDER;
             }
         }
         else if (task instanceof ISequence) {
-            return new int[] { 0, 2, 3, 1 };                       
+            return DEFAULT_SEQUENCE_BUCKET_SEARCH_ORDER;
         }
         else if (task instanceof ISelection) {
-            return new int[] { 1, 4, 2, 3 };                       
+            return DEFAULT_SELECTION_BUCKET_SEARCH_ORDER;
         }
         else if (task instanceof IIteration) {
-            return new int[] { 2, 1, 4 };                       
+            return DEFAULT_ITERATION_BUCKET_SEARCH_ORDER;
         }
         else if (task instanceof IOptional) {
-            return new int[] { 3, 4, 2, 1, 0 };                       
+            return DEFAULT_OPTIONAL_BUCKET_SEARCH_ORDER;
         }
         
@@ -509,9 +605,15 @@
             }
             
-            // try to search the other buckets
+            // try to search the other buckets (may be required, if bucket separation given by
+            // bucket ids is different from logical bucket separation of comparator
             if (entry == null) {
-                Arrays.sort(bucketSearchOrder);
+                // create a copy of the search order to be able to sort and afterwards binary
+                // search it. The original version MUST NOT BE SORTED.
+                int[] bucketSearchOrderCopy =
+                    Arrays.copyOf(bucketSearchOrder, bucketSearchOrder.length);
+                
+                Arrays.sort(bucketSearchOrderCopy);
                 for (Map.Entry<Integer, List<Map.Entry<ITask, V>>> bucket : symbolBuckets.entrySet()) {
-                    if (Arrays.binarySearch(bucketSearchOrder, bucket.getKey()) < 0) {
+                    if (Arrays.binarySearch(bucketSearchOrderCopy, bucket.getKey()) < 0) {
                         List<Map.Entry<ITask, V>> list = bucket.getValue();
                         if (list != null) {
