Exemplo n.º 1
1
  /**
   * Given a master list and the new sub list, replace the items in the master list with the
   * matching items from the new sub list. This process works even if the length of the new sublist
   * is different.
   *
   * <p>For example, givn:
   *
   * <pre>
   * replace A by A':
   *   M=[A,B,C], S=[A'] => [A',B,C]
   *   M=[A,B,A,B,C], S=[A',A'] => [A',B,A',B,C]
   *
   * when list length is different:
   *   M=[A,A,B,C], S=[] => [B,C]
   *   M=[A,B,C], S=[A',A'] => [A',A',B,C]
   *   M=[B,C], S=[A',A'] => [B,C,A',A']
   * </pre>
   */
  private static List<Child> stitchList(
      List<Child> list, String name, List<? extends Child> newSubList) {
    List<Child> removed = new LinkedList<Child>();
    // to preserve order, try to put new itesm where old items are found.
    // if the new list is longer than the current list, we put all the extra
    // after the last item in the sequence. That is,
    // given [A,A,B,C] and [A',A',A'], we'll update the list to [A',A',A',B,C]
    // The 'last' variable remembers the insertion position.
    int last = list.size();

    ListIterator<Child> itr = list.listIterator();
    ListIterator<? extends Child> jtr = newSubList.listIterator();
    while (itr.hasNext()) {
      Child child = itr.next();
      if (child.name.equals(name)) {
        if (jtr.hasNext()) {
          itr.set(jtr.next()); // replace
          last = itr.nextIndex();
          removed.add(child);
        } else {
          itr.remove(); // remove
          removed.add(child);
        }
      }
    }

    // new list is longer than the current one
    if (jtr.hasNext()) list.addAll(last, newSubList.subList(jtr.nextIndex(), newSubList.size()));

    return removed;
  }
Exemplo n.º 2
0
  /**
   * Creates a KeyFrameInterpolator, with {@code frame} as associated {@link #frame()}.
   *
   * <p>The {@link #frame()} can be set or changed using {@link #setFrame(Frame)}.
   *
   * <p>{@link #interpolationTime()}, {@link #interpolationSpeed()} and {@link
   * #interpolationPeriod()} are set to their default values.
   */
  public KeyFrameInterpolator(AbstractScene scn, Frame frame) {
    gScene = scn;
    keyFrameList = new ArrayList<KeyFrame>();
    path = new ArrayList<Frame>();
    mainFrame = null;
    period = 40;
    interpolationTm = 0.0f;
    interpolationSpd = 1.0f;
    interpolationStrt = false;
    lpInterpolation = false;
    pathIsValid = false;
    valuesAreValid = true;
    currentFrmValid = false;
    setFrame(frame);

    currentFrame0 = keyFrameList.listIterator();
    currentFrame1 = keyFrameList.listIterator();
    currentFrame2 = keyFrameList.listIterator();
    currentFrame3 = keyFrameList.listIterator();

    interpolationTimerTask =
        new TimingTask() {
          public void execute() {
            update();
          }
        };
    gScene.registerTimingTask(interpolationTimerTask);
  }
Exemplo n.º 3
0
Arquivo: Align.java Projeto: nh13/SRMA
  private static void resetAttributes(
      SAMRecord rec, List<String> optFieldTags, List<Object> optFieldValues) {
    ListIterator<String> iterTags = optFieldTags.listIterator();
    ListIterator<Object> iterValues = optFieldValues.listIterator();

    while (iterTags.hasNext()) {
      rec.setAttribute(iterTags.next(), iterValues.next());
    }
  }
Exemplo n.º 4
0
 public static void reverse(List<?> list) {
   int size = list.size();
   ListIterator fwd = list.listIterator();
   ListIterator rev = list.listIterator(size);
   for (int i = 0, mid = list.size() >> 1; i < mid; i++) {
     Object tmp = fwd.next();
     fwd.set(rev.previous());
     rev.set(tmp);
   }
 }
Exemplo n.º 5
0
 public static void verify(List output, List expected) {
   verifyLength(output.size(), expected.size(), Test.EXACT);
   if (!expected.equals(output)) {
     // find the line of mismatch
     ListIterator it1 = expected.listIterator();
     ListIterator it2 = output.listIterator();
     while (it1.hasNext() && it2.hasNext() && it1.next().equals(it2.next())) ;
     throw new LineMismatchException(
         it1.nextIndex(), it1.previous().toString(), it2.previous().toString());
   }
 }
