POV-Ray : Newsgroups : povray.off-topic : Java Object Collections Server Time
30 Jul 2024 00:31:04 EDT (-0400)
  Java Object Collections (Message 1 to 5 of 5)  
From: Tom Austin
Subject: Java Object Collections
Date: 4 Apr 2011 10:04:44
Message: <4d99cffc$1@news.povray.org>
OK, I'm starting to play with Java and have a couple of questions.

I have several objects that are nested and have collections that I want 
to iterate through

object playground
	collection of ball(s)
	collection of kid(s)
		collection of shoes
	collection of bat(s)

object ball
	object balltype
	object color
object kid
	name
object shoe
	object color
object bat
	length


object color
	colorname
object balltype
	type



I know how to put this together with VB NET using "Inherits CollectionBase".

But how do I go about this with Java?


Thanks,

Tom


Post a reply to this message

From: Darren New
Subject: Re: Java Object Collections
Date: 4 Apr 2011 12:02:39
Message: <4d99eb9f$1@news.povray.org>
On 4/4/2011 7:04, Tom Austin wrote:
> But how do I go about this with Java?

The equivalent abstraction collection in Java is called the Collections 
Framework.

http://download.oracle.com/javase/6/docs/technotes/guides/collections/index.html

I'm not sure what exactly the confusion is?

-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

From: Tom Austin
Subject: Re: Java Object Collections
Date: 5 Apr 2011 12:06:43
Message: <4d9b3e13$1@news.povray.org>
On 4/4/2011 12:02 PM, Darren New wrote:
> On 4/4/2011 7:04, Tom Austin wrote:
>> But how do I go about this with Java?
>
> The equivalent abstraction collection in Java is called the Collections
> Framework.
>
> http://download.oracle.com/javase/6/docs/technotes/guides/collections/index.html
>
>
> I'm not sure what exactly the confusion is?
>


Hi Darren,

Thanks for your reply.

I guess the confusion is that I have not done any programming in Java 
and was trying to explore some ways of doing things.

In the end I am after some good practices that I can follow.  What was a 
good practice in VB is not necessarily good in another language.

Given the example, do you have any suggestions as how they should be stored?

Thanks

Tom


Post a reply to this message

From: Darren New
Subject: Re: Java Object Collections
Date: 5 Apr 2011 13:16:17
Message: <4d9b4e61$1@news.povray.org>
On 4/5/2011 9:06, Tom Austin wrote:
> Given the example, do you have any suggestions as how they should be stored?

The example isn't really detailed enough for me to say.

The Java collection framework gives you a bunch of interfaces for things 
like lists, maps, sets, bags, etc.  It then gives you a bunch of concrete 
implementations like lists-based-on-arrays, maps-based-on-hashtables, 
maps-based-on-trees, etc.

Without knowing how you expect to access the sub-collections, it's hard to 
say whether you have a bag of balls, a list of balls, or a map of balls, for 
example. Are you going to look up balls by name? Do you need to know what 
order they are in?

It looks to me that everything you described as "collection of ..." should 
be a class from the collections framework, and the other stuff should be 
your own classes. In other words, based on what you wrote, I wouldn't expect 
you to declare any class of your own as implementing any of the collection 
interfaces.

class playground {
    public Set<ball> balls;
    public Set<kid> kids;
    public Set<bat> bats;
}
class kid {
    public List<shoe> shoes;
    // shoes[0] is left shoe, shoes[1] is right shoe
}


-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

From: Darren New
Subject: Re: Java Object Collections
Date: 5 Apr 2011 13:16:58
Message: <4d9b4e8a@news.povray.org>
On 4/5/2011 9:06, Tom Austin wrote:
>> http://download.oracle.com/javase/6/docs/technotes/guides/collections/index.html

This is a little more tutorial in nature.

http://download.oracle.com/javase/tutorial/collections/index.html


-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.