• 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Read a txt and make three conected lists

 
Greenhorn
Posts: 7
1
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to read a reviews txt, and make three separate lists with, Reviews, Products, and Users with the respective information of them


Ex of one review :
product/productId: B000140KIW
product/title: Fiskars Softouch Multi-Purpose Scissors 10"
product/price: 3.4
review/userId: ARQAQ6ZYMFPCA
review/profileName: R. GARCIA
review/helpfulness: 0/0
review/score: 5.0
review/time: 1214784000
review/summary: Best scissors ever
review/text: This Fiskars Scissors are the best i've bougth in time. It are excellent for delicated fabrics and silck ribbon embroidery, also work perfectly with paper.



So, as i read, i have to lead, each information, to its respective list, i'm trying to do not repeat Products in the Product list, and for each Product, have the list only of Users take made Reviews for them





I tryed to read them, and add in the respective lists, and erase the repeated products, but i still can't add the Users that made Reviews for them inside the list Product, how can i assure that the only users inside the Product list will be the right ones?
 
Saloon Keeper
Posts: 9955
81
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ricardo Jost wrote:Ex of one review :
product/productId: B000140KIW
product/title: Fiskars Softouch Multi-Purpose Scissors 10"
product/price: 3.4
review/userId: ARQAQ6ZYMFPCA
review/profileName: R. GARCIA
review/helpfulness: 0/0
review/score: 5.0
review/time: 1214784000
review/summary: Best scissors ever
review/text: This Fiskars Scissors are the best i've bougth in time. It are excellent for delicated fabrics...


One thing that is not directly obvious is that a Review has to have a productId field. If you keep a list of Reviews, each review can get to the User record using the userId field in the Review, but a productId is necessary to get to Product record.

Do you have one file for each review? Or does one file contain multiple reviews? If so, what would that file look like?
 
Carey Brown
Saloon Keeper
Posts: 9955
81
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I missed that on line 30 you are passing in references to the Product and User records. I tend to think of accessing a record in a List as being done by some sort of key, such as userId for a User, and productId for a Product. Using a key will work no matter how you decide to handle duplicate entries. The way you have it now, using references, that reference will be broken when you remove duplicates later. If you decide to keep the reference approach you'll have to detect if a list already contains a Product or User prior to adding a new one so that only unique references are added to the Reviews.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If productIds and UserIds are unique (and they should be), you could use a Map instead of a list of Users and Products.

The key would be the IDs of the users and products.
 
Marshal
Posts: 77559
372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Another enhancement I would suggest is to make the Review object immutable and read all the data before instantiating the Review.I would also suggest that your use of substring is brittle and error‑prone. What will happen if a line changes from
price 123.45
to
price: 123.45
or vice versa? You can use String#split and get the text before the / or after the first space, which will probably be more reliable.

And take notice of what CB says; you are using parallel Lists which are also error‑prone. I think you need some way of linking a user, a product and a review. That is actually the sort of thing a datanbse does naturally, but you may not yet know how to link to a database.
 
Ricardo Jost
Greenhorn
Posts: 7
1
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies guys, i'm new here, sorry for the begginer mistakes

Carey

Its a txt with multiple Reviews,all of them have the same format, with different values on the lines, i tryed to attach the file, but i can't upload a .txt or .zip is just .java files?

Here are how that work the list of reviews work:

product/productId: B000GKXY4S
product/title: Crazy Shape Scissor Set
product/price: unknown
review/userId: A1QA985ULVCQOB
review/profileName: Carleen M. Amadio "Lady Dragonfly"
review/helpfulness: 2/2
review/score: 5.0
review/time: 1314057600
review/summary: Fun for adults too!
review/text: I really enjoy these scissors for my inspiration books that I am making (like collage, but in books) and using these different textures these give is just wonderful, makes a great statement with the pictures and sayings. Want more, perfect for any need you have even for gifts as well. Pretty cool!

product/productId: B000GKXY4S
product/title: Crazy Shape Scissor Set
product/price: unknown
review/userId: ALCX2ELNHLQA7
review/profileName: Barbara
review/helpfulness: 0/0
review/score: 5.0
review/time: 1328659200
review/summary: Making the cut!
review/text: Looked all over in art supply and other stores for "crazy cutting" scissors for my 4-year old grandson. These are exactly what I was looking for - fun, very well made, metal rather than plastic blades (so they actually do a good job of cutting paper), safe ("blunt") ends, etc. (These really are for age 4 and up, not younger.) Very high quality. Very pleased with the product.

