Example #1
0
  private Object interpretFunctionListItem(Object left, Sprite sprite) {
    UserList userList = null;
    if (rightChild.getElementType() == ElementType.USER_LIST) {
      DataContainer dataContainer =
          ProjectManager.getInstance().getSceneToPlay().getDataContainer();
      userList = dataContainer.getUserList(rightChild.getValue(), sprite);
    }

    if (userList == null) {
      return "";
    }

    int index = 0;
    if (left instanceof String) {
      try {
        Double doubleValueOfLeftChild = Double.valueOf((String) left);
        index = doubleValueOfLeftChild.intValue();
      } catch (NumberFormatException numberFormatexception) {
        Log.d(getClass().getSimpleName(), "Couldn't parse String", numberFormatexception);
      }
    } else {
      index = ((Double) left).intValue();
    }

    index--;

    if (index < 0) {
      return "";
    } else if (index >= userList.getList().size()) {
      return "";
    }

    return userList.getList().get(index);
  }
Example #2
0
  private Object interpretFunctionContains(Object right, Sprite sprite) {
    if (leftChild.getElementType() == ElementType.USER_LIST) {
      DataContainer dataContainer =
          ProjectManager.getInstance().getSceneToPlay().getDataContainer();
      UserList userList = dataContainer.getUserList(leftChild.getValue(), sprite);

      if (userList == null) {
        return 0d;
      }

      for (Object userListElement : userList.getList()) {
        if (interpretOperatorEqual(userListElement, right) == 1d) {
          return 1d;
        }
      }
    }

    return 0d;
  }
Example #3
0
  private Object interpretFunctionLength(Object left, Sprite sprite) {
    if (leftChild == null) {
      return 0d;
    }
    if (leftChild.type == ElementType.NUMBER) {
      return (double) leftChild.value.length();
    }
    if (leftChild.type == ElementType.STRING) {
      return (double) leftChild.value.length();
    }
    if (leftChild.type == ElementType.USER_VARIABLE) {
      return (double) handleLengthUserVariableParameter(sprite);
    }
    if (leftChild.type == ElementType.USER_LIST) {
      DataContainer dataContainer =
          ProjectManager.getInstance().getSceneToPlay().getDataContainer();
      UserList userList = dataContainer.getUserList(leftChild.getValue(), sprite);
      if (userList == null) {
        return 0d;
      }
      if (userList.getList().size() == 0) {
        return 0d;
      }

      Object interpretedList = leftChild.interpretRecursive(sprite);
      if (interpretedList instanceof Double) {
        Double interpretedListDoubleValue = (Double) interpretedList;
        if (interpretedListDoubleValue.isNaN() || interpretedListDoubleValue.isInfinite()) {
          return 0d;
        }
        return (double) (String.valueOf(interpretedListDoubleValue.intValue())).length();
      }
      if (interpretedList instanceof String) {
        String interpretedListStringValue = (String) interpretedList;
        return (double) interpretedListStringValue.length();
      }
    }
    if (left instanceof Double && ((Double) left).isNaN()) {
      return 0d;
    }
    return (double) (String.valueOf(left)).length();
  }