Чтобы настроить набор результатов на основе другого набора результатов в Java [закрыто]

я имеючетыре методадва метода, а именноFindClosestToMultiplesOfTen () и ClosestToMultiplesOfTen_User () выдает значения beam_current, соответствующие введенному времени журнала через пользователя.Два других метода извлекают все остальные поля из этих beam_current. Я рассматриваю beam_current, извлеченный из FindClosestToMultiplesOfTen, как эталонный beam_current, и они передаются в другой метод, а именно метод refernece (), и извлекаются другие соответствующие им значения. Подобные вещи делаются с двумя другими методами, а именно ClosestToMultiplesOfTen_User и значения beam_current из него передаются в refarray_vac1. Теперь я вычисляю разницу значений, полученных из обоих этих методов, и отображаю их через jsp apge.

Проблема- 1)Я хочу, чтобы все значения, соответствующие beam_current, полученные из метода refarray_vac1 (), приходили непосредственно под соответствующими значениям refernece (). Выход, полученный до сих пор,

Здесь вы можете видеть строки, отображаемые светлым цветом из refarray_vac1, и они сравниваются со строками, представленными серым цветом. Здесь значение около 10 представлено ниже ссылочной строки 10, но я хочу, чтобы оно было представлено ниже 20.02 строки ссылки, а нулевое значение должно быть представлено ниже серого цвета 10 строки, так как в светлом цвете 10 значение отсутствует. Затем все строки появятся ниже соответствующих строк.

Код методов

public  LinkedHashMap<Double, String> FindClosestToMultiplesOfTen(String name) throws SQLException {

    int row_id ;
    int bIdx = 0;
    //double[] vals = new double[47];
    double[] vals=null;
    //double[] bucket =new double[22];
    int rowIndex = 0 ;
    int i=0;
    String first=name.substring(1,19);
    String last =name.substring(24,42);
     try
        { 
          con = getConnection();
          stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
          String sql="select distinct beam_current from INDUS2_BDS.dbo.DCCT where logtime between '"+first+"' and '"+last+"'"+
          "and (beam_current like '%9.95' or 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 FindClosestToMultiplesOfTen is"+sql);
          stmt.executeQuery(sql);
          rs = stmt.getResultSet();

         rs.last();
            int row_cnt=rs.getRow();
            System.out.println("row_count of closest " +row_cnt);
             vals = new double[row_cnt];
            rs.beforeFirst();
while(rs.next()) 
    {
   for(int j=0; j<1; j++)
         {
           vals[i]  = rs.getDouble(1);
         }
        i++;
     }
    }
 catch( Exception e )
    {
        System.out.println("\nException "+e);
    }
   //  get the max value, and its multiple of ten to get the number of buckets
     double max = java.lang.Double.MIN_VALUE;

     for (double v : vals) 
        {
        System.out.println("value of v after double v : vals"+v);
        max = Math.max(max, v);
        }
     Arrays.sort(vals);
     System.out.println("Min value in array in c "+vals[0]);
     double min=vals[0];
     int m2=(int) Math.round(min);
     int m3=(int) Math.round(max);

     int bucketCount = 1+((m3-m2)/10);
     double[] bucket =new double[bucketCount];

     //  initialise the buckets array to store the closest values
    double[][] buckets = new double[bucketCount][3];
    for (int i1 = 0; i1 < bucketCount; i1++){
         // store the current smallest delta in the first element
         buckets[i1][0] = java.lang.Double.MAX_VALUE; 
         // store the current "closest" index in the second element
         buckets[i1][1] = -1d;
         // store the current "closest" value in the third element
         buckets[i1][2] = java.lang.Double.MAX_VALUE;
     }


     //  iterate the rows
     for (row_id=0 ; row_id < vals.length; row_id++) // row_id=137
     {
         //  get the value from the row
         double v = vals[row_id];

         //  get the closest multiple of ten to v
         double mult = getMultipleOfTen(v); // e.g. 50, 60, etc

         //  get the absolute distance of v from the multiple of ten
         double delta = Math.abs(mult - v); // 50 - 49.9 = 0.1
         //  get the bucket index based on the value of `mult`
        bIdx = (int)(mult / 10d) - m2/10;//50/10=5

      if (buckets[bIdx][0] > delta) // max>0.1
         {

           buckets[bIdx][0] = delta;//.01(50-49.95)
           buckets[bIdx][1] = row_id;
            buckets[bIdx][2] = v;


            System.out.println("beam_current: "+buckets[bIdx][2]);
            //z++;

         }
      } 

     System.out.format("    10x row value%n");
    for (int i1 =0; 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+1);
       map1.put(java.lang.Double.valueOf(twoDForm.format(rs.getDouble(1))),"");

         }

    return map1;
    }

В обоих методах FindClosestToMultiplesOfTen () и ClosestToMultiplesOfTen_User () есть разница только в размере набора результатов, так как время журналов обоих типов различается. Теперь я хочу, чтобы размер набора ClosestToMultiplesOfTen_User () был равен размеру результата FindSultiplesOf везде, где нет соответствующего значения в результате ClosestToMultiplesOfTen_User, который получается после обработки.

