Exemplo n.º 1
0
 @Override
 public SecuredSeq getSeq(final int index)
     throws ReadDeniedException, AuthenticationRequiredException {
   checkRead();
   final Seq retval = holder.getBaseItem().getSeq(index);
   checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index).asNode(), retval.asNode()));
   return SecuredSeqImpl.getInstance(getModel(), retval);
 }
Exemplo n.º 2
0
 /**
  * Returns the collection of the Unicode of each character in this {@code CharSeq}.
  *
  * @return the collection of ths Unicode of each character
  */
 public Seq<Integer> eachCodePoint() {
   Seq<Integer> codePoints = Seq.newSeq();
   char[] chars = str.toCharArray();
   for (int i = 0; i < chars.length; i++) {
     codePoints.add((int) chars[i]);
   }
   return codePoints;
 }
Exemplo n.º 3
0
 /**
  * Scan through this CharSeq iteratively, generate a Seq of CharSeq with all the matching
  * subStrings.
  *
  * @param regex The regular expression
  * @return A Seq of CharSeq
  */
 public Seq<CharSeq> scan(String regex) {
   Pattern pat = Pattern.compile(regex);
   Matcher m = pat.matcher(str);
   Seq<CharSeq> charSeq = Seq.of();
   while (m.find()) {
     charSeq.add(CharSeq.of(m.group()));
   }
   return charSeq;
 }
Exemplo n.º 4
0
 /**
  * Searches pattern (regex) in the CharSeq and returns a Seq of CharSeq consists of the part
  * before it, the first match, and the part after it.
  *
  * <p>If no such match is found in this CharSeq, return a Seq of CharSeq consists two empty
  * CharSeqs and the CharSeq itself.
  *
  * @param regex Regular Expression
  * @return A Seq of CharSeq
  */
 public Seq<CharSeq> partition(String regex) {
   Matcher m = Pattern.compile(regex).matcher(str);
   if (m.find()) {
     return Seq.of(
         CharSeq.of(str.substring(0, m.start())),
         CharSeq.of(m.group()),
         CharSeq.of(str.substring(m.end())));
   } else {
     return Seq.of(CharSeq.of(""), CharSeq.of(""), CharSeq.of(str));
   }
 }
Exemplo n.º 5
0
 public boolean hasTail() {
   if (hasPayload()) {
     return seq != null;
   } else {
     return seq != null && seq.tail() != null;
   }
 }
Exemplo n.º 6
0
  /**
   * Searches pattern (regex) in the CharSeq and returns a Seq of CharSeq consists of the part
   * before it, the last match, and the part after it.
   *
   * <p>If no such match is found in this CharSeq, return a Seq of CharSeq consists of two empty
   * CharSeqs and the CharSeq itself.
   *
   * @param regex Regular Expression
   * @return A Seq of CharSeq
   */
  public Seq<CharSeq> rPartition(String regex) {
    Matcher m = Pattern.compile(regex).matcher(str);

    String match = null;
    int start = 0, end = 0;
    while (m.find()) {
      match = m.group();
      start = m.start();
      end = m.end();
    }
    if (match != null) {
      return Seq.of(
          CharSeq.of(str.substring(0, start)), CharSeq.of(match), CharSeq.of(str.substring(end)));
    }
    return Seq.of(CharSeq.of(""), CharSeq.of(""), CharSeq.of(str));
  }
