Exemplo n.º 1
0
  /*
   * (non-Javadoc)
   *
   * @see org.protempa.proposition.Proposition#isEqual(java.lang.Object)
   */
  @Override
  public boolean isEqual(Object o) {
    if (o == this) {
      return true;
    }
    if (!(o instanceof AbstractParameter)) {
      return false;
    }

    AbstractParameter a = (AbstractParameter) o;
    Granularity startGranularity = getInterval().getStartGranularity();
    Granularity aStartGranularity = a.getInterval().getStartGranularity();
    Granularity finishGranularity = getInterval().getFinishGranularity();
    Granularity aFinishGranularity = a.getInterval().getFinishGranularity();
    return super.isEqual(a)
        && (startGranularity == aStartGranularity
            || (startGranularity != null && startGranularity.equals(aStartGranularity)))
        && (finishGranularity == aFinishGranularity
            || (finishGranularity != null && finishGranularity.equals(aFinishGranularity)))
        && (this.contextId == a.contextId
            || (this.contextId != null && this.contextId.equals(a.contextId)));
  }
 @Override
 public void evaluate(KnowledgeHelper arg0, WorkingMemory arg1) throws Exception {
   InternalFactHandle a1f = arg0.getTuple().get(0);
   AbstractParameter a1 = (AbstractParameter) arg1.getObject(a1f);
   String a1Id = a1.getId();
   InternalFactHandle a2f = arg0.getTuple().get(1);
   AbstractParameter a2 = (AbstractParameter) arg1.getObject(a2f);
   Sequence<AbstractParameter> s = new Sequence<>(a1Id, 2);
   s.add(a1);
   s.add(a2);
   Segment<AbstractParameter> segment = new Segment<>(s);
   JBossRulesDerivedLocalUniqueIdValuesProvider provider =
       new JBossRulesDerivedLocalUniqueIdValuesProvider(arg1, a1Id);
   UniqueIdFactory factory = new ProviderBasedUniqueIdFactory(provider);
   AbstractParameter result = new AbstractParameter(a1Id, factory.getInstance());
   result.setSourceSystem(SourceSystem.DERIVED);
   result.setInterval(segment.getInterval());
   result.setValue(a1.getValue());
   result.setCreateDate(new Date());
   Logger logger = ProtempaUtil.logger();
   if (logger.isLoggable(Level.FINEST)) {
     logger.log(Level.FINEST, "Created {0} from {1} and {2}", new Object[] {result, a1, a2});
   }
   arg1.retract(a1f);
   arg1.retract(a2f);
   arg1.insert(result);
   // There should not be any forward derivations yet.
   // List<Proposition> a1PropForward =
   // this.derivationsBuilder.propositionRetractedForward(a1);
   List<Proposition> a1PropBackward = this.derivationsBuilder.propositionRetractedBackward(a1);
   // There should not be any forward derivations yet.
   // List<Proposition> a2PropForward =
   // this.derivationsBuilder.propositionRetractedForward(a2);
   List<Proposition> a2PropBackward = this.derivationsBuilder.propositionRetractedBackward(a2);
   for (Proposition prop : a1PropBackward) {
     this.derivationsBuilder.propositionReplaceForward(prop, a1, result);
     this.derivationsBuilder.propositionAssertedBackward(prop, result);
   }
   for (Proposition prop : a2PropBackward) {
     this.derivationsBuilder.propositionReplaceForward(prop, a2, result);
     this.derivationsBuilder.propositionAssertedBackward(prop, result);
   }
   logger.log(Level.FINER, "Asserted derived proposition {0}", result);
 }