345449.vhj5l3oj7.asia
RecycleB.java
2001-12-26T16:00:00Z
2001-12-26T16:00:00Z
<br/><TEXTAREA name="code" class="java" rows="16" cols="100">//: c12:recycleb:RecycleB.java
// Containers that grab objects of interest.
import c12.trash.*;
import java.util.*;
import com.bruceeckel.test.*;
// A container that admits only the right type
// of Trash (established in the constructor):
class Tbin {
private Collection list = new ArrayList();
private Class type;
public Tbin(Class binType) { type = binType; }
public boolean grab(Trash t) {
// Comparing class types:
if(t.getClass().equals(type)) {
list.add(t);
return true; // Object grabbed
}
return false; // Object not grabbed
}
public Iterator iterator() {
return list.iterator();
}
}
class TbinList extends ArrayList {
void sort(Trash t) {
Iterator e = iterator(); // Iterate over self
while(e.hasNext())
if(((Tbin)e.next()).grab(t)) return;
// Need a new Tbin for this type:
add(new Tbin(t.getClass()));
sort(t); // Recursive call
}
}
public class RecycleB extends UnitTest {
Collection bin = new ArrayList();
TbinList trashBins = new TbinList();
public RecycleB() {
ParseTrash.fillBin("../trash/Trash.dat",bin);
}
public void test() {
Iterator it = bin.iterator();
while(it.hasNext())
trashBins.sort((Trash)it.next());
Iterator e = trashBins.iterator();
while(e.hasNext()) {
Tbin b = (Tbin)e.next();
Trash.sumValue(b.iterator());
}
Trash.sumValue(bin.iterator());
}
public static void main(String args[]) {
new RecycleB().test();
}
} ///:~
</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2001-12-26T16:00:00Z
makefile
2001-12-26T16:00:00Z
2001-12-26T16:00:00Z
<br/><TEXTAREA name="code" class="" rows="16" cols="100"># From Thinking in Patterns (with Java) by Bruce Eckel
# At http://www.BruceEckel.com
# (c)2001 Bruce Eckel
# Copyright notice in Copyright.txt
# Automatically-generated MAKEFILE
# For examples in directory .\c12\recycleb
# using the JDK 1.3 compiler
# Invoke with: make
HOME := ../../
ifndef MAKECMDGOALS
MAKECMDGOALS := javac
endif
# Command.com is too weak to build this under Windows NT/2000:
ifeq ($(OS),Windows_NT)
COMSPEC=$(SYSTEMROOT)\system32\cmd.exe
endif
ifneq ($(MAKECMDGOALS),clean)
include $(HOME)/$(MAKECMDGOALS).mac
endif
.SUFFIXES : .class .java
.java.class :
$(JVC) $(JVCFLAGS) $<
javac: \
RecycleB.class
jikes: \
RecycleB.class
clean:
ifeq ($(notdir $(SHELL)),COMMAND.COM)
del *.class
else
rm -f *.class
endif
RecycleB.class: RecycleB.java
$(JVC) $(JVCFLAGS) $<
java com.bruceeckel.test.RunUnitTests RecycleB
</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2001-12-26T16:00:00Z