Package lupos.rif.model

Examples of lupos.rif.model.RuleList


  @Builtin(Name = "index-of")
  public static RuleList index_of(final Argument arg) {
    if (arg.arguments.size() == 2
        && arg.arguments.get(0) instanceof RuleList
        && arg.arguments.get(1) instanceof Item) {
      final RuleList list = (RuleList) arg.arguments.get(0);
      final Item item = arg.arguments.get(1);
      IExpression lookingFor = null;
      if (item instanceof Variable)
        lookingFor = new RuleVariable(item.getName());
      else if (item instanceof Literal)
        lookingFor = new Constant((Literal) item, list);
      else if (item instanceof IExpression)
        lookingFor = (IExpression) item;
      final RuleList results = new RuleList();
      for (int i = 0; i < list.getItems().size(); i++) {
        if (list.getItems().get(i).equals(lookingFor))
          results.addItem(new Constant(BuiltinHelper
              .createXSLiteral(i, "integer"), results));
      }
      return results;
    }
    return null;
View Full Code Here


  @Builtin(Name = "union")
  public static RuleList union(final Argument arg) {
    if (arg.arguments.size() > 0
        && arg.arguments.get(0) instanceof RuleList) {
      final RuleList list = (RuleList) arg.arguments.get(0);
      final List<IExpression> newList = Lists.newArrayList();
      for (final IExpression expr : list.getItems())
        if (!newList.contains(expr))
          newList.add(expr);
      list.getItems().clear();
      list.getItems().addAll(newList);
      boolean first = true;
      for (final Item item : arg.arguments) {
        if (first) {
          first = false;
          continue;
        }
        for (final IExpression expr : ((RuleList) item).getItems())
          if (!list.getItems().contains(expr))
            list.addItem(expr);
      }
      return list;
    }
    return null;
  }
View Full Code Here

  @Builtin(Name = "distinct-values")
  public static RuleList distinct_values(final Argument arg) {
    if (arg.arguments.size() == 1
        && arg.arguments.get(0) instanceof RuleList) {
      final RuleList list = (RuleList) arg.arguments.get(0);
      final List<IExpression> newList = Lists.newArrayList();
      for (final IExpression expr : list.getItems())
        if (!newList.contains(expr))
          newList.add(expr);
      list.getItems().clear();
      list.getItems().addAll(newList);
      return list;
    }
    return null;
  }
View Full Code Here

  @Builtin(Name = "intersect")
  public static RuleList intersect(final Argument arg) {
    if (arg.arguments.size() > 0
        && arg.arguments.get(0) instanceof RuleList) {
      final RuleList list = (RuleList) arg.arguments.get(0);
      final List<IExpression> newList = Lists.newArrayList();
      for (final Item item : arg.arguments) {
        for (final IExpression expr : ((RuleList) item).getItems()) {
          boolean contained = true;
          for (final Item item1 : arg.arguments)
            if (!((RuleList) item1).getItems().contains(expr)) {
              contained = false;
              break;
            }
          if (contained && !newList.contains(expr))
            newList.add(expr);
        }
      }
      list.getItems().clear();
      list.getItems().addAll(newList);
      return list;
    }
    return null;
  }
View Full Code Here

  @Builtin(Name = "except")
  public static RuleList except(final Argument arg) {
    if (arg.arguments.size() == 2
        && arg.arguments.get(0) instanceof RuleList
        && arg.arguments.get(1) instanceof RuleList) {
      final RuleList list = (RuleList) arg.arguments.get(0);
      final RuleList listE = (RuleList) arg.arguments.get(1);
      for (final IExpression expr : listE.getItems())
        list.getItems().remove(expr);
      return list;
    }
    return null;
  }
View Full Code Here

  @Builtin(Name = "list-contains", Bindable = true)
  public static Object list_contains(final Argument arg) {
    if (arg.arguments.size() == 2) {

      if(arg.arguments.get(0) instanceof RuleList) {
      final RuleList list1 = (RuleList) arg.arguments.get(0);

      if(arg.arguments.get(1) instanceof RuleList){
        final RuleList list2 = (RuleList) arg.arguments.get(1);
        for (final IExpression expr : list1.getItems()) {
          if (expr.equals(list2)) {
            return BooleanLiteral.TRUE;
          }
        }
View Full Code Here

TOP

Related Classes of lupos.rif.model.RuleList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.