忍者ブログ
まにょのITメモ
[6]  [7]  [8]  [9]  [10]  [11]  [12]  [13]  [14]  [15]  [16
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

package jp.co.sample.main;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.List;

import jp.co.sample.bean.SampleTempBean;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

public class SampleMain {
    private static final String SQL_OUTPUT_PATH = "./sql/";
    private static final String TABLE_TEIGI_PATH = "./xls/";

    public static void main(String[] args) {
        try {
           
            /* テキストファイル読み込み */
            List<SampleTempBean> sampleTempBeanList = ControllerExcel.readExcel(TABLE_TEIGI_PATH);

            Velocity.init();// Velocity初期化

            BufferedWriter writer = new BufferedWriter(new FileWriter(
                    SQL_OUTPUT_PATH + "動的SQL作成.txt"));
           
            for (SampleTempBean sampleTempBean : sampleTempBeanList) {
                VelocityContext ctx = new VelocityContext();
                // テーブル名をセット
                ctx.put("sampleTempBean", sampleTempBean);
               
                Template template = Velocity
                        .getTemplate("./template/temp.vm");
                template.merge(ctx, writer);
            }
           
            for (SampleTempBean sampleTempBean : sampleTempBeanList) {
                VelocityContext ctx = new VelocityContext();
                // テーブル名をセット
                ctx.put("sampleTempBean", sampleTempBean);
               
                Template template = Velocity
                        .getTemplate("./template/temp2.vm");
                template.merge(ctx, writer);
            }
           
            writer.flush();
            writer.close();

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("致命的なエラーだ。大変だ・・・");
        }
        System.out.println("正常終了");
    }
}
 

PR
obj1.equals(obj2)がtrueであれば、obj1.hashCode()とobj2.hashCode()は
同一になることを保障しなければいけない。

obj1.equals(obj2)がfalseでも、obj1.hashCode()とobj2.hashCode()は
一致しないとは限らない
obj1.hashCode()とobj2.hashCode()が同一になる可能性もある。

equals()メソッドをオーバーライドしてクラス定義をした場合、
hashCode()メソッドもオーバーライドする必要がある。

★Mathクラスのメソッド

abs ・・・引数の絶対値を返す

ceil ・・・引数の値以上で最小の整数を返す

floor ・・・引数の値以下で最大の整数を返す


public class SampleMath {

    public static void main(String[] args) {
  
        double d = 100;
  
        System.out.println("abs : " + Math.abs(d));
        System.out.println("ceil : " + Math.ceil(d));
        System.out.println("floor : " + Math.floor(d));
    }
}

~実行結果~
abs : 100.0
ceil : 100.0
floor : 100.0

--------------------------------------------------------------------

public class SampleMath {

    public static void main(String[] args) {
  
        double d = 100.1;
  
        System.out.println("abs : " + Math.abs(d));
        System.out.println("ceil : " + Math.ceil(d));
        System.out.println("floor : " + Math.floor(d));
    }
}

~実行結果~
abs : 100.1
ceil : 101.0
floor : 100.0

--------------------------------------------------------------------

public class SampleMath {

    public static void main(String[] args) {
  
        double d = -100.1;
  
        System.out.println("abs : " + Math.abs(d));
        System.out.println("ceil : " + Math.ceil(d));
        System.out.println("floor : " + Math.floor(d));
    }
}

~実行結果~
abs : 100.1
ceil : -100.0
floor : -101.0
 

public static void main(String[] args) {

    try {
        return;
    }finally {
        System.out.println("finally");
    }
}

-----------------------
実行結果
  finally


try{ }の中でreturnをしても、finallyブロックは必ず実行される。

public class Test {
    private String str;
 
    public Test(String str) {
        this.str = str;
    }
}

引数を持つコンストラスタを自分で定義した場合、
デフォルトコンストラスタは呼び出せなくなる。

--------------------------

public class Test {
    private String str;

    public Test( ) {

    }
 
    public Test(String str) {
        this.str = str;
    }
}

引数を持つコンストラクタを定義するときに、
引数を持たないコンストラクタを明示的に書いておけば
デフォルトコンストラクタをオーバーライドするので
呼び出せるようになる。
忍者ブログ * [PR]