Skip to content

Commit 98f5a54

Browse files
committed
TIJ4e Refreshed
1 parent a0fe6da commit 98f5a54

File tree

875 files changed

+38820
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

875 files changed

+38820
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ $RECYCLE.BIN/
4141
Network Trash Folder
4242
Temporary Items
4343
.apdisk
44+
45+
*.class

Copyright.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
This computer source code is Copyright (c)2006 MindView, Inc.
2+
All Rights Reserved.
3+
4+
Permission to use, copy, modify, and distribute this
5+
computer source code (Source Code) and its documentation
6+
without fee and without a written agreement for the
7+
purposes set forth below is hereby granted, provided that
8+
the above copyright notice, this paragraph and the
9+
following five numbered paragraphs appear in all copies.
10+
11+
1. Permission is granted to compile the Source Code and to
12+
include the compiled code, in executable format only, in
13+
personal and commercial software programs.
14+
15+
2. Permission is granted to use the Source Code without
16+
modification in classroom situations, including in
17+
presentation materials, provided that the book "Thinking in
18+
Java" is cited as the origin.
19+
20+
3. Permission to incorporate the Source Code into printed
21+
media may be obtained by contacting:
22+
23+
MindView, Inc. 5343 Valle Vista La Mesa, California 91941
24+
Wayne@MindView.net
25+
26+
4. The Source Code and documentation are copyrighted by
27+
MindView, Inc. The Source code is provided without express
28+
or implied warranty of any kind, including any implied
29+
warranty of merchantability, fitness for a particular
30+
purpose or non-infringement. MindView, Inc. does not
31+
warrant that the operation of any program that includes the Source Code will be uninterrupted or error-free. MindView,
32+
Inc. makes no representation about the suitability of the
33+
Source Code or of any software that includes the Source
34+
Code for any purpose. The entire risk as to the quality
35+
and performance of any program that includes the Source
36+
Code is with the user of the Source Code. The user
37+
understands that the Source Code was developed for research and instructional purposes and is advised not to rely
38+
exclusively for any reason on the Source Code or any
39+
program that includes the Source Code. Should the Source
40+
Code or any resulting software prove defective, the user
41+
assumes the cost of all necessary servicing, repair, or
42+
correction.
43+
44+
5. IN NO EVENT SHALL MINDVIEW, INC., OR ITS PUBLISHER BE
45+
LIABLE TO ANY PARTY UNDER ANY LEGAL THEORY FOR DIRECT,
46+
INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
47+
INCLUDING LOST PROFITS, BUSINESS INTERRUPTION, LOSS OF
48+
BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS, OR FOR
49+
PERSONAL INJURIES, ARISING OUT OF THE USE OF THIS SOURCE
50+
CODE AND ITS DOCUMENTATION, OR ARISING OUT OF THE INABILITY TO USE ANY RESULTING PROGRAM, EVEN IF MINDVIEW, INC., OR
51+
ITS PUBLISHER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
52+
DAMAGE. MINDVIEW, INC. SPECIFICALLY DISCLAIMS ANY
53+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55+
PURPOSE. THE SOURCE CODE AND DOCUMENTATION PROVIDED
56+
HEREUNDER IS ON AN "AS IS" BASIS, WITHOUT ANY ACCOMPANYING
57+
SERVICES FROM MINDVIEW, INC., AND MINDVIEW, INC. HAS NO
58+
OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
59+
ENHANCEMENTS, OR MODIFICATIONS.
60+
61+
Please note that MindView, Inc. maintains a Web site which
62+
is the sole distribution point for electronic copies of the Source Code, http://www.MindView.net (and official mirror
63+
sites), where it is freely available under the terms stated above.
64+
65+
If you think you've found an error in the Source Code,
66+
please submit a correction using the feedback system that you will find at http://www.MindView.net.

