Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import android.text.TextUtils;

import java.util.Locale;

public class Main {
    /**
     * Parses a comma separated list of engine locale preferences. The list is
     * of the form {@code "engine_name_1:locale_1,engine_name_2:locale2"} and so
     * on and so forth. Returns null if the list is empty, malformed or if there
     * is no engine specific preference in the list.
     */
    private static Locale parseEngineLocalePrefFromList(String prefValue, String engineName) {
        if (TextUtils.isEmpty(prefValue)) {
            return null;
        }

        final String[] prefValues = prefValue.split(",");
        for (String value : prefValues) {
            final int delimiter = value.indexOf(':');
            if (delimiter > 0) {
                if (engineName.equals(value.substring(0, delimiter))) {
                    return new Locale(value.substring(delimiter + 1));
                }
            }
        }

        return null;
    }
}