Source Code Cross Referenced for BoundedPriorityQueue.java in  » Ajax » Laszlo-4.0.10 » EDU » oswego » cs » dl » util » concurrent » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » Laszlo 4.0.10 » EDU.oswego.cs.dl.util.concurrent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          File: BoundedPriorityQueue.java
003:
004:          Originally written by Doug Lea and released into the public domain.
005:          This may be used for any purposes whatsoever without acknowledgment.
006:          Thanks for the assistance and support of Sun Microsystems Labs,
007:          and everyone contributing, testing, and using this code.
008:
009:          History:
010:          Date       Who                What
011:          16Jun1998  dl               Create public version
012:          25aug1998  dl               added peek
013:          29aug1998  dl               pulled heap mechanics into separate class
014:         */
015:
016:        package EDU.oswego.cs.dl.util.concurrent;
017:
018:        import java.util.Comparator;
019:        import java.lang.reflect.*;
020:
021:        /**
022:         * A heap-based priority queue, using semaphores for
023:         * concurrency control. 
024:         * The take operation returns the <em>least</em> element
025:         * with respect to the given ordering. (If more than
026:         * one element is tied for least value, one of them is
027:         * arbitrarily chosen to be returned -- no guarantees
028:         * are made for ordering across ties.)
029:         * Ordering follows the JDK1.2 collection
030:         * conventions: Either the elements must be Comparable, or
031:         * a Comparator must be supplied. Comparison failures throw
032:         * ClassCastExceptions during insertions and extractions.
033:         * The implementation uses a standard array-based heap algorithm,
034:         * as described in just about any data structures textbook.
035:         * <p>
036:         * Put and take operations may throw ClassCastException 
037:         * if elements are not Comparable, or
038:         * not comparable using the supplied comparator. 
039:         * Since not all elements are compared on each operation
040:         * it is possible that an exception will not be thrown 
041:         * during insertion of non-comparable element, but will later be 
042:         * encountered during another insertion or extraction.
043:         * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
044:         **/
045:
046:        public class BoundedPriorityQueue extends SemaphoreControlledChannel {
047:            protected final Heap heap_;
048:
049:            /**
050:             * Create a priority queue with the given capacity and comparator
051:             * @exception IllegalArgumentException if capacity less or equal to zero
052:             **/
053:
054:            public BoundedPriorityQueue(int capacity, Comparator cmp)
055:                    throws IllegalArgumentException {
056:                super (capacity);
057:                heap_ = new Heap(capacity, cmp);
058:            }
059:
060:            /**
061:             * Create a priority queue with the current default capacity
062:             * and the given comparator
063:             **/
064:
065:            public BoundedPriorityQueue(Comparator comparator) {
066:                this (DefaultChannelCapacity.get(), comparator);
067:            }
068:
069:            /**
070:             * Create a priority queue with the given capacity,
071:             * and relying on natural ordering.
072:             **/
073:
074:            public BoundedPriorityQueue(int capacity) {
075:                this (capacity, null);
076:            }
077:
078:            /**
079:             * Create a priority queue with the current default capacity
080:             * and relying on natural ordering.
081:             **/
082:
083:            public BoundedPriorityQueue() {
084:                this (DefaultChannelCapacity.get(), null);
085:            }
086:
087:            /**
088:             * Create a priority queue with the given capacity and comparator, using
089:             * the supplied Semaphore class for semaphores.
090:             * @exception IllegalArgumentException if capacity less or equal to zero
091:             * @exception NoSuchMethodException If class does not have constructor 
092:             * that intializes permits
093:             * @exception SecurityException if constructor information 
094:             * not accessible
095:             * @exception InstantiationException if semaphore class is abstract
096:             * @exception IllegalAccessException if constructor cannot be called
097:             * @exception InvocationTargetException if semaphore constructor throws an
098:             * exception
099:             **/
100:
101:            public BoundedPriorityQueue(int capacity, Comparator cmp,
102:                    Class semaphoreClass) throws IllegalArgumentException,
103:                    NoSuchMethodException, SecurityException,
104:                    InstantiationException, IllegalAccessException,
105:                    InvocationTargetException {
106:                super (capacity, semaphoreClass);
107:                heap_ = new Heap(capacity, cmp);
108:            }
109:
110:            protected void insert(Object x) {
111:                heap_.insert(x);
112:            }
113:
114:            protected Object extract() {
115:                return heap_.extract();
116:            }
117:
118:            public Object peek() {
119:                return heap_.peek();
120:            }
121:
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.