示例#1
0
 /**
  * Attempt to add a type to the slice, possibly changing the endpoints of some descendant
  * intervals.
  *
  * @param type the type to add to the slice
  * @param ancestors the new type's ancestors
  * @return if the addition was successful, the event for the endpoint changes, though there might
  *     be none; if the addition failed, <code>null</code>
  */
 public EndpointsChangedEvent add(Constant type, Set<Constant> ancestors) {
   Interval<Constant> common = asInterval();
   for (Constant ancestor : ancestors) {
     Interval<Constant> mask = descendentIntervals.get(ancestor);
     if (mask != null) {
       common.intersect(mask);
     }
   }
   // empty is okay, as long as we still have location
   if (order.compare(common.getMin(), common.getMax()) > 0) {
     return null;
   }
   int surroundMin = 0, surroundMax = 0;
   for (Constant ancestor : ancestors) {
     Interval<Constant> range = descendentIntervals.get(ancestor);
     if (range != null) {
       if (order.compare(range.getMin(), common.getMin()) < 0
           && order.compare(range.getMax(), common.getMin()) > 0) {
         ++surroundMin;
       }
       if (order.compare(range.getMin(), common.getMax()) < 0
           && order.compare(range.getMax(), common.getMax()) > 0) {
         ++surroundMax;
       }
     }
   }
   if (lambdas.get(common.getMin()) == surroundMin) {
     return add(type, common.getMin(), ancestors);
   }
   if (lambdas.get(common.getMax()) == surroundMax) {
     return add(type, common.getMax(), ancestors);
   }
   //// fast slicing: don't check between min and max
   return null;
 }