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> getJoins(Uri uri) {
        List<String> result = new ArrayList<String>();
        Set<String> queryParameterNames = getQueryParameterNames(uri);
        Iterator<String> iterator = queryParameterNames.iterator();
        while (iterator.hasNext()) {
            String param = iterator.next();
            if (param.startsWith(TABLE)) {
                result.add(uri.getQueryParameter(param));
            }
        }
        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);
    }
}