tailorlala / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Initial value enhancement for Table (or a MultiTable?) #1227

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am trying to port existence code to Guava. I am not considering myself a 
Guava expert but what I need is simply iterating over existence collection and 
constructing a table.

My preliminary implemention is as follows: 

  Table<Integer, Integer, Set> setPerUser = HashBasedTable.create();

  for(Conversation conversation : conversations) {
     Set uci = setPerUser.get(conversation.x, conversation.y);
     if(uci == null) {
        uci = new HashSet();
        setPerUser.put(conversation.x, conversation.y, uci);
     }
     uci.add(conversation.id);
  }

Since the inner if insider for loop seems little problematic, I am feeling that 
I am in wrong direction.

Sean from Stackoverflow suggested such a more generic solution as this:

public static <X, Y, Z, S extends Collection<Z>> void addCellValue(
    Table<X, Y, S> table, X rowKey, Y colKey, Z value, Supplier<S> supplier) {

    final S data;
    if (table.contains(rowKey, colKey)) {
        data = table.get(rowKey, colKey);
    } else {
        data = supplier.get();
        table.put(rowKey, colKey, data);
    }
    data.add(value);

}

Honestly I am not satisfied. What I was considering is something similar to 
MultiMap, namely MultiTable which is creating necessary in case a need.

Another solution would be using an initial value by Supplier but this is not 
consistent with the other part of the library.

And last, It would be great to have transformation methods for Table too. 

Original issue reported on code.google.com by cemalettin.koc@gmail.com on 11 Dec 2012 at 9:29

GoogleCodeExporter commented 9 years ago
What do you mean by "transformation methods"?  Is Tables.transformValues not 
sufficient?

The rest of this is a dup of issue 902.

Original comment by lowas...@google.com on 11 Dec 2012 at 9:33

GoogleCodeExporter commented 9 years ago
It is just transforming tables to another table and It would be great 
transforming iterators. 

Original comment by cemalettin.koc@gmail.com on 11 Dec 2012 at 9:39

GoogleCodeExporter commented 9 years ago
> The rest of this is a dup of issue 902.

Well, yes and no. They're attempting to solve the same basic problem, but one 
is significantly more heavyweight than the other.

Original comment by cpov...@google.com on 11 Dec 2012 at 9:39

GoogleCodeExporter commented 9 years ago
> It is just transforming tables to another table and It would be great
> transforming iterators.

We use "transform" to mean something fairly specific in Guava terms. Can you 
give us some idea of what the signature of your proposed method (or multiple 
methods, since you mention both Table and Iterator) would be?

Original comment by cpov...@google.com on 11 Dec 2012 at 9:41

GoogleCodeExporter commented 9 years ago
@cpovirk:  I don't follow.  Both are asking for a Multitable type.

@cemalettin.koc: it's not clear what you mean by "transforming iterators" that 
isn't provided by e.g. Iterators.transfomr.  Could you give a concrete example 
of what you'd want?

Original comment by lowas...@google.com on 11 Dec 2012 at 9:41

GoogleCodeExporter commented 9 years ago
Ok I was expecting this question, let met to think about it. I will try to 
provide a signature for it.

Original comment by cemalettin.koc@gmail.com on 11 Dec 2012 at 9:43

GoogleCodeExporter commented 9 years ago
> @cpovirk:  I don't follow.  Both are asking for a Multitable type.

Sorry, I didn't read carefully. The request I thought he was filing was the one 
I suggested here:
http://stackoverflow.com/questions/13822800/inital-value-for-guava-table/1382539
8#comment19024624_13822967

That suggestion was for Tables.getOrCreate(Table, R, C, Supplier) to match the 
forthcoming Maps method. (Actually, I guess that even *that* isn't quite what I 
asked for, since I didn't read carefully enough there, either....)

Original comment by cpov...@google.com on 11 Dec 2012 at 9:48

GoogleCodeExporter commented 9 years ago
Ok, I can not provide a concrete signature. If I come up with a concrete 
solution, I will provide here.

Just a minor addition, maybe it is not related to here but I have asked another 
question which was my original intention. But because of not providing some 
semantic details, I could not be clear about my intention.

http://stackoverflow.com/questions/13835685/guava-table-alternative

It seems this issue is a duplicate. It can be closed. 

Thanks

Original comment by cemalettin.koc@gmail.com on 12 Dec 2012 at 12:46

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 8 Apr 2013 at 7:00

GoogleCodeExporter commented 9 years ago

Original comment by kak@google.com on 22 Aug 2013 at 11:47

GoogleCodeExporter commented 9 years ago
I have another use case for MultiTable: verification of multiple queues header 
values that are coming in random order. 

Original comment by serg.sme...@gmail.com on 3 Sep 2014 at 5:22

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08