код для ClosestToMultiplesOfTen_User is-

public  LinkedHashMap<Double, String> ClosestToMultiplesOfTen_User(String start,String end) throws SQLException {

int row_id ;
int bIdx = 0;
double[] vals=null;
int rowIndex = 0 ;
int i=0;

try
        { 
          con = getConnection();
          stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);

          String sql="select distinct beam_current from INDUS2_BDS.dbo.DCCT where logtime between '"+start+"' and '"+end+"'"+
                  "and (beam_current like '%9.95' or 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 FindClosestToMultiplesOfTen is"+sql);
          stmt.executeQuery(sql);
          rs = stmt.getResultSet();

         rs.last();
            int row_cnt=rs.getRow();
            System.out.println("row_count of closest " +row_cnt);
             vals = new double[row_cnt];
            rs.beforeFirst();
while(rs.next()) 
    {
   for(int j=0; j<1; j++)
         {
           vals[i]  = rs.getDouble(1);
         }
        i++;
     }
    }
 catch( Exception e )
    {
        System.out.println("\nException "+e);
    }
 //  get the max value, and its multiple of ten to get the number of buckets
 double max = java.lang.Double.MIN_VALUE;
 for (double v : vals) max = Math.max(max, v);
Arrays.sort(vals);
System.out.println("value at vals[0] c "+vals[0]);
double min=vals[0];
int m2=(int) Math.round(min);
int m3=(int) Math.round(max);


int bucketCount = 1+((m3-m2)/10);
double[] bucket =new double[bucketCount];



 System.out.println("bucketcount in closest "+bucketCount);

 //  initialise the buckets array to store the closest values
double[][] buckets = new double[bucketCount][3];
for (int i1 = 0; i1 < bucketCount; i1++){
     // store the current smallest delta in the first element
     buckets[i1][0] = java.lang.Double.MAX_VALUE;
     // store the current "closest" index in the second element
     buckets[i1][1] = -1d;
     // store the current "closest" value in the third element
     buckets[i1][2] = java.lang.Double.MAX_VALUE;
 }

 //  iterate the rows
 for (row_id=0 ; row_id < vals.length; row_id++)
 {
     //  get the value from the row
     double v = vals[row_id];
     System.out.println("value at "+row_id+": "+v);
     //  get the closest multiple of ten to v
     double mult = getMultipleOfTen(v);
     //  get the absolute distance of v from the multiple of ten
     double delta = Math.abs(mult - v);
     //  get the bucket index based on the value of `mult`
     bIdx = (int)(mult / 10d) - m2/10;


    if (buckets[bIdx][0]  > delta)
     {
      //  this is closer than the last known "smallest delta"
       buckets[bIdx][0] = delta;
       buckets[bIdx][1] = row_id;
       buckets[bIdx][2] = v;

       System.out.println("beam_current closeset: "+buckets[bIdx][2]);

     }
  }  
//   print out the result
for (int i1 =0; i1 < buckets.length; i1++)
{
      bucket = buckets[i1];
     rowIndex = (int) bucket[1];
 double rowValue = bucket[2];
      //System.out.println("row index "+row_no+ "value is "+rowValue);
      DecimalFormat twoDForm = new DecimalFormat("#.##"); 
      System.out.println("row index closeset "+rowIndex+ "value is closest "+rowValue);
   //System.out.println("value of rowIndex+1 is"+row_no);
      rs.absolute(rowIndex+1);
      user_current_map.put(java.lang.Double.valueOf(twoDForm.format(rs.getDouble(1))),"");
     // map1.put(rs.getString(2),(rs.getString(1)));
      //l.add(map1);
     }
System.out.println("user_current_map "+user_current_map);

return user_current_map;
}

код для refarray_vac1 ()

public  List<Vacc1_Decline> refarray_vac1(String fdate,String ldate) throws SQLException, ParseException {

        st_jsp.clear();
    //System.out.println("date from jsp is : "+date);
     List<Double> slist_user = new ArrayList<Double>(user_current_map.keySet());
      String s_user = StringUtils.join(slist_user, ',');
System.out.println("comma separated string by user_selection" +s_user);
    //  int i=0;
       try
            {  
              con = getConnection();
              stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);



                     String vs1= " sql query";

        //      System.out.println("value from user_selection is " +vs1);
              stmt.executeQuery(vs1);
               rs = stmt.getResultSet();

               while (rs.next()) {
                   Vacc1_Decline ref = new Vacc1_Decline();

                      ref.setLogtime(rs.getString(1));

                         ref.setBeam_current(rs.getString(2));

                          ref.setBeam_energy(rs.getString(3));

                      ref.setSt1_vs1_bag1_rb(rs.getString(4));

                      ref.setSt1_vs1_bag2_rb(rs.getString(5));

                  st_jsp.add(ref);

                }

            }
       catch( Exception e )
                {
                    System.out.println("\nException in refarray_vac1 "+e);
                }


       return st_jsp;
      }

Ответы на вопрос(0)

Ваш ответ на вопрос