日期:2014-05-20 浏览次数:20806 次
package com.tur.demo;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class Route {
public static List<String> paths = new ArrayList<String>();
/**
* 查找元素在数组中的下标,如果找不到,返回-1
* @param array
* @param number
* @param startIndex
* @return
*/
public static int indexInArray(int[] array, int number, int startIndex) {
for (int i = startIndex; i < array.length; ++i) {
if (array[i] == number) {
return i;
}
}
return -1;
}
/**
* 把List使用String形式表示
* @param list
* @param delimeter
* @return
*/
public static String listToString(List<Integer> list, String delimeter) {
StringBuilder sb = new StringBuilder();
for (int n : list) {
sb.append(delimeter);
sb.append(n);
}
return (sb.length() > 0 ? sb.substring(delimeter.length()) : "");
}
/**
* 把路径加到入路径列表,并去掉重复的路径
* @param path
*/
public static void addPath(String path) {
boolean included = false;
for (int i = 0; i < paths.size(); ++i) {
String str = paths.get(i);
if (path.contains(str)) {
paths.set(i, path);