• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 22684
128
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.

 
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic