Source Code Cross Referenced for ListUtil.java in  » Web-Framework » RSF » uk » org » ponder » arrayutil » 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 » Web Framework » RSF » uk.org.ponder.arrayutil 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 25-Oct-2003
003:         */
004:        package uk.org.ponder.arrayutil;
005:
006:        import java.util.ArrayList;
007:        import java.util.Enumeration;
008:        import java.util.List;
009:
010:        import uk.org.ponder.util.AssertionException;
011:
012:        /**
013:         * Contains useful utility methods for operating on java.util.List instances.
014:         * @author Bosmon
015:         *
016:         * The class 
017:         */
018:        public class ListUtil {
019:            public static final List EMPTY_LIST = new ArrayList(0);
020:
021:            public static Enumeration getEnumeration(final List list) {
022:                return new Enumeration() {
023:                    int pos = 0;
024:
025:                    public boolean hasMoreElements() {
026:                        return pos < list.size();
027:                    }
028:
029:                    public Object nextElement() {
030:                        return list.get(pos++);
031:                    }
032:                };
033:            }
034:
035:            /** Construct a new List instance comprised of the single supplied entry **/
036:
037:            public static List instance(Object entry) {
038:                List togo = new ArrayList();
039:                togo.add(entry);
040:                return togo;
041:            }
042:
043:            /** Construct a new List instance filled with the supplied array of objects **/
044:            public static List instance(Object[] init) {
045:                List togo = new ArrayList();
046:                append(togo, init);
047:                return togo;
048:            }
049:
050:            /** Append the elements in the supplied array to the end of the supplied list **/
051:            public static void append(List list, Object[] toappend) {
052:                if (toappend != null) {
053:                    for (int i = 0; i < toappend.length; ++i) {
054:                        list.add(toappend[i]);
055:                    }
056:                }
057:            }
058:
059:            public static void setSafe(List list, int index, Object toset) {
060:                if (index >= list.size()) {
061:                    expandSize(list, index + 1);
062:                }
063:                list.set(index, toset);
064:            }
065:
066:            public static Object getSafe(List list, int index) {
067:                if (index >= list.size()) {
068:                    expandSize(list, index + 1);
069:                }
070:                return list.get(index);
071:            }
072:
073:            public static void expandSize(List list, int newsize) {
074:                for (int i = list.size(); i < newsize; ++i) {
075:                    list.add(null);
076:                }
077:            }
078:
079:            public static void restrictSize(List list, int newsize) {
080:                for (int i = list.size() - 1; i >= newsize; --i) {
081:                    list.remove(i);
082:                }
083:            }
084:
085:            public static void setSize(List list, int newsize) {
086:                if (newsize > list.size()) {
087:                    expandSize(list, newsize);
088:                } else if (newsize < list.size()) {
089:                    restrictSize(list, newsize);
090:                }
091:            }
092:
093:            public static Object pop(List list) {
094:                int size = list.size();
095:                if (size == 0) {
096:                    throw new AssertionException(
097:                            "Attempt to pop from empty stack");
098:                } else {
099:                    Object togo = list.get(size - 1);
100:                    list.remove(size - 1);
101:                    return togo;
102:                }
103:            }
104:
105:            public static Object peek(List list) {
106:                return list.size() == 0 ? null : list.get(list.size() - 1);
107:            }
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.