본문 바로가기

rowspan 계산.

java by 낼스 2015. 8. 18.

package test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.BeanUtils;
public class TestRowspan {
       public static void load( List<TestModel> resultListAuthdate) {
             TestModel v0 = new TestModel();
             TestModel v1 = new TestModel();
             TestModel v2 = new TestModel();
             TestModel v3 = new TestModel();
             TestModel v4 = new TestModel();
             TestModel v5 = new TestModel();
             TestModel v6 = new TestModel();
             TestModel v7 = new TestModel();
             TestModel v8 = new TestModel();
             TestModel v9 = new TestModel();
             TestModel v10 = new TestModel();
       v0.setAuthdate("20140505");v0.setCooperativename("가능점");v0.setP_gubn_nm("건기식");v0.setS_gubn_nm("건기식(VFood몰):non");
           BeanUtils.copyProperties(v0, v1);
           BeanUtils.copyProperties(v0, v2);
           v0.setP_gubn_nm("발효유");
           BeanUtils.copyProperties(v0, v3);
           BeanUtils.copyProperties(v0, v4);
           BeanUtils.copyProperties(v0, v5);
           v0.setCooperativename("가락점");
           v0.setP_gubn_nm("건기식");
           BeanUtils.copyProperties(v0, v6);
           BeanUtils.copyProperties(v0, v7);
           BeanUtils.copyProperties(v0, v8);
           BeanUtils.copyProperties(v0, v9);
           BeanUtils.copyProperties(v0, v10);

        resultListAuthdate.add(v1 );
        resultListAuthdate.add(v2 );
        resultListAuthdate.add(v3 );
        resultListAuthdate.add(v4 );
        resultListAuthdate.add(v5 );
        resultListAuthdate.add(v6 );
        resultListAuthdate.add(v7 );
        resultListAuthdate.add(v8 );
        resultListAuthdate.add(v9 );
        resultListAuthdate.add(v10);

        for (TestModel rss : resultListAuthdate ) {
             System.out.println(rss.getAuthdate() + " | " + rss.getCooperativename() + " | " + rss.getP_gubn_nm() + " | " + rss.getS_gubn_nm() + " | " );
        }
       }

       public static void main(String[] args) {
        String str1="",str2="";
       String preStr1="",preStr2="";
        Map<String, int[]> tm = new HashMap<String, int[]>();
        List<TestModel> resultListAuthdate = new ArrayList<TestModel>();
        load(resultListAuthdate);
        int loop = 0;
        for (TestModel rss : resultListAuthdate ) {
             loop++;
             str1 = rss.getAuthdate();
             str2 = rss.getCooperativename();
             System.out.println("loop / str1 / str2 : " + loop + " / "+ str1 + " / " + str2);
             setCalcRowspan(tm,loop,str1,preStr1);
             setCalcRowspan(tm,loop,str2,preStr2);
             preStr1 = rss.getAuthdate();
             preStr2 = rss.getCooperativename();
        }
//        System.out.println(ToStringBuilder.reflectionToString(tm,ToStringStyle.MULTI_LINE_STYLE));
        for (Map.Entry<String, int[]>  info : tm.entrySet() ) {
             System.out.println("vv " + info.getKey() + " / " + info.getValue()[0] + " / " + info.getValue()[1]);
        }

       }

    /**
     *
      * Rowspan정보를 계산하여, Map info에 보관합니다.
      *
      * @name setCalcRowspan
      * @param info       : Rowspan정보를 보관
      * @param position   : Rowspan의 시작위치
      * @param key        : Rowspan적용 key
      * @param preKey     : Rowspan적용 previous key
     */
    private static void setCalcRowspan(Map<String, int[]> info,int position,String key,String preKey){
       if ( info.get(key)==null ) {
             info.put(key,new int[]{0,0,0}); // start, end, length
       }
       int[] vv = info.get(key);
       if ( !key.equals(preKey) ) {
             vv[0] = position;
             vv[1] = position;
             vv[2] = 1;
       } else {
             vv[1] = vv[1]+1;
             vv[2] = vv[2]+1;
       }
       info.put(key,vv);
    }

       public static class TestModel {
           private String p_gubn_nm    ;
           private String s_gubn_nm    ;

           private String authdate   ;
           private String cooperativename;

             public TestModel() {
                    super();
             }

             public String getP_gubn_nm() {
                    return p_gubn_nm;
             }

             public void setP_gubn_nm(String p_gubn_nm) {
                    this.p_gubn_nm = p_gubn_nm;
             }
             public String getS_gubn_nm() {
                    return s_gubn_nm;
             }
             public void setS_gubn_nm(String s_gubn_nm) {
                    this.s_gubn_nm = s_gubn_nm;
             }
             public String getAuthdate() {
                    return authdate;
             }
             public void setAuthdate(String authdate) {
                    this.authdate = authdate;
             }
             public String getCooperativename() {
                    return cooperativename;
             }
             public void setCooperativename(String cooperativename) {
                    this.cooperativename = cooperativename;
             }

           }

}


'java' 카테고리의 다른 글

cors enable 가이드.  (0) 2015.10.08
log4jdbc logback 설정.  (0) 2015.10.02
제우스(Jeus) 가상 호스트 등록 방법.  (0) 2015.04.24
Passing String Array Parameter  (0) 2014.12.05
Toggle 1 to 0 and 9 to 1 using xor  (0) 2014.11.28

댓글