Example #1
0
File: List.java Project: pybee/voc
  @org.python.Method(__doc__ = "")
  public org.python.Object __ge__(org.python.Object other) {
    if (other instanceof org.python.types.List) {
      org.python.types.List otherList = (org.python.types.List) other;
      int size = this.value.size();
      int otherSize = otherList.value.size();
      int count = Math.min(size, otherSize);

      for (int i = 0; i < count; i++) {
        org.python.types.Bool b =
            (org.python.types.Bool) this.value.get(i).__ge__(otherList.value.get(i));

        if (!b.value) {
          return b;
        }
      }

      // At this point the lists are different sizes or every comparison is true.
      return new org.python.types.Bool(size >= otherSize);

    } else {
      throw new org.python.exceptions.TypeError(
          String.format("unorderable types: list() >= %s()", Python.typeName(other.getClass())));
    }
  }
Example #2
0
File: List.java Project: pybee/voc
 @org.python.Method(__doc__ = "")
 public org.python.Object __iadd__(org.python.Object other) {
   if (other instanceof org.python.types.List) {
     this.value.addAll(((org.python.types.List) other).value);
     return this;
   } else if (other instanceof org.python.types.Tuple) {
     this.value.addAll(((org.python.types.Tuple) other).value);
     return this;
   } else {
     throw new org.python.exceptions.TypeError(
         String.format("'%s' object is not iterable", Python.typeName(other.getClass())));
   }
 }
Example #3
0
File: List.java Project: pybee/voc
 @org.python.Method(__doc__ = "")
 public org.python.Object __add__(org.python.Object other) {
   if (other instanceof org.python.types.List) {
     org.python.types.List result = new org.python.types.List();
     result.value.addAll(this.value);
     result.value.addAll(((org.python.types.List) other).value);
     return result;
   } else {
     throw new org.python.exceptions.TypeError(
         String.format(
             "can only concatenate list (not \"%s\") to list", Python.typeName(other.getClass())));
   }
 }