• Post Reply Bookmark Topic Watch Topic
  • New Topic

Union List  RSS feed

 
nu nin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Morning

I'm new using union list and i will try to explain it the best i can, if there's any question, i'll try to answer it

My question is . What can i do for add all the elements of both list (prom1 & prom2) in a new one (uniEncProm) but that none has to be repeated, in this case the first that was added prom1 and prom2 doesn't repeat elements of prom1. Also what can i do if i want to add another field to uniProm.

Ex.(20, Coca Cola) then add the other field (20, Coca Cola, yes).




Thank you very much.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nu nin wrote:I'm new using union list and i will try to explain it the best i can, if there's any question, i'll try to answer it
My question is . What can i do for add all the elements of both list (prom1 & prom2) in a new one (uniEncProm) but that none has to be repeated, in this case the first that was added prom1 and prom2 doesn't repeat elements of prom1.

Well, first up: "union" is (in Boolean terms) a Set function, not a List one, so you first need to decide how to handle duplicate elements in either List (since List DOES allow them).

If you don't want ANY duplicates, then my suggestion would be to simply load ALL the elements of both Lists into a HashSet and then, if need be, convert it back to a List (and there are several ways of doing that). But, as I say, that might not deliver exactly what you want.

Winston
 
nu nin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
nu nin wrote:I'm new using union list and i will try to explain it the best i can, if there's any question, i'll try to answer it
My question is . What can i do for add all the elements of both list (prom1 & prom2) in a new one (uniEncProm) but that none has to be repeated, in this case the first that was added prom1 and prom2 doesn't repeat elements of prom1.

Well, first up: "union" is (in Boolean terms) a Set function, not a List one, so you first need to decide how to handle duplicate elements in either List (since List DOES allow them).

If you don't want ANY duplicates, then my suggestion would be to simply load ALL the elements of both Lists into a HashSet and then, if need be, convert it back to a List (and there are several ways of doing that). But, as I say, that might not deliver exactly what you want.

Winston


A Map can work, not allowing duplicates.

Do you think if i use Commons from apache can work, if mean for adding other field?

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nu nin wrote:A Map can work, not allowing duplicates.

True, but unless you are mapping each of your elements to a value, then I can see no point in using a Map in preference to a Set.

The problem with Sets (and with Maps) is that they may not preserve the order of the elements in the List. If that is not important then Sets would appear the best solution.
 
nu nin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
nu nin wrote:A Map can work, not allowing duplicates.

True, but unless you are mapping each of your elements to a value, then I can see no point in using a Map in preference to a Set.

The problem with Sets (and with Maps) is that they may not preserve the order of the elements in the List. If that is not important then Sets would appear the best solution.


Well untill now, i don't belive this could be a problem thank you so much.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nu nin wrote:Do you think if i use Commons from apache can work, if mean for adding other field?

Possibly, but it sounds to me like you're jumping to how you're going to do this, instead of describing to us WHAT you want. And that's usually a bad way to go.

Winston
 
Stephan van Hulst
Saloon Keeper
Posts: 7969
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:The problem with Sets (and with Maps) is that they may not preserve the order of the elements in the List.


Except LinkedHashSet and LinkedHashMap
 
nu nin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
nu nin wrote:Do you think if i use Commons from apache can work, if mean for adding other field?

Possibly, but it sounds to me like you're jumping to how you're going to do this, instead of describing to us WHAT you want. And that's usually a bad way to go.

Winston


I want to add another field in the new list uniProm and set yes in case of element is in both lists (prom1 & prom2).

The question is what's the best option i can use?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:
Joanne Neal wrote:The problem with Sets (and with Maps) is that they may not preserve the order of the elements in the List.


Except LinkedHashSet and LinkedHashMap

That's why I said may. I knew somebody would know of ones that did
 
Stephan van Hulst
Saloon Keeper
Posts: 7969
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by adding another field? And if you want to know if a particular element is in both lists, then why not just use the contains() method of these two lists instead of messing with combining the two lists?
 
nu nin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:What do you mean by adding another field? And if you want to know if a particular element is in both lists, then why not just use the contains() method of these two lists instead of messing with combining the two lists?



The reson i'm adding 2 lists is because those results are from a query that brings me results from 2 fields(id, descprition) in both lists. Then i want to compare them & if an element repeats in both lists add other field or just the word yes in case it exist (20, Coca Cola, yes). After all that, what im doing is saving that list to a database, in that database exist those fields (id, descrition, exist).

