/**根据传入的时间格式,格式化当前时间*/
public static String getDate(String pattern)
{
SimpleDateFormat sdf=new SimpleDateFormat(pattern);
return sdf.format(new Date(System.currentTimeMillis()));
}
/** Vector1中存储的是多个Vector2,将Vector1中的每个Vector2的仅第x列数据提取出来放在一个Vector中
* 提取后的Vector统一添加到一个Vector3中,返回Vector3 */
public static Vector pickUP_from_Vector(Vector vd,int []x)
{
if (vd == null || vd.size() == 0 ||((Vector)vd.get(0)).size()==0) {
return new Vector();
}
Vector vec=new Vector();
for(int i=0;i<vd.size();i++)
{
Vector v=new Vector();
for(int ii=0;ii<x.length;ii++)
{
v.add(((Vector)vd.get(i)).get(x[ii]));
}
vec.add(v);
}
return vec;
}
/** Vector1中存储的是多个Vector2,将Vector1中的每个Vector2的第x列数据提取出来,放在一个Vector中返回 */
public static Vector changeTo_one_Vector(Vector vd,int x)
{
if (vd == null || vd.size() == 0 ||((Vector)vd.get(0)).size()==0) {
return new Vector();
}
Vector v=new Vector();
if(((Vector)vd.get(0)).size()==0||((Vector)vd.get(0)).size()<x)
{
Vector resu=new Vector();
v.add(resu);
return v;
}
for(int i=0;i<vd.size();i++)
{
v.add(((Vector)vd.get(i)).get(x));
}
return v;
}
/**
* 获得传入的Vector中的最大、最小、均值
* @param fData
* @return
*/
public static String[] getMax_Min_Ave(Vector vd)
{
if (vd == null || vd.size() == 0) {
return new String[]{"","",""};
}
String []result=new String[3];
double temp=Double.parseDouble(vd.get(0).toString());
double []f={temp,temp,temp};
for(int i=1;i<vd.size();i++)
{
temp=Double.parseDouble(vd.get(i).toString());
if(f[0]<temp)
f[0]=temp;
if(f[1]>temp)
f[1]=temp;
f[2]+=temp;
}
result[0]=String.valueOf(changeDec(String.valueOf(f[0]),"#0.00"));
result[1]=String.valueOf(changeDec(String.valueOf(f[1]),"#0.00"));
result[2]=String.valueOf(changeDec(String.valueOf(f[2]/vd.size()),"#0.00"));
return result;
}
/**
* 保留一位小数
*
* @param String sData 要转换的数据
* @param String pattern 要转换的格式:#0.0
* @return
*/
public static double changeDec(String sData,String pattern) {
// 对数据进行处理,保留小数点为1位
DecimalFormat pValueFormat = new DecimalFormat(pattern);
double fDecData=0;
boolean numberFlag = true;
try {
Double.valueOf(sData);
} catch (Exception e) {
numberFlag = false;
}
if (numberFlag == true) {
if (sData.indexOf(".") != -1) {
String number = pValueFormat.format(Double.parseDouble(sData));
fDecData = Double.parseDouble(number);
} else {
fDecData = Double.parseDouble(sData);
}
}
return fDecData;
}
/**
* 将小数点保留为n位
*
* @param boolean team 传入的Vector是否是嵌套的
* @param Vector data 需要转换的数据
* @param String pattern 保留位数的格式化公式:#0.00
* @return Vector
*/
public static Vector changeDec(boolean team,Vector temp,String pattern,int except) {
if (temp == null || temp.size() == 0 ||((Vector)temp.get(0)).size()==0) {
return new Vector();
}
Vector dataVec = new Vector();
if(team)
{
for (int i = 0; i < temp.size(); i++)
{
Vector tempVector = new Vector();
Vector tempVec = (Vector) temp.get(i);
DecimalFormat pValueFormat = new DecimalFormat(pattern);
for(int k=0;k<tempVec.size();k++)
{
if(k==except)
{
tempVector.add(tempVec.get(k));
}
else
{
boolean numberFlag = true;
try {
Double.valueOf(tempVec.get(k).toString());
} catch (Exception e) {
numberFlag = false;
}
if(numberFlag==true){
String number = pValueFormat.format(Double.parseDouble(tempVec
.get(k).toString()));
tempVector.add(number);
}else{
tempVector.add(tempVec.get(k));
}
}
}
dataVec.add(tempVector);
}
}
else
{
for (int i = 0; i < temp.size(); i++) {
DecimalFormat pValueFormat = new DecimalFormat(pattern);
// 2008-05-29
boolean numberFlag = true;
try {
Double.valueOf(temp.get(i).toString());
} catch (Exception e) {
numberFlag = false;
}
if (numberFlag == true) {
String number = pValueFormat.format(Double.parseDouble(temp.get(i).toString()));
dataVec.add(number);
}
else
{
dataVec.add(temp.get(i));
}
}
}
return dataVec;
}