Gareth Lloyd

Greenhorn
+ Follow
since Jun 25, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gareth Lloyd

So there are limits on your assignment so you can't use any libraries?

If so, what have you decided to do about html that is not well-formed? If you can treat the input like xhtml, and the document hasn't followed the rules of well-formedness, the right thing to do is to throw an exception and stop parsing.

If this is acceptable to you, it makes the job a great deal easier because you don't have to handle 101 different ways that html can be badly written, and you can basically write something like the SAXParser (or maybe even use that if it's allowed).

Give us a bit more detail about your assignment.
14 years ago
Are you trying to convert binary to decimal?
14 years ago
Hey, I think you need to use readInt() rather than read()

Take a look at the JavaDoc for DataInputStream's various methods:

http://java.sun.com/j2se/1.5.0/docs/api/java/io/DataInputStream.html
14 years ago
I'm afraid I don't follow completely.

Could you provide a little more detail on how the map might solve the problem? Would you store the Updates or various collections of updates in the map?

In your second solution, would you iterate over all Updates to do the select? How would you pick out the specific subtypes of Update that actually could perform the behaviour we want? I don't like using 'instanceof()', and I'm not sure if that's what you're suggesting.

I appreciate the help!
14 years ago
Hey everyone. This seems like a great forum. I'm looking forward to getting involved.

Now, this is the problem that brought me here via Google: My app is recording updates from web services. Updates can be of various types.

I want to find a nice way of storing all these updates so that, at any time, I can iterate over the entire set (treating different types polymorphically), or just over one specific subtype of event. For example, I might want to look through everything that's come in and throw away old updates. Or I might want to look through just the updates of type MessageUpdate and read the messages (or some other behaviour provided by the subclass).

So lots of questions then come up. I'm thinking of an abstract class 'Update' with a basic implementation, extended by various concrete <specificTypeOf>Update -type classes. Is this the right way to handle the polymorphism?

Then I'm thinking I should create a class to contain a bunch of separate collections. The two obvious problems here are that adding a new subtype of Update requires me to add code to that class: a new individual collection type, AND new code to iterate over that collection along with all the others.

The second problem might be mitigated if I created a "collection of collections" and just iterated over all of them. I have provided some basic example code:



Well, this strikes me as a bit wrong, somehow, and I have been looking for ways to apply various design patterns to smarten the design up a bit.

This one looked promising: http://en.wikipedia.org/wiki/Composite_pattern

But Composite seems to be most suited for an arbitrarily deep tree of similar items, and so it doesn't map neatly onto a problem. I think the nature of my problem is a shallow tree, with several different types of things in the tree.

Anyway, is all this making sense?

Does anyone have any suggestions for ways to refactor this code?

Thanks in advance!!
14 years ago