product/productId: B000140KIW
product/title: Fiskars Softouch Multi-Purpose Scissors 10"
product/price: unknown
review/userId: A2M2M4R1KG5WOL
review/profileName: L. Heminway
review/helpfulness: 1/1
review/score: 5.0
review/time: 1156636800
review/summary: Fiskars Softouch Multi-Purpose Scissors, 10"
review/text: These are the BEST scissors I have ever owned. I am left-handed and take note that either a left or right-handed person can use these equally well.If you have arthritis, as I do, these scissors are amazing as well. Well worth the price. I now own three pairs of these and have convinced many other people in my quilting group that they NEED a pair as well!They cut through muli layers and difficult to cut items really well.Do buy them, you won't regret it!

product/productId: B000140KIW
product/title: Fiskars Softouch Multi-Purpose Scissors 10"
product/price: unknown
review/userId: ARQAQ6ZYMFPCA
review/profileName: R. GARCIA
review/helpfulness: 0/0
review/score: 5.0
review/time: 1214784000
review/summary: Best scissors ever
review/text: This Fiskars Scissors are the best i've bougth in time. It are excellent for delicated fabrics and silck ribbon embroidery, also work perfectly with paper.


Every product have a productId, how would i "connect" the User with the reviews by the userID ?


So, i use a repetition(for), to every time i add, verify if the element already exists at the list right?


=====================================================================================


Knute Snortum


I learned about the HashMap a class ago, still searching about it, it is possible to do it with list for now?

=====================================================================================

Campbell Ritchie

Thanks!

I have to research a little bit more on how to make it immutable and the string split, but i'll definetely take a look at it. I have to do the "link" without a database support, i'll just have the reference inside the lists, ex: having the objects of review inside the list of product, this way product would have productId, title, price and the reviews, but this reference is where i'm a little bit lost i guess
 
Carey Brown
Saloon Keeper
Posts: 9955
81
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Every product have a productId, how would i "connect" the User with the reviews by the userID ?

So, i use a repetition(for), to every time i add, verify if the element already exists at the list right?



Your Review class should have two key fields: userId, and productId. You can then use these keys to find the corresponding User or Product records. Ideally, you should use a Map (as suggested) for tracking User's and Product's using their IDs as the Map key.

Using a List (instead of a Map) you have to loop through the List to find the matching ID.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you're on the right track.

So what do you think your product class would look like if you did that?

Edit: Responding to Carey's comment: "Your Review class should have two key fields: userId, and productId."
Personally I don't think the Review class should have the ids. That's thinking like a database.
Thinking about the actual model, a review doesn't have a userId, it has a User who placed it.

 
Ricardo Jost
Greenhorn
Posts: 7
1
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was given to do the exercise, "helpfunless" was included in "review"

I'll try with hashmap as you guys said, i understood now how they'll conect with each other, but will this assure that a specific product be "linked" only with his respective reviews?
map.png
[Thumbnail for map.png]
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:Edit: Responding to Carey's comment: "Your Review class should have two key fields: userId, and productId."
Personally I don't think the Review class should have the ids. That's thinking like a database.
Thinking about the actual model, a review doesn't have a userId, it has a User who placed it.


Either the IDs or the references to a User and Product. Both will be needed. But I would vote for IDs. To illustrate this, think about finding all the Reviews of a certain Product. Without IDs you would have to create a Product object and implement equals and hash methods. Sounds like a lot of work.

Ricardo Jost wrote:I'll try with hashmap as you guys said, i understood now how they'll conect with each other, but will this assure that a specific product be "linked" only with his respective reviews?


The way to link a Review to a Product is by using an ID or a references to the Product itself. The HashMap just makes it easier to lookup the Product and keep Products unique.
 
Ricardo Jost
Greenhorn
Posts: 7
1
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, i used HashMap as you sugested, using the productId as the key, and added a list of reviews inside the respective product, everything under control now, thanks for the help!
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic