Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.net.Uri;
import java.util.*;

public class Main {
    public static final String TABLE = "table";

    public static List<String> getAllTables(Uri uri) {
        List<String> result = new ArrayList<String>();

        String mainTable = uri.getLastPathSegment();
        result.add(mainTable);

        Set<String> queryParameterNames = getQueryParameterNames(uri);
        Iterator<String> iterator = queryParameterNames.iterator();
        while (iterator.hasNext()) {
            String table = iterator.next();
            if (table.startsWith(TABLE)) {
                result.add(table.replaceFirst(TABLE, ""));
            }
        }
        return result;
    }

    public static Set<String> getQueryParameterNames(Uri uri) {
        String query = uri.getEncodedQuery();
        if (query == null) {
            return Collections.emptySet();
        }

        Set<String> names = new LinkedHashSet<String>();
        int start = 0;
        do {
            int next = query.indexOf('&', start);
            int end = (next == -1) ? query.length() : next;

            int separator = query.indexOf('=', start);
            if (separator > end || separator == -1) {
                separator = end;
            }

            String name = query.substring(start, separator);
            names.add(uri.decode(name));

            // Move start to end of name.
            start = end + 1;
        } while (start < query.length());

        return Collections.unmodifiableSet(names);
    }
}