I don't know what element is because it's a query result and it's suppoused to be automatized.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nu nin wrote:The reson i'm adding 2 lists is because those results are from a query that brings me results from 2 fields(id, descprition) in both lists. Then i want to compare them & if an element repeats in both lists add other field or just the word yes in case it exist (20, Coca Cola, yes). After all that, what im doing is saving that list to a database, in that database exist those fields (id, descrition, exist).

Sounds to me like you're overthinking this.

If it's coming from a database, then you probably only have ONE field to consider: ID; since that's usually the unique key to a table row.

Secondly: if you want to remove duplicates, why not get the database to do it for you? That is, after all, what they're designed for.

However, if you don't like either of those ideas, then I refer you back to my (and Joanne's) previous posts.

Winston
 
nu nin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
nu nin wrote:The reson i'm adding 2 lists is because those results are from a query that brings me results from 2 fields(id, descprition) in both lists. Then i want to compare them & if an element repeats in both lists add other field or just the word yes in case it exist (20, Coca Cola, yes). After all that, what im doing is saving that list to a database, in that database exist those fields (id, descrition, exist).

Sounds to me like you're overthinking this.

If it's coming from a database, then you probably only have ONE field to consider: ID; since that's usually the unique key to a table row.

Secondly: if you want to remove duplicates, why not get the database to do it for you? That is, after all, what they're designed for.

However, if you don't like either of those ideas, then I refer you back to my (and Joanne's) previous posts.

Winston


Issue is Requirment, i have to addapt to the exsisting app & this app did it previously with a database(incluying process), but it needs to be modified to lists then when all process is done copy only results to database. It's faster than doing everything in database.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nu nin wrote:Issue is Requirment,

??? Sorry, I don't understand that.

i have to addapt to the exsisting app & this app did it previously with a database(incluying process), but it needs to be modified to lists then when all process is done copy only results to database. It's faster than doing everything in database.

Is it? Says who? I was a db administrator for nearly 20 years and I've rarely found situations when a database wasn't the FASTEST way to deal with large volumes of data, particularly when Boolean operations are concerned.

Sounds to me like someone's not only telling you what to do, but how to do it; and that's a recipe for disaster. Too many cooks.

Who's the programmer here? You.

So, if somebody wants you to simply be a parrot, get them to write down every step of this process and do exactly what they tell you to; otherwise tell them to leave you alone to do what they pay you for.

Winston
 
nu nin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
nu nin wrote:Issue is Requirment,

??? Sorry, I don't understand that.

i have to addapt to the exsisting app & this app did it previously with a database(incluying process), but it needs to be modified to lists then when all process is done copy only results to database. It's faster than doing everything in database.

Is it? Says who? I was a db administrator for nearly 20 years and I've rarely found situations when a database wasn't the FASTEST way to deal with large volumes of data, particularly when Boolean operations are concerned.

Sounds to me like someone's not only telling you what to do, but how to do it; and that's a recipe for disaster. Too many cooks.

Who's the programmer here? You.

So, if somebody wants you to simply be a parrot, get them to write down every step of this process and do exactly what they tell you to; otherwise tell them to leave you alone to do what they pay you for.

Winston



jijij thank you for your advice winston in a good way and well about database is in a server where it recive a BIG AMOUNT of info in a certain period of the day and when the app is going to be use it's peek hour and it takes at least 1 hour picking the needed info.... and app is a disaster........
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nu nin wrote:jijij thank you for your advice winston in a good way and well about database is in a server where it recive a BIG AMOUNT of info in a certain period of the day and when the app is going to be use it's peek hour and it takes at least 1 hour picking the needed info.... and app is a disaster........

Possibly because too many "cooks" (or "chefs") have been involved already. And you're most welcome.

Believe me, my insight only comes after 35 years in the biz, and several situations like yours; and it's not easy to combat if you're perceived as a "junior".

However, after a few cases when I was told to "follow orders", and they failed, I got into the habit of getting my bosses to write those orders down.

Programming - and especially Java programming - is about WhatNotHow (←click).
And the sooner that bosses understand that they have someone with a BRAIN (I can't imagine that you could get through 3 or 4 years of uni without one), they may understand that they need to trust you to come up with the HOW - because ... er ... that's your job.

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!