Last active
June 28, 2018 09:08
-
-
Save artzmb/26972459cd97373087cedb937da4f631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
public static class Shop { | |
public int id; | |
public String name; | |
public List<Coordinate> coordinates = new ArrayList<>(); | |
@Override | |
public String toString() { | |
String str = id + " (" + name + ") [ "; | |
for (Coordinate coordinate : coordinates) { | |
str += (coordinate.toString() + " "); | |
} | |
str += "]"; | |
return str; | |
} | |
} | |
public static class Coordinate { | |
public String latitude; | |
public String longitude; | |
public Coordinate(String latitude, String longitude) { | |
this.latitude = latitude; | |
this.longitude = longitude; | |
} | |
@Override | |
public String toString() { | |
return "{" + latitude + ", " + longitude + "}"; | |
} | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
String[] cursor1row = {"1", "Foo", "lat1-1", "long1-1"}; | |
String[] cursor2row = {"1", "Foo", "lat1-2", "long1-2"}; | |
String[] cursor3row = {"2", "Bar", "lat2-1", "long2-1"}; | |
String[] cursor4row = {"1", "Foo", "lat1-3", "long1-3"}; | |
String[] cursor5row = {"1", "Foo", "lat1-4", "long1-4"}; | |
String[] cursor6row = {"3", "Ping", "lat3-1", "long3-1"}; | |
String[] cursor7row = {"2", "Bar", "lat2-2", "long2-2"}; | |
List<String[]> cursor = Arrays.asList(cursor1row, cursor2row, cursor3row, cursor4row, cursor5row, cursor6row, cursor7row); | |
Observable.from(cursor) | |
.groupBy(cursorRow -> cursorRow[0]) | |
.flatMap(groups -> groups.collect(Shop::new, (shop, rows) -> { | |
shop.id = Integer.parseInt(rows[0]); | |
shop.name = rows[1]; | |
shop.coordinates.add(new Coordinate(rows[2], rows[3])); | |
})) | |
.subscribe(shop -> Log.d("RX", shop.toString())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment