This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Murach's MySQL and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tree implementation in java

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Team,

I have a json object as below, i have to iterate the object and get the unique list of 'label' {label1, label2} and when i select the label 'label1' i need to get the unique list of 'id' {121, 122} and when i select the id '121' i need to get the unique list of 'ip' from the 'items' and when i select the ip ''xx.xx.xx1' i need to get the unique list of 'descirption'

so when i select label1 -- id: {121, 122} -- and on selecting id - 121 -- i should display list of 'ip' for this combination { 'xx.xx.1', 'xx.xx.xx2', 'xx.xx.8'} and when i select the ip - 'xx.xx.1' i should display the list of 'desc' { 'xxxx', 'yyyy', 'aaaa'}

Let me know how i can implement this in java with high performance and scalability.

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

prabhu pandurangan wrote:Let me know how i can implement this in java with high performance and scalability.


I'm afraid I'm no JSON expert, but one thing I will suggest: Get the implementation right first; then worry about performance and scalability.

However, looking at the structure, It would appear to be a set of Nodes, each of which contains a list of Labels, each of which contains a list of Items, each of which contains a list of IP descriptors. Now you say that each IP might contain a list of descriptions, but I don't see any evidence of that from what you've shown us - on the contrary: each IP would appear to have only ONE description.

So, you would appear to have four types: Node, Label, Item and IP (or IPDescriptor).

I'm afraid I'm not familiar enough with the various brackets ([]) and braces ({}) in JSON to know exactly what they mean though - the braces seem to denote a "list" of some kind, but whether it's a List (java.util.List), a Set (java.util.Set), or a Map (java.util.Map), I simply don't know; and the choice could be important.

Hope it helps (as far as it goes).

Winston

[Edit] One thought occurred to me: Presumably, these JSON objects came from somewhere; why not look at the classes/objects that produced them?
 
Sheriff
Posts: 22778
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:I'm afraid I'm not familiar enough with the various brackets ([]) and braces ({}) in JSON to know exactly what they mean though - the braces seem to denote a "list" of some kind, but whether it's a List (java.util.List), a Set (java.util.Set), or a Map (java.util.Map), I simply don't know; and the choice could be important.


Technically, [] means "array", but in Java code you can use an array or any collection type (at least in most JSON mapping libraries). {} means "object", mostly mapped to a custom object, but you can often also use a Map.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:Technically, [] means "array", but in Java code you can use an array or any collection type (at least in most JSON mapping libraries). {} means "object", mostly mapped to a custom object, but you can often also use a Map.


Oh, OK. Thanks for that.

Winston
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
best way to implement this??
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Best way to implement?
Use a library such as jackson to parse the JSON into java objects.

 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic