src/main/java/de/blau/android/osm/StorageDelegator.java
/**
     * Build groups of ways that have common nodes
     * 
     * There must be a better way to do this, but they likely all fall afoul of our current data model
     * 
     * @param ways the ways to group
     * @return a list of list of ways with common nodes
     */
Build groups of ways that have common nodes

There must be a better way to do this, but they likely all fall afoul of our current data model

@param ways the ways to group
@return a list of list of ways with common nodes
Build groups of ways that have common nodes There must be a better way to do this but they likely all fall afoul of our current data model @param ways the ways to group @return a list of list of ways with common nodes
@NonNull
    private List<List<Way>> groupWays(@NonNull List<Way> ways) {
        List<List<Way>> groups = new ArrayList<>();
        int group = 0;
        int index = 0;
        int groupIndex = 1;
        groups.add(new ArrayList<>());
        Way startWay = ways.get(index);
        groups.get(group).add(startWay);
        do {
            do {
                for (Node nd : startWay.getNodes()) {
                    for (Way w : ways) {
                        if (w.getNodes().contains(nd) && !groups.get(group).contains(w)) {
                            groups.get(group).add(w);
                        }
                    }
                }
                if (groupIndex < groups.get(group).size()) {
                    startWay = groups.get(group).get(groupIndex);
                    groupIndex++;
                }
            } while (groupIndex < groups.get(group).size());
            for (; index < ways.size(); index++) {
                Way w = ways.get(index);
                boolean found = false;
                for (List<Way> list : groups) {
                    found = found || list.contains(w);
                }
                if (!found) {
                    group++;
                    groups.add(new ArrayList<>());
                    startWay = w;
                    groupIndex = 1;
                    break;
                }
            }
        } while (index < ways.size());
        Log.d(DEBUG_TAG, "number of groups found " + groups.size());
        return groups;
    }
@ NonNull private List < List < Way > > groupWays ( @ NonNull List < Way > ways ) { List < List < Way > > groups = new ArrayList < > ( ) ; int group = 0 ; int index = 0 ; int groupIndex = 1 ; groups . add ( new ArrayList < > ( ) ) ; Way startWay = ways . get ( index ) ; groups . get ( group ) . add ( startWay ) ; do { do { for ( Node nd : startWay . getNodes ( ) ) { for ( Way w : ways ) { if ( w . getNodes ( ) . contains ( nd ) && ! groups . get ( group ) . contains ( w ) ) { groups . get ( group ) . add ( w ) ; } } } if ( groupIndex < groups . get ( group ) . size ( ) ) { startWay = groups . get ( group ) . get ( groupIndex ) ; groupIndex ++ ; } } while ( groupIndex < groups . get ( group ) . size ( ) ) ; for ( ; index < ways . size ( ) ; index ++ ) { Way w = ways . get ( index ) ; boolean found = false ; for ( List < Way > list : groups ) { found = found || list . contains ( w ) ; } if ( ! found ) { group ++ ; groups . add ( new ArrayList < > ( ) ) ; startWay = w ; groupIndex = 1 ; break ; } } } while ( index < ways . size ( ) ) ; Log . d ( DEBUG_TAG , "number of groups found " + groups . size ( ) ) ; return groups ; }
Build groups of ways that have common nodes
Build groups of ways that have common nodes
// repeat until no new ways are added in the loop // find the next way that is not in a group and start a new one