Exemplo n.º 6
0
 public static void minimize(List<Typing> tgs, IHierarchy h) {
   for (ListIterator<Typing> i = tgs.listIterator(); i.hasNext(); ) {
     Typing tgi = i.next();
     for (ListIterator<Typing> j = tgs.listIterator(); j.hasNext(); ) {
       Typing tgj = j.next();
       if (tgi != tgj && compare(tgi, tgj, h) == 1) {
         i.remove();
         break;
       }
     }
   }
 }
 // Breakout calculation of the termArrays equals
 private boolean termArraysEquals(List<Term[]> termArrays1, List<Term[]> termArrays2) {
   if (termArrays1.size() != termArrays2.size()) {
     return false;
   }
   ListIterator<Term[]> iterator1 = termArrays1.listIterator();
   ListIterator<Term[]> iterator2 = termArrays2.listIterator();
   while (iterator1.hasNext()) {
     Term[] termArray1 = iterator1.next();
     Term[] termArray2 = iterator2.next();
     if (!(termArray1 == null ? termArray2 == null : Arrays.equals(termArray1, termArray2))) {
       return false;
     }
   }
   return true;
 }
Exemplo n.º 8
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.
             }
           }
         }
       }
     }
   }
 }
  public ListIterator<ICFLibAnyObj> enumerateDetails(MssCFGenContext genContext) {
    final String S_ProcName = "CFInternetMssCFIterateTSecGroupIncByGroup.enumerateDetails() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext.getGenDef()");
    }

    List<ICFLibAnyObj> list = new LinkedList<ICFLibAnyObj>();

    if (genDef instanceof ICFInternetTSecGroupObj) {
      Iterator<ICFSecurityTSecGroupIncludeObj> elements =
          ((ICFInternetTSecGroupObj) genDef).getRequiredChildrenIncByGroup().iterator();
      while (elements.hasNext()) {
        list.add(elements.next());
      }
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(), S_ProcName, "genContext.getGenDef()", genDef, "ICFInternetTSecGroupObj");
    }

    return (list.listIterator());
  }
 /** 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);
 }
Exemplo n.º 11
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);
      }
    }
Exemplo n.º 12
0
  /**
   * 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);
  }
Exemplo n.º 13
0
  /**
   * 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;
  }
  public ListIterator<ICFLibAnyObj> enumerateDetails(MssCFGenContext genContext) {
    final String S_ProcName = "CFAsteriskMssCFIterateHostNodeConfFile.enumerateDetails() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext.getGenDef()");
    }

    List<ICFLibAnyObj> list = new LinkedList<ICFLibAnyObj>();

    if (genDef instanceof ICFAsteriskHostNodeObj) {
      Iterator<ICFAsteriskConfigurationFileObj> elements =
          ((ICFAsteriskHostNodeObj) genDef).getOptionalComponentsConfFile().iterator();
      while (elements.hasNext()) {
        list.add(elements.next());
      }
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(), S_ProcName, "genContext.getGenDef()", genDef, "ICFAsteriskHostNodeObj");
    }

    return (list.listIterator());
  }
Exemplo n.º 15
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);
             }
           }
         }
       }
     }
   }
 }
  public ListIterator<ICFLibAnyObj> enumerateDetails(MssCFGenContext genContext) {
    final String S_ProcName = "CFBamMssCFIterateNumberTypeRef.enumerateDetails() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext.getGenDef()");
    }

    List<ICFLibAnyObj> list = new LinkedList<ICFLibAnyObj>();

    if (genDef instanceof ICFBamNumberTypeObj) {
      Iterator<ICFBamTableColObj> elements =
          ((ICFBamNumberTypeObj) genDef).getOptionalChildrenRef().iterator();
      while (elements.hasNext()) {
        list.add(elements.next());
      }
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(), S_ProcName, "genContext.getGenDef()", genDef, "ICFBamNumberTypeObj");
    }

    return (list.listIterator());
  }
Exemplo n.º 17
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;
 }
Exemplo n.º 18
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);
    }
  }
Exemplo n.º 19
0
 public void setUp() throws Exception {
   super.setUp();
   farList =
       new LinkedList(Arrays.asList(farPerson("Polo"), farPerson("Alexander"), farPerson("Polo")));
   farIterator = farList.listIterator();
   iterator =
       new EncapsulatedListIterator<Person>(farIterator, membrane, defaultClassLoader(), loaderA);
 }
Exemplo n.º 20
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() + ">");
   }
 }
 /** listIterator throws an IndexOutOfBoundsException on a negative index */
 public void testListIterator1_IndexOutOfBoundsException() {
   try {
     List c = emptyArray();
     c.listIterator(-1);
     shouldThrow();
   } catch (IndexOutOfBoundsException e) {
   }
 }
Exemplo n.º 22
0
  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());
  }
Exemplo n.º 23
0
 /**
  * Sets the methods supported defined by this AllowHeader.
  *
  * @param methods - the Iterator of Strings defining the methods supported
  *     <p>in this AllowHeader
  * @throws ParseException which signals that an error has been reached
  *     <p>unexpectedly while parsing the Strings defining the methods supported.
  */
 public void setMethods(List<String> methods) throws ParseException {
   ListIterator<String> it = methods.listIterator();
   while (it.hasNext()) {
     Allow allow = new Allow();
     allow.setMethod((String) it.next());
     this.add(allow);
   }
 }
