Beispiel #1
1
 public int compare(XMLGregorianCalendar xmlGregorianCalendar) {
   return calendar.compare(xmlGregorianCalendar);
 }
Beispiel #2
0
  /**
   * Validate that the current time falls between the two boundaries
   *
   * @param now
   * @param notbefore
   * @param notOnOrAfter
   * @return
   */
  public static boolean isValid(
      XMLGregorianCalendar now, XMLGregorianCalendar notbefore, XMLGregorianCalendar notOnOrAfter) {
    if (notbefore == null) throw logger.nullArgumentError("notbefore argument is null");
    if (notOnOrAfter == null) throw logger.nullArgumentError("notOnOrAfter argument is null");

    int val = notbefore.compare(now);

    if (val == DatatypeConstants.INDETERMINATE || val == DatatypeConstants.GREATER) return false;

    val = notOnOrAfter.compare(now);
    if (val != DatatypeConstants.GREATER) return false;
    return true;
  }
 /* (non-Javadoc)
  * @see java.lang.Comparable#compareTo(java.lang.Object)
  */
 public int compareTo(Object o) {
   final AtomicValue other = (AtomicValue) o;
   if (Type.subTypeOf(other.getType(), Type.DATE_TIME))
     try {
       // TODO : find something that will consume less resources
       return calendar.compare(
           TimeUtils.getInstance().newXMLGregorianCalendar(other.getStringValue()));
     } catch (XPathException e) {
       System.out.println("Failed to get string value of '" + other + "'");
       // Why not ?
       return Constants.SUPERIOR;
     }
   else return getType() > other.getType() ? Constants.SUPERIOR : Constants.INFERIOR;
 }
 protected XMLGregorianCalendar validateTerminationTime(String value)
     throws UnacceptableTerminationTimeFault {
   XMLGregorianCalendar tt = parseTerminationTime(value);
   if (tt == null) {
     UnacceptableTerminationTimeFaultType fault = new UnacceptableTerminationTimeFaultType();
     throw new UnacceptableTerminationTimeFault(
         "Unable to parse termination time: '" + value + "'", fault);
   }
   XMLGregorianCalendar ct = getCurrentTime();
   int c = tt.compare(ct);
   if (c == DatatypeConstants.LESSER || c == DatatypeConstants.EQUAL) {
     UnacceptableTerminationTimeFaultType fault = new UnacceptableTerminationTimeFaultType();
     fault.setMinimumTime(ct);
     throw new UnacceptableTerminationTimeFault("Invalid termination time", fault);
   }
   return tt;
 }
  /** Copied from org.openrdf.query.QueryResultUtil */
  private static boolean bindingSetsMatch(final BindingSet bs1, final BindingSet bs2) {

    if (bs1.size() != bs2.size()) {
      return false;
    }

    for (Binding binding1 : bs1) {
      Value value1 = binding1.getValue();
      Value value2 = bs2.getValue(binding1.getName());

      if ((value1 instanceof BNode) && (value2 instanceof BNode)) {
        // BNode mappedBNode = bNodeMapping.get(value1);
        //
        // if (mappedBNode != null) {
        // // bNode 'value1' was already mapped to some other bNode
        // if (!value2.equals(mappedBNode)) {
        // // 'value1' and 'value2' do not match
        // return false;
        // }
        // } else {
        // // 'value1' was not yet mapped, we need to check if 'value2'
        // // is a
        // // possible mapping candidate
        // if (bNodeMapping.containsValue(value2)) {
        // // 'value2' is already mapped to some other value.
        // return false;
        // }
        // }

        return value1.equals(value2);
      } else {
        // values are not (both) bNodes
        if ((value1 instanceof Literal) && (value2 instanceof Literal)) {
          // do literal value-based comparison for supported datatypes
          Literal leftLit = (Literal) value1;
          Literal rightLit = (Literal) value2;

          URI dt1 = leftLit.getDatatype();
          URI dt2 = rightLit.getDatatype();

          if ((dt1 != null)
              && (dt2 != null)
              && dt1.equals(dt2)
              && XMLDatatypeUtil.isValidValue(leftLit.getLabel(), dt1)
              && XMLDatatypeUtil.isValidValue(rightLit.getLabel(), dt2)) {
            Integer compareResult = null;
            if (dt1.equals(XMLSchema.DOUBLE)) {
              compareResult = Double.compare(leftLit.doubleValue(), rightLit.doubleValue());
            } else if (dt1.equals(XMLSchema.FLOAT)) {
              compareResult = Float.compare(leftLit.floatValue(), rightLit.floatValue());
            } else if (dt1.equals(XMLSchema.DECIMAL)) {
              compareResult = leftLit.decimalValue().compareTo(rightLit.decimalValue());
            } else if (XMLDatatypeUtil.isIntegerDatatype(dt1)) {
              compareResult = leftLit.integerValue().compareTo(rightLit.integerValue());
            } else if (dt1.equals(XMLSchema.BOOLEAN)) {
              Boolean leftBool = Boolean.valueOf(leftLit.booleanValue());
              Boolean rightBool = Boolean.valueOf(rightLit.booleanValue());
              compareResult = leftBool.compareTo(rightBool);
            } else if (XMLDatatypeUtil.isCalendarDatatype(dt1)) {
              XMLGregorianCalendar left = leftLit.calendarValue();
              XMLGregorianCalendar right = rightLit.calendarValue();

              compareResult = left.compare(right);
            }

            if (compareResult != null) {
              if (compareResult.intValue() != 0) {
                return false;
              }
            } else if (!value1.equals(value2)) {
              return false;
            }
          } else if (!value1.equals(value2)) {
            return false;
          }
        } else if (!value1.equals(value2)) {
          return false;
        }
      }
    }

    return true;
  }