DEclipse.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/python
2+
"""
3+
DEclipse.py by Bruce Eckel, for Thinking in Java 4e
4+
5+
Undoes the effect of Eclipse.py, so that Ant can be used
6+
again to build the code tree.
7+
8+
You must have Python 2.3 installed to run this program. See www.python.org.
9+
"""
10+
import os
11+
12+
for path, dirs, files in os.walk('.'):
13+
for file in files:
14+
if file.endswith(".java"):
15+
filepath = path + os.sep + file
16+
code = open(filepath).readlines()
17+
found = False
18+
for n, line in enumerate(code):
19+
if line.find(" /* Added by Eclipse.py */") != -1:
20+
del code[n]
21+
open(filepath, 'w').writelines(code)
22+
23+
24+
print "Project ready to be built with Ant."
25+

Eclipse.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/python
2+
"""
3+
Eclipse.py by Bruce Eckel, for Thinking in Java 4e
4+
Modify or insert package statments so that Eclipse is happy with the code tree.
5+
Run this with no arguments from the root of the code tree.
6+
7+
The Ant build will not work once you run this program!
8+
9+
You may also want to modify the dotproject and dotclasspath text below.
10+
11+
You must have Python 2.3 installed to run this program. See www.python.org.
12+
"""
13+
import os
14+
15+
os.remove("reusing/Lisa.java");
16+
17+
for path, dirs, files in os.walk('.'):
18+
for file in files:
19+
if file.endswith(".java"):
20+
filepath = path + os.sep + file
21+
firstLine = open(filepath).readline().strip()
22+
tagPath = firstLine.split()[1]
23+
tagPath = ".".join(tagPath.split('/')[:-1])
24+
packageStatement = "package " + tagPath + ";"
25+
code = open(filepath).readlines()
26+
found = False
27+
for line in code:
28+
if line.startswith("package "):
29+
found = True
30+
if not found:
31+
code.insert(1, packageStatement + " /* Added by Eclipse.py */\n")
32+
open(filepath, 'w').writelines(code)
33+
34+
here = os.path.abspath('.').replace("\\", "/")
35+
if here.startswith("/cygdrive/"): # If using cygwin
36+
here = here.replace("/cygdrive/", "", 1)
37+
here = here[0] + ":" + here[1:]
38+
print "here", here
39+
open(".classpath", 'w').write(\
40+
"""<?xml version="1.0" encoding="UTF-8"?>
41+
<classpath>
42+
<classpathentry excluding="polymorphism/|holding/|flow/|exceptions/|concurrency/|typeinfo/|innerclasses/|arrays/|interfaces/|reusing/|initialization/|cloning/|io/|containers/|generics/|xml/|hiding/|io/xfiles/|passing/|gui/|annotations/|enumerated/|discovering/|object/|strings/|swt/" kind="src" path=""/>
43+
<classpathentry kind="src" path="annotations"/>
44+
<classpathentry kind="src" path="arrays"/>
45+
<classpathentry kind="src" path="cloning"/>
46+
<classpathentry kind="src" path="concurrency"/>
47+
<classpathentry kind="src" path="containers"/>
48+
<classpathentry kind="src" path="discovering"/>
49+
<classpathentry kind="src" path="enumerated"/>
50+
<classpathentry kind="src" path="exceptions"/>
51+
<classpathentry kind="src" path="flow"/>
52+
<classpathentry kind="src" path="generics"/>
53+
<classpathentry kind="src" path="gui"/>
54+
<classpathentry kind="src" path="hiding"/>
55+
<classpathentry kind="src" path="holding"/>
56+
<classpathentry kind="src" path="initialization"/>
57+
<classpathentry kind="src" path="innerclasses"/>
58+
<classpathentry kind="src" path="interfaces"/>
59+
<classpathentry excluding="xfiles/" kind="src" path="io"/>
60+
<classpathentry kind="src" path="io/xfiles"/>
61+
<classpathentry kind="src" path="object"/>
62+
<classpathentry kind="src" path="passing"/>
63+
<classpathentry kind="src" path="polymorphism"/>
64+
<classpathentry kind="src" path="reusing"/>
65+
<classpathentry kind="src" path="strings"/>
66+
<classpathentry kind="src" path="swt"/>
67+
<classpathentry kind="src" path="typeinfo"/>
68+
<classpathentry kind="src" path="xml"/>
69+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.5.0_01"/>
70+
<classpathentry kind="output" path="bin"/>
71+
</classpath>
72+
""") # % (here, here))
73+
74+
open(".project", 'w').write(\
75+
"""<?xml version="1.0" encoding="UTF-8"?>
76+
<projectDescription>
77+
<name>TIJ4</name>
78+
<comment></comment>
79+
<projects>
80+
</projects>
81+
<buildSpec>
82+
<buildCommand>
83+
<name>org.eclipse.jdt.core.javabuilder</name>
84+
<arguments>
85+
</arguments>
86+
</buildCommand>
87+
</buildSpec>
88+
<natures>
89+
<nature>org.eclipse.jdt.core.javanature</nature>
90+
</natures>
91+
</projectDescription>
92+
93+
""")
94+
95+
if not os.path.exists(".settings"):
96+
os.mkdir(".settings")
97+
os.chdir(".settings")
98+
open("org.eclipse.jdt.core.prefs", 'w').write(\
99+
"""#Fri Jan 14 11:03:37 MST 2005
100+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
101+
org.eclipse.jdt.core.compiler.compliance=1.5
102+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
103+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
104+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
105+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
106+
eclipse.preferences.version=1
107+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
108+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
109+
org.eclipse.jdt.core.compiler.source=1.5
110+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
111+
""")
112+
113+
print """Project ready to be opened with Eclipse (see www.Eclipse.org)
114+
Use DEclipse.py if you want to go back to building with Ant."""
115+