Exemplo n.º 24
0
 public static <T> void sort(List<T> list, Comparator<? super T> c) {
   Object[] a = list.toArray();
   Arrays.sort(a, (Comparator) c);
   ListIterator i = list.listIterator();
   for (int j = 0; j < a.length; j++) {
     i.next();
     i.set(a[j]);
   }
 }
Exemplo n.º 25
0
 /*
    data for this specific object not internal objects
 */
 public List print() {
   for (ListIterator it = datas.listIterator(); it.hasNext(); ) {
     SnapShotData shotA = (SnapShotData) it.next();
     for (ListIterator it1 = datas.listIterator(Math.max(0, it.previousIndex() - maxTimeRelation));
         it1.hasNext() && it1.nextIndex() < it.nextIndex() + maxTimeRelation; ) {
       SnapShotData shotB = (SnapShotData) it1.next();
       if (it.previousIndex() != it1.previousIndex()) {
         for (int i = 0; i < shotB.getNodeShadows().length; i++) {
           storage +=
               getSpeedRatio(shotA.getNodeShadows()[i], shotB.getNodeShadows()[i])
                   * getRelativeDir(shotA.getNodeShadows()[i], shotB.getNodeShadows()[i]);
           numOfValue++;
         }
       }
     }
   }
   return Arrays.asList(storage / numOfValue);
 }
Exemplo n.º 26
0
 public int getChildPosition(MindMapNode childNode) {
   int position = 0;
   for (ListIterator i = children.listIterator(); i.hasNext(); ++position) {
     if (((MindMapNode) i.next()) == childNode) {
       return position;
     }
   }
   return -1;
 }
Exemplo n.º 27
0
  protected void updateCurrentKeyFrameForTime(float time) {
    // Assertion: times are sorted in monotone order.
    // Assertion: keyFrame_ is not empty

    // TODO: Special case for loops when closed path is implemented !!
    if (!currentFrmValid)
      // Recompute everything from scratch
      currentFrame1 = keyFrameList.listIterator();

    // currentFrame_[1]->peekNext() <---> keyFr.get(currentFrame1.nextIndex());
    while (keyFrameList.get(currentFrame1.nextIndex()).time() > time) {
      currentFrmValid = false;
      if (!currentFrame1.hasPrevious()) break;
      currentFrame1.previous();
    }

    if (!currentFrmValid) currentFrame2 = keyFrameList.listIterator(currentFrame1.nextIndex());

    while (keyFrameList.get(currentFrame2.nextIndex()).time() < time) {
      currentFrmValid = false;

      if (!currentFrame2.hasNext()) break;

      currentFrame2.next();
    }

    if (!currentFrmValid) {
      currentFrame1 = keyFrameList.listIterator(currentFrame2.nextIndex());

      if ((currentFrame1.hasPrevious())
          && (time < keyFrameList.get(currentFrame2.nextIndex()).time())) currentFrame1.previous();

      currentFrame0 = keyFrameList.listIterator(currentFrame1.nextIndex());

      if (currentFrame0.hasPrevious()) currentFrame0.previous();

      currentFrame3 = keyFrameList.listIterator(currentFrame2.nextIndex());

      if (currentFrame3.hasNext()) currentFrame3.next();

      currentFrmValid = true;
      splineCacheIsValid = false;
    }
  }
Exemplo n.º 28
0
 // @RubyLevelMethod(name="reverse_each")
 public RubyValue reverse_each(RubyBlock block) {
   ListIterator /*<RubyValue>*/ ite = array_.listIterator(array_.size());
   while (ite.hasPrevious()) {
     RubyValue v = block.invoke(this, (RubyValue) ite.previous());
     if (block.breakedOrReturned()) {
       return v;
     }
   }
   return this;
 }
 /** listIterator throws an IndexOutOfBoundsException on a too high index */
 public void testListIterator2_IndexOutOfBoundsException() {
   try {
     List c = emptyArray();
     c.add("adasd");
     c.add("asdasdas");
     c.listIterator(100);
     shouldThrow();
   } catch (IndexOutOfBoundsException e) {
   }
 }
Exemplo n.º 30
0
 public void leaveTemps() {
   FrameMap frameMap = codegen.getFrameMap();
   List<ParameterInfo> infos = invocationParamBuilder.listAllParams();
   for (ListIterator<? extends ParameterInfo> iterator = infos.listIterator(infos.size());
       iterator.hasPrevious(); ) {
     ParameterInfo param = iterator.previous();
     if (!param.isSkippedOrRemapped()) {
       frameMap.leaveTemp(param.type);
     }
   }
 }