• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

array of sub Sets from parent Set ?

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
name, age and qualification are the columns in the database. I accessed whole data from the database and put in the Set(java.util.Set). Now i want to form array of Sets based on qualification value(qualification is the key for forming array of Sets).
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kri shan wrote:name, age and qualification are the columns in the database. I accessed whole data from the database and put in the Set(java.util.Set).



But how can you insert three values into a set?? Do you have a POJO class like User which you insert into the set?? I also didn't get the actual question that you asked...
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you inserting data into the set? Is it a tuple.. I mean as some class objects?
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, POJO class like User which inserts data into the set
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two different types of sub sets.

The first is the snapshot (pseudo code):


The second is much harder, and is a view on the original set. If the original set changes, the view changes as well. This is what SortedSet.subSet, SortedSet.headSet and SortedSet.tailSet are required to return. You can check TreeSet (and effectively TreeMap) of how this can be implemented.
AbstractList.subList also does something similar.
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob,

based on your first soultion:
I want to create array of subSets based on Qualification values. Because i do not know how many different qulification type values are in the database.


 
Rob Spoor
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would go for a Map<Qualification,Set<MyType>>, combined with a method that returns a Set<MyType> given a Set<MyType> and Qualification. (This method can be private, or an instance method on Qualification, or whatever you choose.)

You can store the entire set with a null key, or of course as a separate field. For all qualifications, you can retrieve them from the map as follows:

This is a lazy initialization implementation; if you never need a sub set for a qualification, you simply never initialize it. If you do, you only initialize it once and cache it afterwards.

Note that I made an abstraction of your qualification; perhaps in your code it will be a simple String, or an int / long (in which case you use Integer / Long as key type). The important thing is, that this code should work regardless of your representation choice.
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob, sbSet = getSubSet(allTypes, qualification); here getSubSet() is taking two arguments allTypes and qualification. Is it separate function ?
 
Rob Spoor
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is. It is the method that actually does the filtering (e.g. like my previous post). But like I said, it could be a method of class Qualification, in which case the call would be qualification.getSubSet(allTypes).
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic