<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FCollections_Data_Structure%2FPriority_List</id>
		<title>Java/Collections Data Structure/Priority List - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FCollections_Data_Structure%2FPriority_List"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Collections_Data_Structure/Priority_List&amp;action=history"/>
		<updated>2026-04-18T22:17:22Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Collections_Data_Structure/Priority_List&amp;diff=9149&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Collections_Data_Structure/Priority_List&amp;diff=9149&amp;oldid=prev"/>
				<updated>2010-06-01T07:26:44Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 07:26, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Collections_Data_Structure/Priority_List&amp;diff=9148&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Collections_Data_Structure/Priority_List&amp;diff=9148&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:50Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== A basic priority linked list: maintaining an individual LinkedList for each priority level. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source&lt;br /&gt;
 * Copyright 2005, JBoss Inc., and individual contributors as indicated&lt;br /&gt;
 * by the @authors tag. See the copyright.txt in the distribution for a&lt;br /&gt;
 * full listing of individual contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it&lt;br /&gt;
 * under the terms of the GNU Lesser General Public License as&lt;br /&gt;
 * published by the Free Software Foundation; either version 2.1 of&lt;br /&gt;
 * the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is distributed in the hope that it will be useful,&lt;br /&gt;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&lt;br /&gt;
 * Lesser General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this software; if not, write to the Free&lt;br /&gt;
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA&lt;br /&gt;
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.LinkedList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import java.util.ListIterator;&lt;br /&gt;
import java.util.NoSuchElementException;&lt;br /&gt;
/**&lt;br /&gt;
 * A basic priority linked list&lt;br /&gt;
 * &lt;br /&gt;
 * It implements this by maintaining an individual LinkedList for each priority&lt;br /&gt;
 * level.&lt;br /&gt;
 * &lt;br /&gt;
 * @author &lt;br /&gt;
 * @version &amp;lt;tt&amp;gt;$Revision: 1174 $&amp;lt;/tt&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * $Id: BasicPrioritizedDeque.java 1174 2006-08-02 14:14:32Z timfox $&lt;br /&gt;
 */&lt;br /&gt;
