1

I have a collection, I want to split it by a predicate, the predicate is on the resulting collection.

I want to split this list by strings with common letter.

"Inky", "Blinky", "Pinky", "Pinky", "Clyde"

will result in:

  • Inky,Blinky,Pinky - same inky
  • Blinky,Clyde - same l

better yet, the result will be map: - 1=Blinky,Clyde - 4=Inky,Blinky,Pinky

on the number of common letters.

The predicate for giving the common letters is easy and I have it. the problem is creating the new collection.

I guess I was unclear, I want to divide the collection to equivalence classes, based on the predicate. the strings were an example. a poor one I guess. in every equivalence class there will be objects that answer: (a,b) such that f(a,b) < X. in my problem the X represents the distance between a,b and I want to divide the graph by nearby vertices.

Jeffrey Bosboom
  • 13,313
  • 16
  • 79
  • 92
Zamir
  • 1,492
  • 1
  • 12
  • 20
  • 2
    [What have you tried?](http://whathaveyoutried.com) Also, whatever this predicate implementation you have in mind, it is not at all obvious/clear. – Matt Ball May 08 '12 at 10:59
  • 1
    Possible duplicate of http://stackoverflow.com/questions/122105/java-what-is-the-best-way-to-filter-a-collection – Christian Garbin May 08 '12 at 10:59
  • Could you show the way that you call your predicate, and what it returns? The implementation of the predicate itself is less important. – Sergey Kalinichenko May 08 '12 at 11:00
  • 1
    I don't think you defined the map result of your function properly since you don't want all words that share some (any) letter with another word to be together. So the map key should be the exact string they share. Good luck, I find this an interesting and tough problem. – Marko Topolnik May 08 '12 at 11:14
  • You should improve the title to better indicate the kind of problem you are looking to solve. I can do it for you. – Marko Topolnik May 08 '12 at 11:17
  • Is there a unique partitioning in all cases? It seems to me there is not. Therefore you must specify an additional rule for breaking ties. – Raedwald Jun 21 '14 at 21:37

0 Answers0