/**
   * Either adds a value to set or does nothing if value is already present.
   *
   * @param val Value to add.
   * @return The instance of value from this set or {@code null} if value was added.
   */
  @Nullable
  public V addx(V val) {
    A.notNull(val, "val");

    if (comp == null) {
      for (V v : vals) if (v.equals(val)) return v;

      vals.add(val);

      return null;
    }

    if (strict) {
      for (ListIterator<V> it = vals.listIterator(); it.hasNext(); ) {
        V v = it.next();

        // Prefer equals to comparator.
        if (v.equals(val)) return v;

        int c = comp.compare(v, val);

        if (c == 0) throw new IllegalStateException("Inconsistent equals and compare methods.");

        if (c > 0) {
          // Back up.
          it.previous();

          it.add(val);

          return null;
        }
      }

      vals.add(val);

      return null;
    }

    // Full scan first.
    for (V v : vals) if (v.equals(val)) return v;

    for (ListIterator<V> it = vals.listIterator(); it.hasNext(); ) {
      V v = it.next();

      if (comp.compare(v, val) > 0) {
        do {
          // Back up.
          v = it.previous();
        } while (comp.compare(v, val) == 0);

        it.add(val);

        return null;
      }
    }

    vals.add(val);

    return null;
  }
예제 #2
0
  public void connectGraph() {
    // make sure I have some elements - not sure what to do otherwise
    assert !streamElements.isEmpty();

    // go through the list and connect it together:
    ListIterator<Stream> childIter;
    childIter = (ListIterator<Stream>) streamElements.iterator();
    Stream source = null;

    while (childIter.hasNext()) {
      // advance the iterator:
      Stream sink = childIter.next();
      assert sink != null;

      // setup the sink itself
      sink.setupOperator();

      if (source != null && source.getOutputChannel() != null) {
        // create and connect a pass filter
        ChannelConnectFilter connect = new ChannelConnectFilter();
        Channel in = source.getOutputChannel();
        Channel out = sink.getInputChannel();
        connect.useChannels(in, out);
        connect.setupOperator();
      }
      source = sink;
    }

    // set myself up with proper input and output
    {
      inputChannel = streamElements.getFirst().getInputChannel();
      outputChannel = streamElements.getLast().getOutputChannel();
    }
  }
