Source Code Cross Referenced for ParameterNullnessProperty.java in  » Code-Analyzer » findbugs » edu » umd » cs » findbugs » ba » npe » 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 » Code Analyzer » findbugs » edu.umd.cs.findbugs.ba.npe 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Bytecode Analysis Framework
003:         * Copyright (C) 2005, University of Maryland
004:         * 
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:        package edu.umd.cs.findbugs.ba.npe;
020:
021:        import java.util.BitSet;
022:
023:        /**
024:         * Method property recording which parameters are (or should be)
025:         * non-null, meaning that null values should not be passed
026:         * as their arguments.
027:         * 
028:         * @author David Hovemeyer
029:         */
030:        public class ParameterNullnessProperty {
031:            /**
032:             * Maximum number of parameters that can be represented by a ParameterNullnessProperty.
033:             */
034:            public static final int MAX_PARAMS = 32;
035:
036:            private int nonNullParamSet;
037:
038:            /**
039:             * Constructor.
040:             * Parameters are all assumed not to be non-null.
041:             */
042:            public ParameterNullnessProperty() {
043:                this .nonNullParamSet = 0;
044:            }
045:
046:            /**
047:             * Get the non-null param bitset.
048:             * 
049:             * @return the non-null param bitset
050:             */
051:            int getNonNullParamSet() {
052:                return nonNullParamSet;
053:            }
054:
055:            /**
056:             * Set the non-null param bitset.
057:             * 
058:             * @param nonNullParamSet the non-null param bitset
059:             */
060:            void setNonNullParamSet(int nonNullParamSet) {
061:                this .nonNullParamSet = nonNullParamSet;
062:            }
063:
064:            /**
065:             * Set the non-null param set from given BitSet.
066:             * 
067:             * @param nonNullSet BitSet indicating which parameters are
068:             *                              non-null
069:             */
070:            public void setNonNullParamSet(BitSet nonNullSet) {
071:                for (int i = 0; i < 32; ++i) {
072:                    setNonNull(i, nonNullSet.get(i));
073:                }
074:            }
075:
076:            /**
077:             * Set whether or not a parameter might be non-null.
078:             * 
079:             * @param param              the parameter index
080:             * @param nonNull true if the parameter might be non-null, false otherwise
081:             */
082:            public void setNonNull(int param, boolean nonNull) {
083:                if (param < 0 || param > 31)
084:                    return;
085:                if (nonNull) {
086:                    nonNullParamSet |= (1 << param);
087:                } else {
088:                    nonNullParamSet &= ~(1 << param);
089:                }
090:            }
091:
092:            /**
093:             * Return whether or not a parameter might be non-null.
094:             * 
095:             * @param param the parameter index
096:             * @return true if the parameter might be non-null, false otherwise
097:             */
098:            public boolean isNonNull(int param) {
099:                if (param < 0 || param > 31)
100:                    return false;
101:                else
102:                    return (nonNullParamSet & (1 << param)) != 0;
103:            }
104:
105:            /**
106:             * Given a bitset of null arguments passed to the method represented
107:             * by this property, return a bitset indicating which null arguments
108:             * correspond to an non-null param.
109:             * 
110:             * @param nullArgSet bitset of null arguments
111:             * @return bitset intersecting null arguments and non-null params
112:             */
113:            public BitSet getViolatedParamSet(BitSet nullArgSet) {
114:                BitSet result = new BitSet();
115:                for (int i = 0; i < 32; ++i) {
116:                    result.set(i, nullArgSet.get(i) && isNonNull(i));
117:                }
118:                return result;
119:            }
120:
121:            public BitSet getAsBitSet() {
122:                BitSet result = new BitSet();
123:                if (isEmpty())
124:                    return result;
125:                for (int i = 0; i < 32; ++i) {
126:                    result.set(i, isNonNull(i));
127:                }
128:                return result;
129:            }
130:
131:            /**
132:             * Return whether or not the set of non-null parameters
133:             * is empty.
134:             * 
135:             * @return true if the set is empty, false if it contains at least one parameter
136:             */
137:            public boolean isEmpty() {
138:                return nonNullParamSet == 0;
139:            }
140:
141:            @Override
142:            public String toString() {
143:                StringBuffer buf = new StringBuffer();
144:
145:                buf.append('{');
146:                for (int i = 0; i < 32; ++i) {
147:                    if (isNonNull(i)) {
148:                        if (buf.length() > 1)
149:                            buf.append(',');
150:                        buf.append(i);
151:                    }
152:                }
153:                buf.append('}');
154:
155:                return buf.toString();
156:            }
157:
158:            /**
159:             * Intersect this set with the given set.
160:             * Useful for summarizing the properties of multiple methods.
161:             * 
162:             * @param targetDerefParamSet another set
163:             */
164:            public void intersectWith(
165:                    ParameterNullnessProperty targetDerefParamSet) {
166:                nonNullParamSet &= targetDerefParamSet.nonNullParamSet;
167:            }
168:
169:            /**
170:             * Make this object the same as the given one.
171:             * 
172:             * @param other another ParameterNullnessProperty
173:             */
174:            public void copyFrom(ParameterNullnessProperty other) {
175:                this.nonNullParamSet = other.nonNullParamSet;
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.