Source Code Cross Referenced for bitfield.java in  » Search-Engine » yacy » de » anomic » tools » 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 » Search Engine » yacy » de.anomic.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // bitfield.java 
002:        // -------------------------------------
003:        // (C) by Michael Peter Christen; mc@anomic.de
004:        // first published on http://www.anomic.de
005:        // Frankfurt, Germany, 2004
006:        // last major change: 11.08.2004
007:        //
008:        // This program is free software; you can redistribute it and/or modify
009:        // it under the terms of the GNU General Public License as published by
010:        // the Free Software Foundation; either version 2 of the License, or
011:        // (at your option) any later version.
012:        //
013:        // This program is distributed in the hope that it will be useful,
014:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
015:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:        // GNU General Public License for more details.
017:        //
018:        // You should have received a copy of the GNU General Public License
019:        // along with this program; if not, write to the Free Software
020:        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
021:        //
022:        // Using this software in any meaning (reading, learning, copying, compiling,
023:        // running) means that you agree that the Author(s) is (are) not responsible
024:        // for cost, loss of data or any harm that may be caused directly or indirectly
025:        // by usage of this softare or this documentation. The usage of this software
026:        // is on your own risk. The installation and usage (starting/running) of this
027:        // software may allow other people or application to access your computer and
028:        // any attached devices and is highly dependent on the configuration of the
029:        // software which must be done by the user of the software; the author(s) is
030:        // (are) also not responsible for proper configuration and usage of the
031:        // software, even if provoked by documentation provided together with
032:        // the software.
033:        //
034:        // Any changes to this file according to the GPL as documented in the file
035:        // gpl.txt aside this file in the shipment you received can be done to the
036:        // lines that follows this copyright notice here, but changes must not be
037:        // done inside the copyright notive above. A re-distribution must contain
038:        // the intact and unchanged copyright notice.
039:        // Contributions and changes to the program code must be marked as such.
040:
041:        package de.anomic.tools;
042:
043:        public class bitfield {
044:
045:            private byte[] bb;
046:
047:            public bitfield() {
048:                this (0);
049:            }
050:
051:            public bitfield(int bytelength) {
052:                this .bb = new byte[bytelength];
053:                for (int i = 0; i < bytelength; i++)
054:                    bb[i] = 0;
055:            }
056:
057:            public bitfield(byte[] field) {
058:                bb = field;
059:            }
060:
061:            private static byte setAtom(byte a, int pos) {
062:                if ((pos > 5) || (pos < 0))
063:                    throw new RuntimeException("atom position out of bounds: "
064:                            + pos);
065:                return (byte) ((64 | ((a + 16) | (1 << pos))) - 16);
066:            }
067:
068:            private static byte unsetAtom(byte a, int pos) {
069:                if ((pos > 5) || (pos < 0))
070:                    throw new RuntimeException("atom position out of bounds: "
071:                            + pos);
072:                return (byte) (((a + 16) & (0xff ^ (1 << pos))) - 16);
073:            }
074:
075:            public void set(int pos, boolean value) {
076:                int slot = pos / 6;
077:                if (pos < 0)
078:                    throw new RuntimeException("position out of bounds: " + pos);
079:                if (slot > bb.length) {
080:                    // extend capacity
081:                    byte[] nb = new byte[slot + 1];
082:                    System.arraycopy(bb, 0, nb, 0, bb.length);
083:                    for (int i = bb.length; i < nb.length; i++)
084:                        nb[i] = 0;
085:                    bb = nb;
086:                    nb = null;
087:                }
088:                bb[slot] = (value) ? setAtom(bb[slot], pos % 6) : unsetAtom(
089:                        bb[slot], pos % 6);
090:            }
091:
092:            public boolean get(int pos) {
093:                int slot = pos / 6;
094:                if (pos < 0)
095:                    throw new RuntimeException("position out of bounds: " + pos);
096:                if (slot > bb.length)
097:                    return false;
098:                return (bb[slot] & (1 << (pos % 6))) > 0;
099:            }
100:
101:            public int length() {
102:                return bb.length * 6;
103:            }
104:
105:            public byte[] getBytes() {
106:                return bb;
107:            }
108:
109:            public String toString() {
110:                throw new UnsupportedOperationException("testing");
111:                /*
112:                StringBuffer sb = new StringBuffer(length());
113:                for (int i = length() - 1; i >= 0; i--) sb.append((get(i)) ? '1' : '0');
114:                return sb.toString();
115:                 */
116:            }
117:
118:            public static void main(String[] args) {
119:                bitfield test = new bitfield(4);
120:                int l = test.length();
121:                System.out.println("available: " + l);
122:                System.out.println("before:    " + test.toString());
123:                for (int i = 0; i < l / 2; i++) {
124:                    test.set(i, true);
125:                    System.out.println(i + ":" + test.toString());
126:                }
127:                for (int i = l / 2 - 1; i >= 0; i--) {
128:                    test.set(i, false);
129:                    System.out.println(i + ":" + test.toString());
130:                }
131:                System.out.println("after:     " + test.toString());
132:            }
133:
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.