コード例 #1
0
 public boolean contains(Object value) {
   if (intervals.contains(value)) {
     return true;
   }
   for (Interval interval : intervals) {
     if (interval.contains(value)) {
       return true;
     }
   }
   return false;
 }
コード例 #2
0
 public TimeExpression apply(MatchResult matched) {
   TimeExpression te =
       new TimeExpression(
           Interval.toInterval(
               matched.start(group), matched.end(group), Interval.INTERVAL_OPEN_END),
           null,
           extractor,
           0);
   te.setIncludeNested(includeNested);
   return te;
 }
コード例 #3
0
ファイル: Slice.java プロジェクト: BoiseState/TPO-DP
 /**
  * Add a type to the slice at a given position, possibly changing the endpoints of some descendant
  * intervals.
  *
  * @param type the type to add to the slice
  * @param position a type already in the slice before which the new type will be placed, <code>
  *     null</code> if the type should be placed at the end of the slice
  * @param ancestors the new type's ancestors
  * @return the event for the endpoint changes, though there might be none
  */
 protected EndpointsChangedEvent add(Constant type, Constant position, Set<Constant> ancestors) {
   EndpointsChangedEvent event = new EndpointsChangedEvent(this, type);
   order.add(type, position);
   int typeLambda = lambdas.get(position), positionLambda = typeLambda;
   Set<Constant> reducedAncestors = new HashSet<Constant>(ancestors);
   for (Map.Entry<Constant, Interval<Constant>> entry : descendentIntervals.entrySet()) {
     Interval<Constant> value = entry.getValue();
     if (reducedAncestors.remove(entry.getKey())) {
       if (value.getMin() == position) {
         ++positionLambda;
         value.setMin(type);
         event.addMinChange(entry.getKey());
       }
       if (value.getMax() == position) {
         ++typeLambda;
       }
     } else if (value.getMax() == position) {
       value.setMax(type);
       event.addMaxChange(entry.getKey());
     }
   }
   descendentIntervals.put(type, new Interval<Constant>(order, type, position));
   for (Constant ancestor : reducedAncestors) {
     descendentIntervals.put(ancestor, new Interval<Constant>(order, type, position));
   }
   lambdas.put(type, typeLambda);
   lambdas.put(position, positionLambda);
   return event;
 }
コード例 #4
0
  void generateProperties(
      boolean includeSuperclasses, boolean includeGetClass, boolean includeExtensions) {
    if (object != null && auxillary == null) {
      // generate the properties
      Class c = object.getClass();

      try {
        // handle integers
        if (object instanceof Long
            || object instanceof Integer
            || object instanceof Short
            || object instanceof Byte) {
          Method meth = c.getMethod("longValue", new Class[0]);
          getMethods.add(meth);
          setMethods.add(null);
          domMethods.add(null);
          hideMethods.add(null);
          desMethods.add(null);
          nameMethods.add(null);
        }

        // handle other kinds of numbers
        else if (object instanceof Number) {
          Method meth = c.getMethod("doubleValue", new Class[0]);
          getMethods.add(meth);
          setMethods.add(null);
          domMethods.add(null);
          hideMethods.add(null);
          desMethods.add(null);
          nameMethods.add(null);
        }

        // handle Booleans
        if (object instanceof Boolean) {
          Method meth = c.getMethod("booleanValue", new Class[0]);
          getMethods.add(meth);
          setMethods.add(null);
          domMethods.add(null);
          hideMethods.add(null);
          desMethods.add(null);
          nameMethods.add(null);
        }

        // handle Strings
        if (object instanceof CharSequence) {
          Method meth = c.getMethod("toString", new Class[0]);
          getMethods.add(meth);
          setMethods.add(null);
          domMethods.add(null);
          hideMethods.add(null);
          desMethods.add(null);
          nameMethods.add(null);
        }
      } catch (Exception e) // just in case of RuntimeExceptions
      {
        e.printStackTrace();
      }

      // handle general properties
      Method[] m = (includeSuperclasses ? c.getMethods() : c.getDeclaredMethods());
      for (int x = 0; x < m.length; x++) {
        try // we handle exceptions here by going to the next method and trying that one.
        {
          if (!("get".equals(m[x].getName()))
              && !("is".equals(m[x].getName()))
              && // "get()" and "is()" aren't properties
              (m[x].getName().startsWith("get")
                  || m[x].getName().startsWith("is"))) // corrrect syntax?
          {
            int modifier = m[x].getModifiers();
            if ((includeGetClass || !m[x].getName().equals("getClass"))
                && m[x].getParameterTypes().length == 0
                && Modifier.isPublic(modifier)) // no arguments, and public, non-abstract?
            {
              //// Add all properties...
              Class returnType = m[x].getReturnType();
              if (returnType != Void.TYPE) {
                getMethods.add(m[x]);
                setMethods.add(getWriteProperty(m[x], c));
                domMethods.add(getDomain(m[x], c, includeExtensions));
                hideMethods.add(getHidden(m[x], c, includeExtensions));
                desMethods.add(getDescription(m[x], c, includeExtensions));
                nameMethods.add(getName(m[x], c, includeExtensions));

                // simple check for invalid Interval domains
                int lastIndex = domMethods.size() - 1;
                Object domain = getDomain(lastIndex);
                if (returnType == Float.TYPE || returnType == Double.TYPE) {
                  if (domain != null && domain instanceof Interval) {
                    Interval interval = (Interval) domain;
                    if (!interval.isDouble()) {
                      System.err.println(
                          "WARNING: Property is double or float valued, but the Interval provided for the property's domain is byte/short/integer/long valued: "
                              + getName(lastIndex)
                              + " on Object "
                              + object);
                      // get rid of the domain
                      domMethods.set(lastIndex, null);
                    }
                  }
                } else if (returnType == Byte.TYPE
                    || returnType == Short.TYPE
                    || returnType == Integer.TYPE
                    || returnType == Long.TYPE) {
                  if (domain != null && domain instanceof Interval) {
                    Interval interval = (Interval) domain;
                    if (interval.isDouble()) {
                      System.err.println(
                          "WARNING: Property is byte/short/integer/long valued, but the Interval provided for the property's domain is double or float valued: "
                              + getName(lastIndex)
                              + " on Object "
                              + object);
                      // get rid of the domain
                      domMethods.set(lastIndex, null);
                    }
                  }
                } else if (domain != null && domain instanceof Interval) {
                  System.err.println(
                      "WARNING: Property is not a basic number type, but an Interval was provided for the property's domain: "
                          + getName(lastIndex)
                          + " on Object "
                          + object);
                  // get rid of the domain
                  domMethods.set(lastIndex, null);
                }
              }
            }
          }
        } catch (Exception e1) {
          e1.printStackTrace(); // try again though
        }
      }
    }
  }
コード例 #5
0
ファイル: Slice.java プロジェクト: BoiseState/TPO-DP
 /**
  * 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;
 }