我有一个方法,通过该方法,我可以按十的倍数过滤行,即我可以按升序过滤最接近十的倍数的行,例如10,20,30等。现在我想按降序执行相同的过程。
请参考以下链接-
Filter array to one row per multiple of ten, based on difference?
在上面提到的链接中,相同的过程是按升序进行的,我想按降序进行,并将值存储在map中。但我无法做到。
我使用下面的代码来检索beam_current是10的倍数的行,顺序是递增的-
public static LinkedHashMap<Double, String> ClosestToMultiplesOfTen_User() throws SQLException {
int row_id ;
int bIdx = 0;
double[] vals = new double[34];
int rowIndex = 0 ;
int i=0;
try
{
con = getConnection();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql="select logtime,beam_current from INDUS2_BDS.dbo.DCCT where logtime between '2014-10-10 08:50:00' and '2014-10-10 12:50:00'"+
"and (beam_current like '%9.96' or beam_current like '%9.97' or beam_current like '%9.98' or beam_current like '%9.99' or beam_current like '%0' or beam_current like '%_0.01' or beam_current like '%_0.02' or beam_current like '%_0.03' or beam_current like '%_0.04' or beam_current like '%_0.05' or beam_current like '%_0.06')";
System.out.println("Value of sql of ClosestToMultiplesOfTen_User is"+sql);
stmt.executeQuery(sql);
rs = stmt.getResultSet();
while(rs.next())
{
for(int j=0; j<1; j++)
{
vals[i] = rs.getDouble(2);
}
i++;
}
}
catch( Exception e )
{
System.out.println("\nException "+e);
}
double max = java.lang.Double.MIN_VALUE;
for (double v : vals) max = Math.max(max, v);
int bucketCount = 1 + (int)(max/10);
double[] bucket =new double[bucketCount];
double[][] buckets = new double[bucketCount][3];
for (int i1 = 0; i1 < bucketCount; i1++){
buckets[i1][0] = java.lang.Double.MAX_VALUE;
buckets[i1][1] = -1d;
buckets[i1][2] = java.lang.Double.MAX_VALUE;
}
for (row_id=1 ; row_id < vals.length; row_id++)
{
double v = vals[row_id];
double mult = getMultipleOfTen(v);
double delta = Math.abs(mult - v);
bIdx = (int)(mult / 10d);
if (buckets[bIdx][0] > delta)
{
buckets[bIdx][0] = delta;
buckets[bIdx][1] = row_id;
buckets[bIdx][2] = v;
}
}
for (int i1 =1; i1 <buckets.length; i1++)
{
bucket = buckets[i1];
rowIndex = (int) bucket[1];
int row_no=rowIndex+1;
double rowValue = bucket[2];
System.out.println("row index "+row_no+ "value is "+rowValue);
DecimalFormat twoDForm = new DecimalFormat("#.##");
rs.absolute(rowIndex);
user_current_map.put(java.lang.Double.valueOf(twoDForm.format(rs.getDouble(2))),(rs.getString(1)));
}
System.out.println("user_current_map "+user_current_map);
return user_current_map;
}
public static double getMultipleOfTen(double v)
{
System.out.println(10d * Math.round(v / 10d));
return 10d * Math.round(v / 10d);
}
现在我只想颠倒顺序,也就是说,现在我想降低射束电流的顺序,即210,22190等。