google / guava

Google core libraries for Java
Apache License 2.0
50.19k stars 10.9k forks source link

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

Closed gissuebot closed 10 years ago

gissuebot commented 10 years ago

Original issue created by cemalettin.koc on 2012-12-11 at 09:29 PM


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.

gissuebot commented 10 years ago

Original comment posted by lowasser@google.com on 2012-12-11 at 09:33 PM


What do you mean by "transformation methods"? Is Tables.transformValues not sufficient?

The rest of this is a dup of issue 902.


Status: ``

gissuebot commented 10 years ago

Original comment posted by cemalettin.koc on 2012-12-11 at 09:39 PM


It is just transforming tables to another table and It would be great transforming iterators.

gissuebot commented 10 years ago

Original comment posted by cpovirk@google.com on 2012-12-11 at 09:39 PM


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.

gissuebot commented 10 years ago

Original comment posted by cpovirk@google.com on 2012-12-11 at 09:41 PM


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?

gissuebot commented 10 years ago

Original comment posted by lowasser@google.com on 2012-12-11 at 09:41 PM


@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?

gissuebot commented 10 years ago

Original comment posted by cemalettin.koc on 2012-12-11 at 09:43 PM


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

gissuebot commented 10 years ago

Original comment posted by cpovirk@google.com on 2012-12-11 at 09:48 PM


@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/13825398#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....)

gissuebot commented 10 years ago

Original comment posted by cemalettin.koc on 2012-12-12 at 12:46 PM


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

gissuebot commented 10 years ago

Original comment posted by kevinb@google.com on 2013-04-08 at 07:00 PM


(No comment entered for this change.)


Labels: Package-Collect

gissuebot commented 10 years ago

Original comment posted by kak@google.com on 2013-08-22 at 11:47 PM


(No comment entered for this change.)


Status: Duplicate Merged Into: #902 Labels: Type-Addition

gissuebot commented 10 years ago

Original comment posted by serg.smertin on 2014-09-03 at 05:22 PM


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