Source Code Cross Referenced for NExtremeBufferHolder.java in  » Profiler » JAMon » com » jamonapi » utils » 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 » Profiler » JAMon » com.jamonapi.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jamonapi.utils;
002:
003:        import java.util.*;
004:
005:        /** Buffer used to keep the last N recent values based on the comparator.  Note the Comparator must
006:         * be thread safe.
007:         * @author steve souza
008:         *
009:         */
010:        public class NExtremeBufferHolder implements  BufferHolder, Comparator {
011:
012:            private Object nextToRemove;
013:            private List list = new ArrayList();
014:
015:            private static final int EQUALTO = 0;
016:            private static final int GREATERTHAN = 1;
017:            private Comparator comparator;
018:
019:            public NExtremeBufferHolder(Comparator comparator) {
020:                this .comparator = comparator;
021:
022:            }
023:
024:            public NExtremeBufferHolder(boolean naturalOrder) {
025:                comparator = new JAMonComparator(naturalOrder);
026:            }
027:
028:            public List getCollection() {
029:                return list;
030:            }
031:
032:            public void setComparator(Comparator comparator) {
033:                this .comparator = comparator;
034:            }
035:
036:            public Comparator getComparator() {
037:                return comparator;
038:            }
039:
040:            private Object getNextToRemove() {
041:                return Collections.min(list, comparator);
042:            }
043:
044:            private boolean isTrue(int newVal) {
045:                return (newVal == GREATERTHAN || newVal == EQUALTO) ? true
046:                        : false;
047:
048:            }
049:
050:            /**
051:             * Method used by the comparator interface. <br><br>
052:             *   o1 &lt; o2 - returns a negative integer<br>
053:             *   o1==o2 - returns zero<br>
054:             *   o1>o2 - returns a postitive integer<br><br>
055:             *  Iterate through all columns that should be compared (in the proper order) 
056:             *  and call the Comparator for each of the column elements.
057:             * Note the column value is always the first argument and the comparison value is always the second
058:             * 
059:             *
060:             */
061:
062:            /*
063:             * Returns 
064:             * this object is less than - returns a negative integer, 
065:             * this object equal to - retunrs zero
066:             * this object greater than - return positive integer 
067:             */
068:            public int compare(Object newObj, Object existingObj) {
069:                return comparator.compare(newObj, existingObj);
070:            }
071:
072:            public void add(Object replaceWithObj) {
073:                list.add(replaceWithObj);
074:            }
075:
076:            public void remove(Object replaceWithObj) {
077:                list.remove(nextToRemove);
078:                nextToRemove = getNextToRemove();
079:            }
080:
081:            public boolean shouldReplaceWith(Object replaceWithObj) {
082:                if (nextToRemove == null)
083:                    nextToRemove = getNextToRemove();
084:
085:                return isTrue(compare(replaceWithObj, nextToRemove));
086:            }
087:
088:            public List getOrderedCollection() {
089:                Collections.sort(list, comparator);
090:                return list;
091:            }
092:
093:            public void setCollection(List list) {
094:                this .list = list;
095:
096:            }
097:
098:            public BufferHolder copy() {
099:                return new NExtremeBufferHolder(comparator);
100:            }
101:
102:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.