예제 #3
0
  void setupBufferLengths(Scheduler buffers) {
    ListIterator<Stream> childIter;
    childIter = (ListIterator<Stream>) streamElements.iterator();
    Stream source = null;
    Stream sink = null;

    // go through all the children
    while (childIter.hasNext()) {
      // advance the iterator:
      Stream child = childIter.next();
      assert child != null;
      child.setupBufferLengths(buffers);

      source = sink;
      sink = child;

      if (source != null) {
        assert sink != null;

        int buffSize = buffers.getBufferSizeBetween(new Iterator(source), new Iterator(sink));
        assert buffSize != 0;

        StreamIt.totalBuffer += buffSize;

        source.getOutputChannel().makePassThrough();
        sink.getInputChannel().setChannelSize(buffSize);
      }
    }
  }
  @Override
  void replaceChild(
      @SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) {
    // Replace child
    if (this._classOrInterfaceType_ == oldChild) {
      setClassOrInterfaceType((PClassOrInterfaceType) newChild);
      return;
    }

    for (ListIterator<PDim> i = this._dim_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set((PDim) newChild);
          newChild.parent(this);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    if (this._arrayInitializer_ == oldChild) {
      setArrayInitializer((PArrayInitializer) newChild);
      return;
    }

    throw new RuntimeException("Not a child.");
  }
예제 #5
0
 /**
  * Removes overloaded methods from the contents list and adds them to the overloadedMethods list
  * of the first overloaded method encountered.
  *
  * @param contents
  * @param doExtractedMethods
  */
 private static void cullOverloadedMethods(
     List<ClassContentsEntry> contents, boolean doExtractedMethods) {
   List<ClassContentsEntry> copy = new ArrayList<ClassContentsEntry>(contents);
   for (ClassContentsEntry o : copy) {
     if (o instanceof RelatableEntry) {
       MethodEntry me = (MethodEntry) o;
       if ((me.isRelatedMethod() == doExtractedMethods) && !me.isOverloadedMethod) {
         String meName = me.myEnd.toString();
         // search contents list for methods with identical name, and attach them as overloaded
         // methods.
         ListIterator<ClassContentsEntry> contentIterator = contents.listIterator();
         while (contentIterator.hasNext()) {
           Object o1 = contentIterator.next();
           if (o1 instanceof RelatableEntry) {
             MethodEntry me2 = (MethodEntry) o1;
             if (me2 == me) {
               continue;
             }
             String me2Name = me2.myEnd.toString();
             if (meName.equals(me2Name)) {
               contentIterator.remove();
               me.myOverloadedMethods.add(me2);
               me2.isOverloadedMethod = true; // set flag so array copy will skip this entry.
             }
           }
         }
       }
     }
   }
 }
예제 #6
0
  /**
   * Calculates how every traffic light should be switched Per node, per sign the waiting roadusers
   * are passed and per each roaduser the gain is calculated.
   *
   * @param The TLDecision is a tuple consisting of a traffic light and a reward (Q) value, for it
   *     to be green
   * @see gld.algo.tlc.TLDecision
   */
  public TLDecision[][] decideTLs() {
    int num_dec;
    int num_tld = tld.length;

    // Determine wheter it should be random or not
    boolean do_this_random = false;
    if (random_number.nextFloat() < random_chance) do_this_random = true;

    for (int i = 0; i < num_tld; i++) {
      num_dec = tld[i].length;
      for (int j = 0; j < num_dec; j++) {
        Sign currenttl = tld[i][j].getTL();
        float gain = 0;

        Drivelane currentlane = currenttl.getLane();
        int waitingsize = currentlane.getNumRoadusersWaiting();
        ListIterator queue = currentlane.getQueue().listIterator();

        if (!do_this_random) {
          for (; waitingsize > 0; waitingsize--) {
            Roaduser ru = (Roaduser) queue.next();
            int pos = ru.getPosition();
            Node destination = ru.getDestNode();
            gain +=
                q_table[currenttl.getId()][pos][destination.getId()][1]
                    - q_table[currenttl.getId()][pos][destination.getId()][0]; // red - green
          }
          float q = gain;
        } else gain = random_number.nextFloat();

        tld[i][j].setGain(gain);
      }
    }
    return tld;
  }
  public void updateRound() {
    ListIterator<Action> actionIterator = actions.listIterator();
    while (actionIterator.hasNext()) {
      Action a = actionIterator.next();
      if (currentRound >= (a.roundStarted + a.length)) {
        actionIterator.remove();
      }
    }

    aliveRounds += 1;

    updateDrawLoc();

    broadcast = (broadcast << 1) & 0x000FFFFF;
    if (regen > 0) regen--;

    Iterator<Map.Entry<Animation.AnimationType, Animation>> it = animations.entrySet().iterator();
    Map.Entry<Animation.AnimationType, Animation> entry;
    while (it.hasNext()) {
      entry = it.next();
      entry.getValue().updateRound();
      if (!entry.getValue().isAlive()) {
        if (entry.getKey() != DEATH_EXPLOSION) it.remove();
      }
    }
    currentRound++;
  }
예제 #8
0
  /** Sorts the static LinkedList mainlineLinks in the order they appear on the freeway */
  private LinkedList<Link> recursiveLinkSort(LinkedList<Link> links2) {

    if (links2.size() == 1) {

      return links2;

    } else {

      boolean swapMade = false;
      ListIterator<Link> itr1 = links2.listIterator();
      while (itr1.hasNext()) {
        Link temp = itr1.next();
        int tempindex = itr1.nextIndex();
        // if this loop makes any switches, set the flag to true
        if (links2.getFirst().getUpNode().getNodeID() == temp.getDownNode().getNodeID()) {
          swapMade = true;
          links2.addFirst(temp);
          links2.remove(tempindex);
          return this.recursiveLinkSort(links2);
        }
      }

      if (!swapMade) {
        // assign last n-1 links to links3
        LinkedList<Link> links3 = new LinkedList<Link>();
        Link temp = links2.getFirst();
        links2.removeFirst();
        links3 = this.recursiveLinkSort(links2);
        links3.addFirst(temp);
        return links3;
      } else {
        return links2;
      }
    }
  }
  /* Determines whether a course sequence is valid in the sense that all prerequisites
   * are satisfied when each course is taken.  This method uses the temporary
   * variable 'visited' associated with each course to efficiently validate the sequence.
   * Throws InvalidCourseNumberException if any of the course numbers are not positive.
   * Throws NoSuchElementException if any of the courses do not exist in the database.
   */
  boolean validateCourseSequence(int[] sequence)
      throws InvalidCourseNumberException, NoSuchElementException {
    ListIterator<Course> itr = courses.listIterator();
    Course course, next;
    boolean visited = true;
    for (; itr.hasNext(); ) {

      next = itr.next();
      next.setVisited(!visited);

      if (next.getCourseNumber() <= 0) {
        throw new InvalidCourseNumberException("The course number is invalid");
      }
    }
    for (int i = 0; i < sequence.length; i++) {
      course = getCourse(sequence[i]);

      if (course.canTakeCourse()) {
        course.setVisited(visited);
      } else {
        visited = false;
        return visited;
      }
    }
    return visited;
  }
  @Override
  public boolean incrementToken() throws IOException {
    while (!done && queue.size() < windowSize) {
      if (!input.incrementToken()) {
        done = true;
        break;
      }

      // reverse iterating for better efficiency since we know the
      // list is already sorted, and most token start offsets will be too.
      ListIterator<OrderedToken> iter = queue.listIterator(queue.size());
      while (iter.hasPrevious()) {
        if (offsetAtt.startOffset() >= iter.previous().startOffset) {
          // insertion will be before what next() would return (what
          // we just compared against), so move back one so the insertion
          // will be after.
          iter.next();
          break;
        }
      }
      OrderedToken ot = new OrderedToken();
      ot.state = captureState();
      ot.startOffset = offsetAtt.startOffset();
      iter.add(ot);
    }

    if (queue.isEmpty()) {
      return false;
    } else {
      restoreState(queue.removeFirst().state);
      return true;
    }
  }
  /*
   * Do the Samba! Perform a random sequence of next and previous
   * and check if you are at the correct point in the list
   */
  public void testSamba() {

    Random random = new Random();
    final int sambaSteps = 1;

    iter = list.listIterator(numElements / 2); // Position roughly in the middle
    int pos = numElements / 2;

    for (int i = 0; i < sambaSteps; i++) {
      boolean next = random.nextBoolean();

      // Randomly jump ahead or back
      // pos keeps track of where you should be
      if (next && iter.hasNext()) {
        iter.next();
        pos = pos + 1;
      } else if (!next && iter.hasPrevious()) {
        iter.previous();
        pos = pos - 1;
      }
    }

    // Check to see if you are where you ought to be
    assertTrue((pos == numElements) || (iter.next().equals(pos)));
  }
예제 #12
0
    @Override
    public Properties getMessages(String baseBundlename, Locale locale) throws IOException {
      if (messages.get(baseBundlename) == null
          || messages.get(baseBundlename).get(locale) == null) {
        Properties messages = new Properties();

        if (!Locale.ENGLISH.equals(locale)) {
          messages.putAll(getMessages(baseBundlename, Locale.ENGLISH));
        }

        ListIterator<Theme> itr = themes.listIterator(themes.size());
        while (itr.hasPrevious()) {
          Properties m = itr.previous().getMessages(baseBundlename, locale);
          if (m != null) {
            messages.putAll(m);
          }
        }

        this.messages.putIfAbsent(baseBundlename, new ConcurrentHashMap<Locale, Properties>());
        this.messages.get(baseBundlename).putIfAbsent(locale, messages);

        return messages;
      } else {
        return messages.get(baseBundlename).get(locale);
      }
    }
예제 #13
0
    // implement CallConvertlet
    public void convert(RexCall call) {
      // REVIEW jvs 18-Mar-2006:  The test for variableSeen
      // here and elsewhere precludes predicates like where
      // (boolean_col AND (int_col > 10)).  Should probably
      // support bare boolean columns as predicates with
      // coordinate TRUE.

      if (variableSeen || (coordinate != null)) {
        failed = true;
      }

      if (failed) {
        return;
      }

      int nOperands = call.getOperands().size();
      assert (exprStack.size() >= nOperands);

      SargSetExpr expr = factory.newSetExpr(boundInputRef.getType(), setOp);

      // Pop the correct number of operands off the stack
      // and transfer them to the new set expression.
      ListIterator<SargExpr> iter = exprStack.listIterator(exprStack.size() - nOperands);
      while (iter.hasNext()) {
        expr.addChild(iter.next());
        iter.remove();
      }

      exprStack.add(expr);
    }
예제 #14
0
파일: Dom.java 프로젝트: hk2-project/hk2
  /**
   * Inserts a new {@link Dom} node right after the given DOM element.
   *
   * @param reference If null, the new element will be inserted at the very beginning.
   * @param name The element name of the newly inserted item. "*" to indicate that the element name
   *     be determined by the model of the new node.
   */
  public synchronized void insertAfter(Dom reference, String name, Dom newNode) {
    // TODO: reparent newNode
    if (name.equals("*")) name = newNode.model.tagName;
    NodeChild newChild = new NodeChild(name, newNode);

    if (children.size() == 0) {
      children = new ArrayList<Child>();
    }
    if (reference == null) {
      children.add(0, newChild);
      newNode.domDescriptor =
          addWithAlias(getHabitat(), newNode, newNode.getProxyType(), newNode.getKey());
      return;
    }

    ListIterator<Child> itr = children.listIterator();
    while (itr.hasNext()) {
      Child child = itr.next();
      if (child instanceof NodeChild) {
        NodeChild nc = (NodeChild) child;
        if (nc.dom == reference) {
          itr.add(newChild);
          newNode.domDescriptor =
              addWithAlias(getHabitat(), newNode, newNode.getProxyType(), newNode.getKey());

          return;
        }
      }
    }
    throw new IllegalArgumentException(
        reference + " is not a valid child of " + this + ". Children=" + children);
  }
예제 #15
0
  /**
   * Encode the CertPath using PKIPATH format.
   *
   * @return a byte array containing the binary encoding of the PkiPath object
   * @exception CertificateEncodingException if an exception occurs
   */
  private byte[] encodePKIPATH() throws CertificateEncodingException {

    ListIterator<X509Certificate> li = certs.listIterator(certs.size());
    try {
      DerOutputStream bytes = new DerOutputStream();
      // encode certs in reverse order (trust anchor to target)
      // according to PkiPath format
      while (li.hasPrevious()) {
        X509Certificate cert = li.previous();
        // check for duplicate cert
        if (certs.lastIndexOf(cert) != certs.indexOf(cert)) {
          throw new CertificateEncodingException("Duplicate Certificate");
        }
        // get encoded certificates
        byte[] encoded = cert.getEncoded();
        bytes.write(encoded);
      }

      // Wrap the data in a SEQUENCE
      DerOutputStream derout = new DerOutputStream();
      derout.write(DerValue.tag_SequenceOf, bytes);
      return derout.toByteArray();

    } catch (IOException ioe) {
      throw new CertificateEncodingException("IOException encoding " + "PkiPath data: " + ioe, ioe);
    }
  }
 /** listIterator only returns those elements after the given index */
 public void testListIterator2() {
   List full = populatedArray(3);
   ListIterator i = full.listIterator(1);
   int j;
   for (j = 0; i.hasNext(); j++) assertEquals(j + 1, ((Integer) i.next()).intValue());
   assertEquals(2, j);
 }
예제 #17
0
  @Override
  void replaceChild(
      @SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) {
    // Replace child
    if (this._deNum_ == oldChild) {
      setDeNum((TNumeroInteiro) newChild);
      return;
    }

    if (this._ateNum_ == oldChild) {
      setAteNum((TNumeroInteiro) newChild);
      return;
    }

    for (ListIterator<PComandos> i = this._comandos_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set((PComandos) newChild);
          newChild.parent(this);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    throw new RuntimeException("Not a child.");
  }
    private TextFilePatch readPatch(String curLine, ListIterator<String> iterator)
        throws PatchSyntaxException {
      final TextFilePatch curPatch =
          mySaveHunks ? new TextFilePatch(null) : new EmptyTextFilePatch();
      extractFileName(curLine, curPatch, true, myDiffCommandLike && myIndexLike);

      if (!iterator.hasNext())
        throw new PatchSyntaxException(iterator.previousIndex(), "Second file name expected");
      curLine = iterator.next();
      String secondNamePrefix = myDiffFormat == DiffFormat.UNIFIED ? "+++ " : "--- ";
      if (!curLine.startsWith(secondNamePrefix)) {
        throw new PatchSyntaxException(iterator.previousIndex(), "Second file name expected");
      }
      extractFileName(curLine, curPatch, false, myDiffCommandLike && myIndexLike);

      while (iterator.hasNext()) {
        PatchHunk hunk;
        if (myDiffFormat == DiffFormat.UNIFIED) {
          hunk = readNextHunkUnified(iterator);
        } else {
          hunk = readNextHunkContext(iterator);
        }
        if (hunk == null) break;
        curPatch.addHunk(hunk);
      }
      if (curPatch.getBeforeName() == null) {
        curPatch.setBeforeName(curPatch.getAfterName());
      }
      if (curPatch.getAfterName() == null) {
        curPatch.setAfterName(curPatch.getBeforeName());
      }
      return curPatch;
    }
예제 #19
0
  @Override
  void replaceChild(
      @SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) {
    // Replace child
    if (this._quad_ == oldChild) {
      setQuad((TQuad) newChild);
      return;
    }

    for (ListIterator<TId> i = this._path_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set((TId) newChild);
          newChild.parent(this);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    if (this._id_ == oldChild) {
      setId((TId) newChild);
      return;
    }

    throw new RuntimeException("Not a child.");
  }
예제 #20
0
파일: IFD.java 프로젝트: KOST-CECO/SIP-Val
  /**
   * Reads an array of strings from the TIFF file.
   *
   * @param count Number of strings to read
   * @param value Offset from which to read
   */
  protected String[] readASCIIArray(long count, long value) throws IOException {
    _raf.seek(value);

    int nstrs = 0;
    List list = new LinkedList();
    byte[] buf = new byte[(int) count];
    _raf.read(buf);
    StringBuffer strbuf = new StringBuffer();
    for (int i = 0; i < count; i++) {
      int b = buf[i];
      if (b == 0) {
        list.add(strbuf.toString());
        strbuf.setLength(0);
      } else {
        strbuf.append((char) b);
      }
    }
    /* We can't use ArrayList.toArray because that returns an
    Object[], not a String[] ... sigh. */
    String[] strs = new String[nstrs];
    ListIterator iter = list.listIterator();
    for (int i = 0; i < nstrs; i++) {
      strs[i] = (String) iter.next();
    }
    return strs;
  }
예제 #21
0
    public String hasSameContent(JarFile2 file, JarEntry entry) throws IOException {

      String thisName = null;

      Long crcL = new Long(entry.getCrc());

      // check if this jar contains files with the passed in entry's crc
      if (_crcToEntryMap.containsKey(crcL)) {
        // get the Linked List with files with the crc
        LinkedList ll = (LinkedList) _crcToEntryMap.get(crcL);
        // go through the list and check for content match
        ListIterator li = ll.listIterator(0);
        if (li != null) {
          while (li.hasNext()) {
            JarEntry thisEntry = (JarEntry) li.next();

            // check for content match
            InputStream oldIS = getJarFile().getInputStream(thisEntry);
            InputStream newIS = file.getJarFile().getInputStream(entry);

            if (!differs(oldIS, newIS)) {
              thisName = thisEntry.getName();
              return thisName;
            }
          }
        }
      }

      return thisName;
    }
  @Override
  public String visitBoilerplate(@NotNull InfixParser.BoilerplateContext ctx) {
    // Declare all functions.
    ListIterator<InfixParser.FuncContext> funcIt = ctx.func().listIterator();

    String funcDefinitions = "";
    while (funcIt.hasNext()) {
      funcDefinitions += visit(funcIt.next());
      funcDefinitions += " ";
    }

    // Declare all variable names.
    String varDeclarations = "";

    for (VariableSymbol variableSymbol : variableSymbols) {
      varDeclarations += "variable ";
      varDeclarations += variableSymbol.getCompiledVariableName();
      varDeclarations += " ";
    }

    // Generate program code.
    String formatString = "%s%s: program %s ; program";
    forthSource =
        String.format(formatString, varDeclarations, funcDefinitions, visit(ctx.sequence()));

    // This is to allow generation of the postscript parse tree at a later time.
    rootCtx = ctx;

    return forthSource;
  }
예제 #23
0
 public void positionStmtsAfterEnumInitStmts(List<Statement> staticFieldStatements) {
   MethodNode method = getOrAddStaticConstructorNode();
   Statement statement = method.getCode();
   if (statement instanceof BlockStatement) {
     BlockStatement block = (BlockStatement) statement;
     // add given statements for explicitly declared static fields just after enum-special fields
     // are found - the $VALUES binary expression marks the end of such fields.
     List<Statement> blockStatements = block.getStatements();
     ListIterator<Statement> litr = blockStatements.listIterator();
     while (litr.hasNext()) {
       Statement stmt = litr.next();
       if (stmt instanceof ExpressionStatement
           && ((ExpressionStatement) stmt).getExpression() instanceof BinaryExpression) {
         BinaryExpression bExp = (BinaryExpression) ((ExpressionStatement) stmt).getExpression();
         if (bExp.getLeftExpression() instanceof FieldExpression) {
           FieldExpression fExp = (FieldExpression) bExp.getLeftExpression();
           if (fExp.getFieldName().equals("$VALUES")) {
             for (Statement tmpStmt : staticFieldStatements) {
               litr.add(tmpStmt);
             }
           }
         }
       }
     }
   }
 }
예제 #24
0
  public static void maxFlow(ListGraph g) {
    ListGraph residualG = g.residualGraph();

    LinkedList<DirEdge> path = residualG.getFlowPath();
    while (path != null) {
      // System.out.println("Got path");
      int minCapacity = ListGraph.minCapacityInPath(path);

      assert minCapacity > 0;
      // augment every edge on the path in the original graph
      int head = g.getSource();
      ListIterator it = path.listIterator();
      while (it.hasNext()) {
        DirEdge rEdge = (DirEdge) it.next();
        int tail = rEdge.end;

        DirEdge e = g.getEdge(head, tail);
        e.flow += minCapacity;

        // System.out.println("Augmenting (" + head + "," + tail + ") to be " + e.flow);

        head = tail;
      }

      residualG = g.residualGraph();

      // System.out.println("g:");
      // g.print();

      // System.out.println("Residual graph:");
      // residualG.print();

      path = residualG.getFlowPath();
    }
  }
    @Override
    public Object findElement(String s) {
      List<ObjectWithWeight> elements = new ArrayList<ObjectWithWeight>();
      s = s.trim();
      final ListIterator<Object> it = getElementIterator(0);
      while (it.hasNext()) {
        final ObjectWithWeight o = new ObjectWithWeight(it.next(), s, getComparator());
        if (!o.weights.isEmpty()) {
          elements.add(o);
        }
      }
      ObjectWithWeight cur = null;
      ArrayList<ObjectWithWeight> current = new ArrayList<ObjectWithWeight>();
      for (ObjectWithWeight element : elements) {
        if (cur == null) {
          cur = element;
          current.add(cur);
          continue;
        }

        final int i = element.compareWith(cur);
        if (i == 0) {
          current.add(element);
        } else if (i < 0) {
          cur = element;
          current.clear();
          current.add(cur);
        }
      }

      return current.isEmpty() ? null : findClosestTo(myInitialPsiElement, current);
    }
예제 #26
0
 private Column undeclaredHKeyColumn(HKeyColumn hKeyColumn) {
   Column undeclaredHKeyColumn = null;
   int rootMostDepth = rootMostTable().getDepth();
   List<Column> equivalentColumns = hKeyColumn.equivalentColumns();
   switch (getJoinType()) {
     case LEFT:
       // use a rootward bias, but no more rootward than the rootmost table
       for (Column equivalentColumn : equivalentColumns) {
         int equivalentColumnDepth = equivalentColumn.getTable().getDepth();
         if (undeclaredHKeyColumn == null && equivalentColumnDepth >= rootMostDepth) {
           undeclaredHKeyColumn = equivalentColumn;
         }
       }
       break;
     case RIGHT:
       // use a leafward bias, but no more leafward than the leafdmost table
       int leafMostDepth = leafMostTable().getDepth();
       for (ListIterator<Column> reverseCols =
               equivalentColumns.listIterator(equivalentColumns.size());
           reverseCols.hasPrevious(); ) {
         Column equivalentColumn = reverseCols.previous();
         int equivalentColumnDepth = equivalentColumn.getTable().getDepth();
         if (undeclaredHKeyColumn == null && equivalentColumnDepth <= leafMostDepth) {
           undeclaredHKeyColumn = equivalentColumn;
         }
       }
       break;
   }
   if (undeclaredHKeyColumn == null) {
     undeclaredHKeyColumn = hKeyColumn.column();
   }
   return undeclaredHKeyColumn;
 }
예제 #27
0
  protected void processUses(FunctionStmtToken result, ListIterator<Token> iterator) {
    Token next = nextToken(iterator);
    if (next instanceof NamespaceUseStmtToken) {
      next = nextToken(iterator);
      if (!isOpenedBrace(next, BraceExprToken.Kind.SIMPLE)) unexpectedToken(next, "(");

      List<ArgumentStmtToken> arguments = new ArrayList<ArgumentStmtToken>();
      while (iterator.hasNext()) {
        ArgumentStmtToken argument = processArgument(iterator);
        if (argument == null) break;

        if (argument.getValue() != null) unexpectedToken(argument.getValue().getSingle());
        arguments.add(argument);

        FunctionStmtToken parent = analyzer.getFunction(true);
        if (parent != null) {
          parent.variable(argument.getName()).setUsed(true);

          if (argument.isReference()) {
            parent.variable(argument.getName()).setPassed(true).setUnstable(true);
          }

          parent = analyzer.peekClosure();
          if (parent != null) {
            parent.variable(argument.getName()).setUnstable(true);
          }
        }
      }

      result.setUses(arguments);
    } else {
      result.setUses(new ArrayList<ArgumentStmtToken>());
      iterator.previous();
    }
  }
예제 #28
0
 public static void verifyAtLeast(List output, List expected) {
   verifyLength(output.size(), expected.size(), Test.AT_LEAST);
   if (!output.containsAll(expected)) {
     ListIterator it = expected.listIterator();
     while (output.contains(it.next())) {}
     throw new SimpleTestException("expected: <" + it.previous().toString() + ">");
   }
 }
예제 #29
0
 public String getGoederen() {
   String returnString = "";
   ListIterator listItr = this.goederen.listIterator();
   while (listItr.hasNext()) {
     returnString += "*" + listItr.next() + "\n";
   }
   return returnString;
 }
  public void testAddElements(int size) {
    List<Integer> src = makeRandomNumberList(size);
    SinglyLinkedList l = new SinglyLinkedList();
    copy(src, l);

    ListIterator it = src.listIterator(src.size());
    while (it.hasPrevious()) assertEquals(it.previous(), l.pop_back());
  }