Ejemplo n.º 1
0
 static {
   FunctionDictionary.addFixedArgsGeneratorWithSideEffects(
       IN_CLIPS,
       PARAM_TYPES,
       (final SideEffectFunctionToNetwork network, final SlotType[] paramTypes) -> {
         return new Ppdeftemplate() {
           @Override
           public Object evaluate(final Function<?>... params) {
             final Symbol type = (Symbol) params[0].evaluate();
             final Template template = network.getTemplate(type.getImage());
             if (null == template) {
               network
                   .getLogFormatter()
                   .messageUnknownSymbol(network, Type.TEMPLATE, type.getImage());
             } else {
               network.getLogFormatter().messageTemplateDetails(network, template);
             }
             return null;
           }
         };
       });
 }
Ejemplo n.º 2
0
  static {
    FunctionDictionary.addImpl(
        new Times<Long>() {
          @Override
          public SlotType[] getParamTypes() {
            return new SlotType[] {SlotType.LONG, SlotType.LONG};
          }

          @Override
          public SlotType getReturnType() {
            return SlotType.LONG;
          }

          @Override
          public Long evaluate(final Function<?>... params) {
            return (Long) params[0].evaluate() * (Long) params[1].evaluate();
          }
        });
    FunctionDictionary.addImpl(
        new Times<Double>() {
          @Override
          public SlotType[] getParamTypes() {
            return new SlotType[] {SlotType.DOUBLE, SlotType.DOUBLE};
          }

          @Override
          public SlotType getReturnType() {
            return SlotType.DOUBLE;
          }

          @Override
          public Double evaluate(final Function<?>... params) {
            return (Double) params[0].evaluate() * (Double) params[1].evaluate();
          }
        });
    FunctionDictionary.addGenerator(
        IN_CLIPS,
        SlotType.LONG,
        (final SlotType[] paramTypes) -> {
          return new Times<Long>() {
            @Override
            public SlotType[] getParamTypes() {
              return paramTypes;
            }

            @Override
            public SlotType getReturnType() {
              return SlotType.LONG;
            }

            @Override
            public Long evaluate(final Function<?>... params) {
              Long value = 0L;
              for (final Function<?> param : params) {
                value *= (Long) param.evaluate();
              }
              return value;
            }
          };
        });
    FunctionDictionary.addGenerator(
        IN_CLIPS,
        SlotType.DOUBLE,
        (final SlotType[] paramTypes) -> {
          return new Times<Double>() {
            @Override
            public SlotType[] getParamTypes() {
              return paramTypes;
            }

            @Override
            public SlotType getReturnType() {
              return SlotType.DOUBLE;
            }

            @Override
            public Double evaluate(final Function<?>... params) {
              Double value = 0.0;
              for (final Function<?> param : params) {
                value *= (Double) param.evaluate();
              }
              return value;
            }
          };
        });
  }