⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 airportcode.java

📁 这是一个手机上的J2ME程序
💻 JAVA
字号:
// J2ME Compass
// Copyright (C) 2007 Dana Peters
// http://www.qcontinuum.org/compass

package org.qcontinuum.compass;

import java.io.*;
import java.util.Vector;
import org.qcontinuum.astro.EarthPosition;

// Each entry in the GlobalAirportDatabase is 7 bytes long.
// Fields are packed into the available bits as follows:
//
// | Byte 0 | Byte 1 | Byte 2 | Byte 3 | Byte 4 | Byte 5 | Byte 6 |
// |AAAAABBB|BBCCCCCD|DDDDEEEE|EFFFFFGG|GGGLLLLL|LLLLLMMM|MMMMMMMM|
//
// The fields are indicated by the following letter codes:
// Airport Code4=(ABCD) Airport Code3=(EFG) Latitude=(L) Longitude=(M)

public class AirportCode {

    public static Object find(Object obj, String airport) {

        boolean code4;
        int i, match = 0;
        switch (airport.length()) {
            case 3:
                code4 = false;
                break;
            case 4:
                code4 = true;
                break;
            default:
                return null;
        }
        for (i = 0; i < airport.length(); i++)
            match = match << 5 | ((airport.charAt(i) - 64) & 0x1f);
        InputStream inputStream = obj.getClass().getResourceAsStream("AirportCode.dat");
        DataInputStream dataInputStream = new DataInputStream(inputStream);
        byte[] data = new byte[7];
        int code;
        EarthPosition earthPosition = null;
        Vector airportVector = new Vector();
        try
        {
            while (true)
            {
                dataInputStream.readFully(data);
                if (code4)
                    code = ((data[0] << 12) & 0xff000) | ((data[1] << 4) & 0xff0) | ((data[2] >> 4) & 0xf);
                else
                    code = ((data[2] << 11) & 0x7800) | ((data[3] << 3) & 0x7f8) | ((data[4] >> 5) & 0x7);
                if (code == match) {
                    earthPosition = new EarthPosition(
                        (((data[4] << 5) & 0x3e0) | ((data[5] >> 3) & 0x1f)) * 15 - 90 * 60,
                        (((data[5] << 8) & 0x700) | ((data[6] << 0) & 0xff)) * 15 - 180 * 60);
                    if (code4)
                        return earthPosition;
                    else {
                        char airportCode[] = new char[4];
                        airportCode[0] = (char)(((data[0] >> 3) & 0x1f) + 64);
                        airportCode[1] = (char)((((data[0] << 2) & 0x1c) | ((data[1] >> 6) & 0x03)) + 64);
                        airportCode[2] = (char)(((data[1] >> 1) & 0x1f) + 64);
                        airportCode[3] = (char)((((data[1] << 4) & 0x10) | ((data[2] >> 4) & 0x0f)) + 64);
                        airportVector.addElement(new String(airportCode));
                    }
                }
            }
        }
        catch (Exception exception) { }
        finally
        {
            try
            {
                dataInputStream.close();
            }
            catch (Exception exception) { }
        }
        if (airportVector.size() > 1) {
            String[] airports = new String[airportVector.size()];
            airportVector.copyInto(airports);
            return airports;
        } else
            return earthPosition;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -