Ejemplo n.º 1
0
    private boolean compare(Object source, Object target, InternalWorkingMemory workingMemory) {
      BitSet sourceTraits = null;
      BitSet targetTraits = null;
      if (source instanceof Thing) {
        sourceTraits = ((TraitableBean) ((Thing) source).getCore()).getCurrentTypeCode();
      } else if (source instanceof TraitableBean) {
        sourceTraits = ((TraitableBean) source).getCurrentTypeCode();
      } else {
        TraitableBean tbean = lookForWrapper(source, workingMemory);
        if (tbean != null) {
          sourceTraits = tbean.getCurrentTypeCode();
        }
      }

      if (target instanceof Class) {
        CodedHierarchy x =
            ((ReteooRuleBase) workingMemory.getRuleBase())
                .getConfiguration()
                .getComponentFactory()
                .getTraitRegistry()
                .getHierarchy();
        targetTraits = x.getCode(((Class) target).getName());
      } else if (target instanceof String) {
        CodedHierarchy x =
            ((ReteooRuleBase) workingMemory.getRuleBase())
                .getConfiguration()
                .getComponentFactory()
                .getTraitRegistry()
                .getHierarchy();
        targetTraits = x.getCode(target);
      } else if (target instanceof Thing) {
        targetTraits = ((TraitableBean) ((Thing) target).getCore()).getCurrentTypeCode();
      } else if (target instanceof TraitableBean) {
        targetTraits = ((TraitableBean) target).getCurrentTypeCode();
      } else {
        TraitableBean tbean = lookForWrapper(target, workingMemory);
        if (tbean != null) {
          targetTraits = tbean.getCurrentTypeCode();
        }
      }

      if (sourceTraits == null || targetTraits == null) {
        return getOperator().isNegated();
      }

      return isA(sourceTraits, targetTraits) ^ getOperator().isNegated();
    }
Ejemplo n.º 2
0
 private BitSet getCode(Object value, CodedHierarchy x) {
   if (value instanceof Class) {
     String typeName = ((Class) value).getName();
     return x.getCode(typeName);
   } else if (value instanceof String) {
     return x.getCode(value);
   } else if (value instanceof Collection) {
     BitSet code = null;
     for (Object o : ((Collection) value)) {
       if (code == null) {
         code = (BitSet) getCode(o, x).clone();
       } else {
         code.and(getCode(o, x));
       }
     }
     return code;
   }
   throw new UnsupportedOperationException(" IsA Operator : Unsupported literal " + value);
 }