public class BasicPriorityLinkedList {&lt;br /&gt;
  protected LinkedList[] linkedLists;&lt;br /&gt;
  protected int priorities;&lt;br /&gt;
  protected int size;&lt;br /&gt;
  public BasicPriorityLinkedList(int priorities) {&lt;br /&gt;
    this.priorities = priorities;&lt;br /&gt;
    initDeques();&lt;br /&gt;
  }&lt;br /&gt;
  public void addFirst(Object obj, int priority) {&lt;br /&gt;
    linkedLists[priority].addFirst(obj);&lt;br /&gt;
    size++;&lt;br /&gt;
  }&lt;br /&gt;
  public void addLast(Object obj, int priority) {&lt;br /&gt;
    linkedLists[priority].addLast(obj);&lt;br /&gt;
    size++;&lt;br /&gt;
  }&lt;br /&gt;
  public Object removeFirst() {&lt;br /&gt;
    Object obj = null;&lt;br /&gt;
    // Initially we are just using a simple prioritization algorithm:&lt;br /&gt;
    // Highest priority refs always get returned first.&lt;br /&gt;
    // This could cause starvation of lower priority refs.&lt;br /&gt;
    // TODO - A better prioritization algorithm&lt;br /&gt;
    for (int i = priorities - 1; i &amp;gt;= 0; i--) {&lt;br /&gt;
      LinkedList ll = linkedLists[i];&lt;br /&gt;
      if (!ll.isEmpty()) {&lt;br /&gt;
        obj = ll.removeFirst();&lt;br /&gt;
        break;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    if (obj != null) {&lt;br /&gt;
      size--;&lt;br /&gt;
    }&lt;br /&gt;
    return obj;&lt;br /&gt;
  }&lt;br /&gt;
  public Object removeLast() {&lt;br /&gt;
    Object obj = null;&lt;br /&gt;
    // Initially we are just using a simple prioritization algorithm:&lt;br /&gt;
    // Lowest priority refs always get returned first.&lt;br /&gt;
    // TODO - A better prioritization algorithm&lt;br /&gt;
    for (int i = 0; i &amp;lt; priorities; i++) {&lt;br /&gt;
      LinkedList ll = linkedLists[i];&lt;br /&gt;
      if (!ll.isEmpty()) {&lt;br /&gt;
        obj = ll.removeLast();&lt;br /&gt;
      }&lt;br /&gt;
      if (obj != null) {&lt;br /&gt;
        break;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    if (obj != null) {&lt;br /&gt;
      size--;&lt;br /&gt;
    }&lt;br /&gt;
    return obj;&lt;br /&gt;
  }&lt;br /&gt;
  public Object peekFirst() {&lt;br /&gt;
    Object obj = null;&lt;br /&gt;
    // Initially we are just using a simple prioritization algorithm:&lt;br /&gt;
    // Highest priority refs always get returned first.&lt;br /&gt;
    // This could cause starvation of lower priority refs.&lt;br /&gt;
    // TODO - A better prioritization algorithm&lt;br /&gt;
    for (int i = priorities - 1; i &amp;gt;= 0; i--) {&lt;br /&gt;
      LinkedList ll = linkedLists[i];&lt;br /&gt;
      if (!ll.isEmpty()) {&lt;br /&gt;
        obj = ll.getFirst();&lt;br /&gt;
      }&lt;br /&gt;
      if (obj != null) {&lt;br /&gt;
        break;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    return obj;&lt;br /&gt;
  }&lt;br /&gt;
  public List getAll() {&lt;br /&gt;
    List all = new ArrayList();&lt;br /&gt;
    for (int i = priorities - 1; i &amp;gt;= 0; i--) {&lt;br /&gt;
      LinkedList deque = linkedLists[i];&lt;br /&gt;
      all.addAll(deque);&lt;br /&gt;
    }&lt;br /&gt;
    return all;&lt;br /&gt;
  }&lt;br /&gt;
  public void clear() {&lt;br /&gt;
    initDeques();&lt;br /&gt;
  }&lt;br /&gt;
  public int size() {&lt;br /&gt;
    return size;&lt;br /&gt;
  }&lt;br /&gt;
  public boolean isEmpty() {&lt;br /&gt;
    return size == 0;&lt;br /&gt;
  }&lt;br /&gt;
  public ListIterator iterator() {&lt;br /&gt;
    return new PriorityLinkedListIterator(linkedLists);&lt;br /&gt;
  }&lt;br /&gt;
  protected void initDeques() {&lt;br /&gt;
    linkedLists = new LinkedList[priorities];&lt;br /&gt;
    for (int i = 0; i &amp;lt; priorities; i++) {&lt;br /&gt;
      linkedLists[i] = new LinkedList();&lt;br /&gt;
    }&lt;br /&gt;
    size = 0;&lt;br /&gt;
  }&lt;br /&gt;
  class PriorityLinkedListIterator implements ListIterator {&lt;br /&gt;
    private LinkedList[] lists;&lt;br /&gt;
    private int index;&lt;br /&gt;
    private ListIterator currentIter;&lt;br /&gt;
    PriorityLinkedListIterator(LinkedList[] lists) {&lt;br /&gt;
      this.lists = lists;&lt;br /&gt;
      index = lists.length - 1;&lt;br /&gt;
      currentIter = lists[index].listIterator();&lt;br /&gt;
    }&lt;br /&gt;
    public void add(Object arg0) {&lt;br /&gt;
      throw new UnsupportedOperationException();&lt;br /&gt;
    }&lt;br /&gt;
    public boolean hasNext() {&lt;br /&gt;
      if (currentIter.hasNext()) {&lt;br /&gt;
        return true;&lt;br /&gt;
      }&lt;br /&gt;
      while (index &amp;gt;= 0) {&lt;br /&gt;
        if (index == 0 || currentIter.hasNext()) {&lt;br /&gt;
          break;&lt;br /&gt;
        }&lt;br /&gt;
        index--;&lt;br /&gt;
        currentIter = lists[index].listIterator();&lt;br /&gt;
      }&lt;br /&gt;
      return currentIter.hasNext();&lt;br /&gt;
    }&lt;br /&gt;
    public boolean hasPrevious() {&lt;br /&gt;
      throw new UnsupportedOperationException();&lt;br /&gt;
    }&lt;br /&gt;
    public Object next() {&lt;br /&gt;
      if (!hasNext()) {&lt;br /&gt;
        throw new NoSuchElementException();&lt;br /&gt;
      }&lt;br /&gt;
      return currentIter.next();&lt;br /&gt;
    }&lt;br /&gt;
    public int nextIndex() {&lt;br /&gt;
      throw new UnsupportedOperationException();&lt;br /&gt;
    }&lt;br /&gt;
    public Object previous() {&lt;br /&gt;
      throw new UnsupportedOperationException();&lt;br /&gt;
    }&lt;br /&gt;
    public int previousIndex() {&lt;br /&gt;
      throw new UnsupportedOperationException();&lt;br /&gt;
    }&lt;br /&gt;
    public void remove() {&lt;br /&gt;
      currentIter.remove();&lt;br /&gt;
      size--;&lt;br /&gt;
    }&lt;br /&gt;
    public void set(Object obj) {&lt;br /&gt;
      throw new UnsupportedOperationException();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>