Exemplo n.º 7
0
  /**
   * Runs a query with an external variable declaration.
   *
   * @throws IOException I/O exception
   */
  @Test
  public void queryBindSequence() throws IOException {
    Query query = session.query("declare variable $a external; $a");
    query.bind("a", "1\u00012", "xs:integer");
    assertEqual("1", query.next());
    assertEqual("2", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", "09\u0002xs:hexBinary\u00012", "xs:integer");
    assertEqual("09", query.next());
    assertEqual("2", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", Seq.get(new Item[] {Int.get(1), Str.get("X")}, 2));
    assertEqual("1", query.next());
    assertEqual("X", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", IntSeq.get(new long[] {1, 2}, AtomType.INT));
    assertEqual("1", query.next());
    assertEqual("2", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", IntSeq.get(new long[] {1, 2}, AtomType.INT), "xs:integer");
    assertEqual("1", query.next());
    assertEqual("2", query.next());
    query.close();
  }
Exemplo n.º 8
0
 /**
  * Converts this CharSeq to a new Character Seq.
  *
  * @return A Seq of Character
  */
 public Seq<Character> eachChar() {
   char[] chars = str.toCharArray();
   Character[] characters = new Character[str.length()];
   for (int i = 0; i < characters.length; i++) {
     characters[i] = chars[i];
   }
   return Seq.of(characters);
 }
Exemplo n.º 9
0
 /**
  * Encodes this {@code CharSeq} into a sequence of bytes using the platform's default charset,
  * storing the result into a new Byte Seq.
  *
  * @return A Seq of Byte
  */
 public Seq<Byte> eachByte() {
   byte[] rawBytes = str.getBytes();
   Byte[] bytes = new Byte[rawBytes.length];
   for (int i = 0; i < bytes.length; i++) {
     bytes[i] = rawBytes[i];
   }
   return Seq.of(bytes);
 }
Exemplo n.º 10
0
 public Pattern head() {
   if (!generated) {
     generate();
   }
   if (hasPayload()) {
     return wrap(token);
   } else {
     return (seq == null) ? null : seq.head();
   }
 }
Exemplo n.º 11
0
 public Seq<Pattern> tail() {
   if (!generated) {
     generate();
   }
   if (hasPayload()) {
     return seq;
   } else {
     return (seq == null) ? null : seq.tail();
   }
 }
Exemplo n.º 12
0
 @Override
 default boolean endsWith(Seq<? extends T> that) {
   Objects.requireNonNull(that, "that is null");
   if (that instanceof IndexedSeq) {
     int i = length() - 1;
     int j = that.length() - 1;
     if (j > i) {
       return false;
     } else {
       while (j >= 0) {
         if (!Objects.equals(this.get(i), that.get(j))) {
           return false;
         }
         i--;
         j--;
       }
       return true;
     }
   } else {
     return Seq.super.endsWith(that);
   }
 }
Exemplo n.º 13
0
 static <T, U, C extends Iterable<U>, R extends Traversable<U>> R scanRight(
     Iterable<? extends T> elements,
     U zero,
     BiFunction<? super T, ? super U, ? extends U> operation,
     C cumulativeResult,
     BiFunction<C, U, C> combiner,
     Function<C, R> finisher) {
   final Iterable<T> reversedElements = Seq.ofAll(elements).reverseIterator();
   return scanLeft(
       reversedElements,
       zero,
       (u, t) -> operation.apply(t, u),
       cumulativeResult,
       combiner,
       finisher);
 }
Exemplo n.º 14
0
 /**
  * get a SecuredSeq.
  *
  * @param securedModel The secured model that provides the security context
  * @param seq The Seq to secure.
  * @return the SecuredSeq
  */
 public static SecuredSeq getInstance(final SecuredModel securedModel, final Seq seq) {
   if (securedModel == null) {
     throw new IllegalArgumentException("Secured securedModel may not be null");
   }
   if (seq == null) {
     throw new IllegalArgumentException("Seq may not be null");
   }
   final ItemHolder<Seq, SecuredSeq> holder = new ItemHolder<Seq, SecuredSeq>(seq);
   final SecuredSeqImpl checker = new SecuredSeqImpl(securedModel, holder);
   // if we are going to create a duplicate proxy, just return this
   // one.
   if (seq instanceof SecuredSeq) {
     if (checker.isEquivalent((SecuredSeq) seq)) {
       return (SecuredSeq) seq;
     }
   }
   return holder.setSecuredItem(new SecuredItemInvoker(seq.getClass(), checker));
 }
Exemplo n.º 15
0
 public void splitIndex(String name, String seq) {
   int start = 0;
   boolean go = true;
   while (go) {
     int end = start + numberOfBases;
     if (end >= seq.length()) {
       end = seq.length();
       go = false;
     }
     String subSeq = seq.substring(start, end);
     File binarySeq = new File(indexDirectory, name + "_" + start + "-" + (end - 1));
     if (binarySeq.exists()) {
       System.out.println("WARNING, " + binarySeq + " already exists, skipping!");
       return;
     }
     Seq.writeBinarySequence(subSeq, binarySeq);
     start = end;
   }
 }
Exemplo n.º 16
0
  @Test
  public void testSimple() {

    Random rnd = ThreadLocalRandom.current();

    Seq<Integer> seq = new Seq<>();
    seq.add(0, rnd.nextInt(100));
    seq.add(1, rnd.nextInt(100));
    seq.add(2, rnd.nextInt(100));
    seq.add(3, rnd.nextInt(100));
    seq.add(4, rnd.nextInt(100));

    SeqIterator<Integer> iter = new SeqIterator<>(seq);

    try {
      Assert.assertNull(iter.getCurrItem());
      Assert.fail();
    } catch (Exception ex) {
      // expected
    }

    try {
      Assert.assertEquals(0, iter.getMovedItems().size());
      Assert.fail();
    } catch (Exception ex) {
      // expected
    }

    iter.moveToTime(0);

    Assert.assertNotNull(iter.getCurrItem());
    Assert.assertEquals(seq.getItems().get(0).getInteger(), iter.getCurrItem().getInteger());
    Assert.assertEquals(1, iter.getMovedItems().size());

    iter.moveToTime(2);

    Assert.assertNotNull(iter.getCurrItem());
    Assert.assertEquals(seq.getItems().get(2).getInteger(), iter.getCurrItem().getInteger());
    Assert.assertEquals(2, iter.getMovedItems().size());

    iter.moveToTime(10);

    Assert.assertNull(iter.getCurrItem());
    Assert.assertEquals(2, iter.getMovedItems().size());
  }
Exemplo n.º 17
0
 /** Flattens a seq of seqs into a single seq by concatenating each element in turn. */
 public static <A> Seq<A> flatten(Seq<? extends Iterable<A>> seq) {
   Seq.Builder<A> sb = Seq.builder();
   for (Iterable<A> as : seq) sb.append(as);
   return sb.build();
 }
Exemplo n.º 18
0
 /** Creates new SeqNodeIteratorImpl */
 public SeqNodeIteratorImpl(Iterator<Statement> iterator, Seq seq) {
   this.base = iterator;
   this.seq = seq;
   this.size = seq.size();
 }
Exemplo n.º 19
0
  public static void main(String[] args) {
    // instantiate some sequences
    Constant c1 = new Constant(4, 11);
    Constant c2 = new Constant(4, 0);
    Constant c3 = new Constant(0, 11);
    Constant c4 = new Constant(0, 0);
    Constant c5 = new Constant(4, 88);
    Constant c6 = new Constant(3, 55);
    Constant c7 = new Constant(0, -77);
    Constant c8 = new Constant(10, 22);
    Delta d1 = new Delta(4, 1, 1);
    Delta d2 = new Delta(4, 1, -1);
    Delta d3 = new Delta(0, 1, -1);
    Delta d4 = new Delta(0, 1, 0);
    Delta d5 = new Delta(4, 1, 0);
    Delta d6 = new Delta(3, 21, 1);
    Delta d7 = new Delta(0, 25, -2);
    Delta d8 = new Delta(10, 2, 4);
    Jumble j1 = new Jumble(new int[] {});
    Jumble j2 = new Jumble(new int[] {88});
    Jumble j3 = new Jumble(new int[] {97, 55});
    Jumble j4 = new Jumble(new int[] {199, 198, 197, 196, 195, 194, 193, 192});
    Jumble j5 = new Jumble(new int[] {102, 103, 101, 107, 109});
    Jumble j6 = new Jumble(new int[] {41, 42, 43, 44});
    // do everything twice just to double check
    for (int i = 0; i < 2; i++) {

      System.out.print("c1" + ":");
      System.out.print(c1);
      System.out.println(":");
      System.out.println(
          "(Seq)c1 instanceof Constant" + ":" + ((Seq) c1 instanceof Constant) + ":");
      System.out.println("(Seq)c1 instanceof Delta" + ":" + ((Seq) c1 instanceof Delta) + ":");
      System.out.println("(Seq)c1 instanceof Jumble" + ":" + ((Seq) c1 instanceof Jumble) + ":");
      System.out.println("c1.min()" + ":" + (c1.min()) + ":");

      System.out.print("c2" + ":");
      System.out.print(c2);
      System.out.println(":");
      System.out.println(
          "(Seq)c2 instanceof Constant" + ":" + ((Seq) c2 instanceof Constant) + ":");
      System.out.println("(Seq)c2 instanceof Delta" + ":" + ((Seq) c2 instanceof Delta) + ":");
      System.out.println("(Seq)c2 instanceof Jumble" + ":" + ((Seq) c2 instanceof Jumble) + ":");
      System.out.println("c2.min()" + ":" + (c2.min()) + ":");

      System.out.print("c3" + ":");
      System.out.print(c3);
      System.out.println(":");
      System.out.println(
          "(Seq)c3 instanceof Constant" + ":" + ((Seq) c3 instanceof Constant) + ":");
      System.out.println("(Seq)c3 instanceof Delta" + ":" + ((Seq) c3 instanceof Delta) + ":");
      System.out.println("(Seq)c3 instanceof Jumble" + ":" + ((Seq) c3 instanceof Jumble) + ":");
      System.out.println("c3.min()" + ":" + (c3.min()) + ":");

      System.out.print("c4" + ":");
      System.out.print(c4);
      System.out.println(":");
      System.out.println(
          "(Seq)c4 instanceof Constant" + ":" + ((Seq) c4 instanceof Constant) + ":");
      System.out.println("(Seq)c4 instanceof Delta" + ":" + ((Seq) c4 instanceof Delta) + ":");
      System.out.println("(Seq)c4 instanceof Jumble" + ":" + ((Seq) c4 instanceof Jumble) + ":");
      System.out.println("c4.min()" + ":" + (c4.min()) + ":");

      System.out.print("c5" + ":");
      System.out.print(c5);
      System.out.println(":");
      System.out.println(
          "(Seq)c5 instanceof Constant" + ":" + ((Seq) c5 instanceof Constant) + ":");
      System.out.println("(Seq)c5 instanceof Delta" + ":" + ((Seq) c5 instanceof Delta) + ":");
      System.out.println("(Seq)c5 instanceof Jumble" + ":" + ((Seq) c5 instanceof Jumble) + ":");
      System.out.println("c5.min()" + ":" + (c5.min()) + ":");

      System.out.print("c6" + ":");
      System.out.print(c6);
      System.out.println(":");
      System.out.println(
          "(Seq)c6 instanceof Constant" + ":" + ((Seq) c6 instanceof Constant) + ":");
      System.out.println("(Seq)c6 instanceof Delta" + ":" + ((Seq) c6 instanceof Delta) + ":");
      System.out.println("(Seq)c6 instanceof Jumble" + ":" + ((Seq) c6 instanceof Jumble) + ":");
      System.out.println("c6.min()" + ":" + (c6.min()) + ":");

      System.out.print("c7" + ":");
      System.out.print(c7);
      System.out.println(":");
      System.out.println(
          "(Seq)c7 instanceof Constant" + ":" + ((Seq) c7 instanceof Constant) + ":");
      System.out.println("(Seq)c7 instanceof Delta" + ":" + ((Seq) c7 instanceof Delta) + ":");
      System.out.println("(Seq)c7 instanceof Jumble" + ":" + ((Seq) c7 instanceof Jumble) + ":");
      System.out.println("c7.min()" + ":" + (c7.min()) + ":");

      System.out.print("c8" + ":");
      System.out.print(c8);
      System.out.println(":");
      System.out.println(
          "(Seq)c8 instanceof Constant" + ":" + ((Seq) c8 instanceof Constant) + ":");
      System.out.println("(Seq)c8 instanceof Delta" + ":" + ((Seq) c8 instanceof Delta) + ":");
      System.out.println("(Seq)c8 instanceof Jumble" + ":" + ((Seq) c8 instanceof Jumble) + ":");
      System.out.println("c8.min()" + ":" + (c8.min()) + ":");

      System.out.print("d1" + ":");
      System.out.print(d1);
      System.out.println(":");
      System.out.println(
          "(Seq)d1 instanceof Constant" + ":" + ((Seq) d1 instanceof Constant) + ":");
      System.out.println("(Seq)d1 instanceof Delta" + ":" + ((Seq) d1 instanceof Delta) + ":");
      System.out.println("(Seq)d1 instanceof Jumble" + ":" + ((Seq) d1 instanceof Jumble) + ":");
      System.out.println("d1.min()" + ":" + (d1.min()) + ":");

      System.out.print("d2" + ":");
      System.out.print(d2);
      System.out.println(":");
      System.out.println(
          "(Seq)d2 instanceof Constant" + ":" + ((Seq) d2 instanceof Constant) + ":");
      System.out.println("(Seq)d2 instanceof Delta" + ":" + ((Seq) d2 instanceof Delta) + ":");
      System.out.println("(Seq)d2 instanceof Jumble" + ":" + ((Seq) d2 instanceof Jumble) + ":");
      System.out.println("d2.min()" + ":" + (d2.min()) + ":");

      System.out.print("d3" + ":");
      System.out.print(d3);
      System.out.println(":");
      System.out.println(
          "(Seq)d3 instanceof Constant" + ":" + ((Seq) d3 instanceof Constant) + ":");
      System.out.println("(Seq)d3 instanceof Delta" + ":" + ((Seq) d3 instanceof Delta) + ":");
      System.out.println("(Seq)d3 instanceof Jumble" + ":" + ((Seq) d3 instanceof Jumble) + ":");
      System.out.println("d3.min()" + ":" + (d3.min()) + ":");

      System.out.print("d4" + ":");
      System.out.print(d4);
      System.out.println(":");
      System.out.println(
          "(Seq)d4 instanceof Constant" + ":" + ((Seq) d4 instanceof Constant) + ":");
      System.out.println("(Seq)d4 instanceof Delta" + ":" + ((Seq) d4 instanceof Delta) + ":");
      System.out.println("(Seq)d4 instanceof Jumble" + ":" + ((Seq) d4 instanceof Jumble) + ":");
      System.out.println("d4.min()" + ":" + (d4.min()) + ":");

      System.out.print("d5" + ":");
      System.out.print(d5);
      System.out.println(":");
      System.out.println(
          "(Seq)d5 instanceof Constant" + ":" + ((Seq) d5 instanceof Constant) + ":");
      System.out.println("(Seq)d5 instanceof Delta" + ":" + ((Seq) d5 instanceof Delta) + ":");
      System.out.println("(Seq)d5 instanceof Jumble" + ":" + ((Seq) d5 instanceof Jumble) + ":");
      System.out.println("d5.min()" + ":" + (d5.min()) + ":");

      System.out.print("d6" + ":");
      System.out.print(d6);
      System.out.println(":");
      System.out.println(
          "(Seq)d6 instanceof Constant" + ":" + ((Seq) d6 instanceof Constant) + ":");
      System.out.println("(Seq)d6 instanceof Delta" + ":" + ((Seq) d6 instanceof Delta) + ":");
      System.out.println("(Seq)d6 instanceof Jumble" + ":" + ((Seq) d6 instanceof Jumble) + ":");
      System.out.println("d6.min()" + ":" + (d6.min()) + ":");

      System.out.print("d6" + ":");
      System.out.print(d6);
      System.out.println(":");
      System.out.println(
          "(Seq)d6 instanceof Constant" + ":" + ((Seq) d6 instanceof Constant) + ":");
      System.out.println("(Seq)d6 instanceof Delta" + ":" + ((Seq) d6 instanceof Delta) + ":");
      System.out.println("(Seq)d6 instanceof Jumble" + ":" + ((Seq) d6 instanceof Jumble) + ":");
      System.out.println("d6.min()" + ":" + (d6.min()) + ":");

      System.out.print("d7" + ":");
      System.out.print(d7);
      System.out.println(":");
      System.out.println(
          "(Seq)d7 instanceof Constant" + ":" + ((Seq) d7 instanceof Constant) + ":");
      System.out.println("(Seq)d7 instanceof Delta" + ":" + ((Seq) d7 instanceof Delta) + ":");
      System.out.println("(Seq)d7 instanceof Jumble" + ":" + ((Seq) d7 instanceof Jumble) + ":");
      System.out.println("d7.min()" + ":" + (d7.min()) + ":");

      System.out.print("d8" + ":");
      System.out.print(d8);
      System.out.println(":");
      System.out.println(
          "(Seq)d8 instanceof Constant" + ":" + ((Seq) d8 instanceof Constant) + ":");
      System.out.println("(Seq)d8 instanceof Delta" + ":" + ((Seq) d8 instanceof Delta) + ":");
      System.out.println("(Seq)d8 instanceof Jumble" + ":" + ((Seq) d8 instanceof Jumble) + ":");
      System.out.println("d8.min()" + ":" + (d8.min()) + ":");

      System.out.print("j1" + ":");
      System.out.print(j1);
      System.out.println(":");
      System.out.println(
          "(Seq)j1 instanceof Constant" + ":" + ((Seq) j1 instanceof Constant) + ":");
      System.out.println("(Seq)j1 instanceof Delta" + ":" + ((Seq) j1 instanceof Delta) + ":");
      System.out.println("(Seq)j1 instanceof Jumble" + ":" + ((Seq) j1 instanceof Jumble) + ":");
      System.out.println("j1.min()" + ":" + (j1.min()) + ":");

      System.out.print("j2" + ":");
      System.out.print(j2);
      System.out.println(":");
      System.out.println(
          "(Seq)j2 instanceof Constant" + ":" + ((Seq) j2 instanceof Constant) + ":");
      System.out.println("(Seq)j2 instanceof Delta" + ":" + ((Seq) j2 instanceof Delta) + ":");
      System.out.println("(Seq)j2 instanceof Jumble" + ":" + ((Seq) j2 instanceof Jumble) + ":");
      System.out.println("j2.min()" + ":" + (j2.min()) + ":");

      System.out.print("j3" + ":");
      System.out.print(j3);
      System.out.println(":");
      System.out.println(
          "(Seq)j3 instanceof Constant" + ":" + ((Seq) j3 instanceof Constant) + ":");
      System.out.println("(Seq)j3 instanceof Delta" + ":" + ((Seq) j3 instanceof Delta) + ":");
      System.out.println("(Seq)j3 instanceof Jumble" + ":" + ((Seq) j3 instanceof Jumble) + ":");
      System.out.println("j3.min()" + ":" + (j3.min()) + ":");

      System.out.print("j4" + ":");
      System.out.print(j4);
      System.out.println(":");
      System.out.println(
          "(Seq)j4 instanceof Constant" + ":" + ((Seq) j4 instanceof Constant) + ":");
      System.out.println("(Seq)j4 instanceof Delta" + ":" + ((Seq) j4 instanceof Delta) + ":");
      System.out.println("(Seq)j4 instanceof Jumble" + ":" + ((Seq) j4 instanceof Jumble) + ":");
      System.out.println("j4.min()" + ":" + (j4.min()) + ":");

      System.out.print("j5" + ":");
      System.out.print(j5);
      System.out.println(":");
      System.out.println(
          "(Seq)j5 instanceof Constant" + ":" + ((Seq) j5 instanceof Constant) + ":");
      System.out.println("(Seq)j5 instanceof Delta" + ":" + ((Seq) j5 instanceof Delta) + ":");
      System.out.println("(Seq)j5 instanceof Jumble" + ":" + ((Seq) j5 instanceof Jumble) + ":");
      System.out.println("j5.min()" + ":" + (j5.min()) + ":");

      System.out.print("j6" + ":");
      System.out.print(j6);
      System.out.println(":");
      System.out.println(
          "(Seq)j6 instanceof Constant" + ":" + ((Seq) j6 instanceof Constant) + ":");
      System.out.println("(Seq)j6 instanceof Delta" + ":" + ((Seq) j6 instanceof Delta) + ":");
      System.out.println("(Seq)j6 instanceof Jumble" + ":" + ((Seq) j6 instanceof Jumble) + ":");
      System.out.println("j6.min()" + ":" + (j6.min()) + ":");
      // check a bit more
      Seq x;
      x = j3;

      System.out.print("x" + ":");
      System.out.print(x);
      System.out.println(":");
      System.out.println("(Seq)x instanceof Constant" + ":" + ((Seq) x instanceof Constant) + ":");
      System.out.println("(Seq)x instanceof Delta" + ":" + ((Seq) x instanceof Delta) + ":");
      System.out.println("(Seq)x instanceof Jumble" + ":" + ((Seq) x instanceof Jumble) + ":");
      System.out.println("x.min()" + ":" + (x.min()) + ":");
      x = d4;

      System.out.print("x" + ":");
      System.out.print(x);
      System.out.println(":");
      System.out.println("(Seq)x instanceof Constant" + ":" + ((Seq) x instanceof Constant) + ":");
      System.out.println("(Seq)x instanceof Delta" + ":" + ((Seq) x instanceof Delta) + ":");
      System.out.println("(Seq)x instanceof Jumble" + ":" + ((Seq) x instanceof Jumble) + ":");
      System.out.println("x.min()" + ":" + (x.min()) + ":");
      x = c1;

      System.out.print("x" + ":");
      System.out.print(x);
      System.out.println(":");
      System.out.println("(Seq)x instanceof Constant" + ":" + ((Seq) x instanceof Constant) + ":");
      System.out.println("(Seq)x instanceof Delta" + ":" + ((Seq) x instanceof Delta) + ":");
      System.out.println("(Seq)x instanceof Jumble" + ":" + ((Seq) x instanceof Jumble) + ":");
      System.out.println("x.min()" + ":" + (x.min()) + ":");
    }
    // okay, if you're still not convinced ...
    Seq b[] = new Seq[8];
    b[0] = new Constant(8, 888);
    b[1] = new Jumble(new int[] {77, 78, 79});
    b[2] = new Jumble(new int[] {81, 82});
    b[3] = new Delta(4, 5, 1);
    b[4] = new Jumble(new int[] {});
    b[5] = new Jumble(new int[] {10, 1, 2, 3, 4, 5, 10, -1, -2, -3, -4});
    b[6] = new Delta(11, 0, 5);
    b[7] = new Constant(22, 222);
    for (int k = 0; k < 16; k++) {

      System.out.print("b[k%8]" + ":");
      System.out.print(b[k % 8]);
      System.out.println(":");
      System.out.println(
          "(Seq)b[k%8] instanceof Constant" + ":" + ((Seq) b[k % 8] instanceof Constant) + ":");
      System.out.println(
          "(Seq)b[k%8] instanceof Delta" + ":" + ((Seq) b[k % 8] instanceof Delta) + ":");
      System.out.println(
          "(Seq)b[k%8] instanceof Jumble" + ":" + ((Seq) b[k % 8] instanceof Jumble) + ":");
      System.out.println("b[k%8].min()" + ":" + (b[k % 8].min()) + ":");
    }
    // did you copy Jumble's array?
    int[] aa = {8, 4, 11};
    Jumble jj1 = new Jumble(aa);

    System.out.print("jj1" + ":");
    System.out.print(jj1);
    System.out.println(":");
    System.out.println(
        "(Seq)jj1 instanceof Constant" + ":" + ((Seq) jj1 instanceof Constant) + ":");
    System.out.println("(Seq)jj1 instanceof Delta" + ":" + ((Seq) jj1 instanceof Delta) + ":");
    System.out.println("(Seq)jj1 instanceof Jumble" + ":" + ((Seq) jj1 instanceof Jumble) + ":");
    System.out.println("jj1.min()" + ":" + (jj1.min()) + ":");
    aa[1] = 9999;
    Jumble jj2 = new Jumble(aa);

    System.out.print("jj2" + ":");
    System.out.print(jj2);
    System.out.println(":");
    System.out.println(
        "(Seq)jj2 instanceof Constant" + ":" + ((Seq) jj2 instanceof Constant) + ":");
    System.out.println("(Seq)jj2 instanceof Delta" + ":" + ((Seq) jj2 instanceof Delta) + ":");
    System.out.println("(Seq)jj2 instanceof Jumble" + ":" + ((Seq) jj2 instanceof Jumble) + ":");
    System.out.println("jj2.min()" + ":" + (jj2.min()) + ":");
    // jj1 shouldn't have been changed

    System.out.print("jj1" + ":");
    System.out.print(jj1);
    System.out.println(":");
    System.out.println(
        "(Seq)jj1 instanceof Constant" + ":" + ((Seq) jj1 instanceof Constant) + ":");
    System.out.println("(Seq)jj1 instanceof Delta" + ":" + ((Seq) jj1 instanceof Delta) + ":");
    System.out.println("(Seq)jj1 instanceof Jumble" + ":" + ((Seq) jj1 instanceof Jumble) + ":");
    System.out.println("jj1.min()" + ":" + (jj1.min()) + ":");
    System.exit(0);
  }
Exemplo n.º 20
0
 /**
  * Performs the given action for each line of the CharSeq, with additional parameter "index" as
  * the second parameter.
  *
  * @param action BiConsumer with parameters of CharSeq and the index
  * @return Self
  */
 public CharSeq forEachLine(BiConsumer<CharSeq, Integer> action) {
   Objects.requireNonNull(action);
   Seq<CharSeq> lines = this.eachLine();
   lines.forEach(action);
   return this;
 }
Exemplo n.º 21
0
 public void checkArguments(Seq argv) throws IllegalArgumentException {
   if (argv.length() != argc)
     throw new IllegalArgumentException(argv.length() + " != argc:" + argc);
 }
Exemplo n.º 22
0
 /**
  * Splits this CharSeq around matches of the given regular expression.
  *
  * @param regex Regular expression
  * @return
  */
 public Seq<CharSeq> split(String regex) {
   return Seq.of(str.split(regex)).map(CharSeq::new);
 }