FindBugsExcluder.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""FindBugsExcluder.py
2+
Creates a filter file from the xml and text output of FindBugs
3+
To prepare, you must run
4+
findbugs -textui . > findbugs.txt
5+
findbugs -textui -xml . > findbugs.xml
6+
Once you've run this program you can then run
7+
findbugs -textui -exclude FindBugsFilter-auto.xml .
8+
To exclude the bugs that have been discovered.
9+
10+
The program includes the suggested changes with each exclusion,
11+
so you can go through FindBugsFilter-auto.xml and decide
12+
to fix things and remove their "Match" nodes.
13+
"""
14+
from xml.dom.minidom import parse
15+
import xml.dom
16+
import os, sys, re, pprint
17+
18+
xml_buglist = 'findbugs.xml' #'D:\\aaa-TIJ4\\code\\findbugs.xml'
19+
text_buglist = 'findbugs.txt' # 'D:\\aaa-TIJ4\\code\\findbugs.txt'
20+
findbugs_filter = 'FindBugsFilter-auto.xml' # 'D:\\aaa-TIJ4\\code\\FindBugsFilter-auto.xml'
21+
22+
def main():
23+
textbugs = [bug.split(':', 1) for bug in file(text_buglist)
24+
if bug.startswith("M ") or bug.startswith("H ")]
25+
textbugs = [(bug[0].split()[2], bug[1].strip()) for bug in textbugs]
26+
dom1 = parse(xml_buglist)
27+
dom2 = xml.dom.getDOMImplementation().createDocument(
28+
None, "FindBugsFilter", None)
29+
bugsDone = []
30+
for bugNode in [bug for bug in dom1.firstChild.childNodes
31+
if bug.nodeName == "BugInstance"]:
32+
for child in bugNode.childNodes:
33+
if child.nodeName == "Class":
34+
classname = child.attributes.item(0).value
35+
bugtype = bugNode.attributes.item(2).value
36+
if (bugtype, classname) in bugsDone:
37+
continue
38+
else:
39+
bugsDone.append((bugtype, classname))
40+
match = dom2.createElement("Match")
41+
match.setAttribute("class", classname)
42+
bugCode = dom2.createElement("BugCode")
43+
bugCode.setAttribute("name", bugtype)
44+
match.appendChild(bugCode)
45+
for textbug in textbugs:
46+
if textbug[0] == bugtype and classname in textbug[1]:
47+
match.appendChild(dom2.createComment(textbug[1]))
48+
dom2.documentElement.appendChild(match)
49+
break # out of inner for loop
50+
file(findbugs_filter, 'w').write(dom2.toprettyxml(' ', '\n'))
51+
52+
if __name__ == "__main__": main()
53+

0 commit comments

Comments
 (0)