www.pudn.com > busStop_java_srccode.rar > Query.java
/***********************************************************************
*
*
* 软件:公交路线选择软件
* 作者:李蛟
* 学校:浙江工业大学计本
* 邮箱:joke_leee@163.com
*
* 说明:本软件是用于查询市公交路线选择的软件。
* 本软件在对相应文件进行修改后可用于任何类似各个城市的公交路线等的查询。
* 除了用于商业需经得本人同意外,你可以学习使用甚至修改。
* 第一次发布,难免很多的错误和不足,欢迎有兴趣的朋友批评指正,发现问
* 题请与本人联系,咱们可以交流交流!
*
*
***********************************************************************/
/***********************************************************************
*
*此文件对路线选择的进行全权处理
*包括读入数据(文件),生成数据结构,提供函数用于搜索
*并有一些其他操作,保障安全
*
***********************************************************************/
//package classes;
//import query.*;
//import query.StopFile;
//import query.BusFile;
//import query.GoodLine;
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Query
{
public Query()
{
m_lines=new GoodLine[m_maxline];
m_line=new GoodLine();
for(int i=0;i=0) m_startStop%=m_stopNameLen;
}
public int getStopIDFromName(String name)
{
if(name==null || name.length()==0) return -1;
return m_stopName.indexOf(name)/m_stopNameLen;
}
public int getBusIdFromName(String name)
{
if(name==null || name.length()==0) return -1;
return m_busName.indexOf(name)/m_busNameLen;
}
public int getLineNum() {return m_lineNum;} //返回路径的数量
public void setDepth(short depth){m_routeDepth=depth>GoodLine.maxnum?GoodLine.maxnum:depth;}
//获得下标为i的可行路径
public final GoodLine getGoodLine(int i){if(i=m_stopNum) return null;
return m_stopName.substring(index*m_stopNameLen, (index+1)*m_stopNameLen);
}
public final String getBusName(int index)
{
if(index<0 || index>=m_busNum) return null;
return m_busName.substring(index*m_busNameLen, (index+1)*m_busNameLen);
}
//public short getStopNameLen(){return m_stopNameLen;}
//public short getStopNameLen(){return m_stopNameLen;}
private boolean createNode()
{
if(!(m_busList.readFile()) || !(m_stopList.readFile()))
{
m_stopList.reset();
m_busList.reset();
return false;
}
return true;
}
public boolean createStopAndBus()
{
if(!m_nodeCreaded)
{
m_nodeCreaded=true;
return createNode();
}
return true;
}
/*************************站点名的文件结构****************
*short int busnum //站点数量
*short int namelen //名字的统一长度
*loop{
* short int namelen;
* byte name[]; //Unicode
*}
*************************公交车名的文件结构****************
*short int busnum //公交车数量
*short int namelen //名字的统一长度
*loop{
* byte name[]; //Unicode
*}
* *******************************************************/
public boolean readName()
{
if(m_stopName!=null) return true;
try{
//read stop's name
DataInputStream stopName=new DataInputStream(getClass().getResourceAsStream("stopname.db"));
//DataInputStream stopName=new DataInputStream(new FileInputStream("stopname.db"));
m_stopNum=stopName.readShort();
m_stopNameLen=stopName.readShort();
char [] stopNameChars=new char[m_stopNum*m_stopNameLen];
//stopName.read(m_stopName, 0, m_stopNum*m_stopNameLen);
for(int i=0; i= m_routeDepth) return;
short curBus=0, curStop=0;
for(int busOnStop=0; busOnStop=m_curRouteDepth){}//满了,且不是更好的则舍弃
else//替换掉存在的比目前路线更长的路线
{
int i=0,rnum=0;//找到那条差的
for(int j=0;j-1 && num-1 && num