Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2009 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 java.util.HashMap;

public class Main {
    /** A marker that isn't a valid TONE */
    public static final int CDMA_INVALID_TONE = -1;
    static public final int IS95_CONST_IR_SIGNAL_IS54B = 2;
    static public final int TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN = 0;
    static private HashMap<Integer, Integer> mHm = new HashMap<Integer, Integer>();

    public static int getAudioToneFromSignalInfo(int signalType, int alertPitch, int signal) {
        Integer result = mHm.get(signalParamHash(signalType, alertPitch, signal));
        if (result == null) {
            return CDMA_INVALID_TONE;
        }
        return result;
    }

    private static Integer signalParamHash(int signalType, int alertPitch, int signal) {
        if ((signalType < 0) || (signalType > 256) || (alertPitch > 256) || (alertPitch < 0) || (signal > 256)
                || (signal < 0)) {
            return new Integer(CDMA_INVALID_TONE);
        }
        // Based on 3GPP2 C.S0005-E, seciton 3.7.5.5 Signal,
        // the alert pitch field is ignored by the mobile station unless
        // SIGNAL_TYPE is '10',IS-54B Alerting.
        // Set alert pitch to TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN
        // so the alert pitch is not involved in hash calculation
        // when signal type is not IS-54B.
        if (signalType != IS95_CONST_IR_SIGNAL_IS54B) {
            alertPitch = TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN;
        }
        return new Integer(signalType * 256 * 256 + alertPitch * 256 + signal);
    }
}