SoftwareEngineering

 

CSV

CSVを読み込む

CSVを書きこむ

XML

XMLを読み込む

ファイル名から拡張子を除いたベース名を取得する

プロパティファイル

XML版

配列

String配列

歯抜けになっている中身を前詰する

public class RemoveBlankItems{
    
    public static void main(String args[]) throws Exception {
        String items[] = new String[30];
        
        for (int i = 0; i < items.length; i++) {
            items[i] = "";
        }
        
        items[5] = "5番目のデータ";
        items[10] = "10番目のデータ";
        items[15] = "15番目のデータ";
        items[20] = "20番目のデータ";
        items[25] = "25番目のデータ";
        
        System.out.println("---------------------------------------------------------------------------");
        System.out.println("-- 未処理");
        for (int i = 0; i < items.length; i++) {
            System.out.println("items[" + Integer.toString(i) + "]:[" + items[i] + "]");
        }
        
        removeBlankItems(items);
        
        System.out.println("---------------------------------------------------------------------------");
        System.out.println("-- 処理後");
        for (int i = 0; i < items.length; i++) {
            System.out.println("items[" + Integer.toString(i) + "]:[" + items[i] + "]");
        }
    }
    
    
    private static void removeBlankItems(String items[]) {
        String buffer[] = new String[items.length];
        
        // 配列の中身を退避
        for (int index = 0; index < items.length; index++) {
            buffer[index] = items[index];
        }
        
        // 前方に詰めたい配列の中身をクリア
        for (int index = 0; index < items.length; index++) {
            items[index] = "";
        }
        
        // 前方に詰める
        int itemIndex = 0;
        for (int bufferIndex = 0; bufferIndex < buffer.length; bufferIndex++) {
            if (buffer[bufferIndex] == null) continue;
            if (buffer[bufferIndex].equals("")) continue;
            
            items[itemIndex] = buffer[bufferIndex];
            itemIndex++;
        }
        
    }
    
}

画像

画像を回転させる

private Image rotate(Image sourceImage, int rotation) {
    int sourceWidth = sourceImage.getWidth(this);       // 幅(変換前の画像)
    int sourceHeight = sourceImage.getHeight(this);     // 高さ(変換後の画像)
    double angle = 0;                                   // 角度
    
    int targetWidth = sourceWidth;                      // 幅(変換後の画像)
    int targetHeight = sourceHeight;                    // 高さ(変換後の画像)
    
    double posX = 0;    // 中心点 X座標
    double posY = 0;    // 中心点 Y座標
    
    
    switch (rotation) {
        case 1: {
            // 右に90度回転する
            angle = Math.toRadians(90d);
            posX = (sourceWidth / 2) - ((sourceWidth - sourceHeight) / 2);
            posY = sourceHeight / 2;
            
            targetWidth = sourceHeight;
            targetHeight = sourceWidth;
            
            break;
        }
        
        case 2: {
            // 右に180度回転する
            angle = Math.toRadians(180d);
            posX = sourceWidth / 2;
            posY = sourceHeight / 2;
            
            targetWidth = sourceWidth;
            targetHeight = sourceHeight;
            
            break;
        }
        
        case 3: {
            // 右に270度回転する
            angle = Math.toRadians(270d);
            posX = sourceWidth / 2;
            posY = (sourceHeight / 2) + ((sourceWidth - sourceHeight) / 2);
            
            targetWidth = sourceHeight;
            targetHeight = sourceWidth;
            
            break;
        }
    }
    
    
    BufferedImage targetImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
    
    java.awt.geom.AffineTransform affin
        = java.awt.geom.AffineTransform.getRotateInstance(angle, posX, posY);
    
    Graphics2D g2 = (Graphics2D)targetImage.createGraphics();
    g2.drawImage(sourceImage, affin, null);
    
    return targetImage;
}

トップ   一覧 検索 最終更新   ヘルプ   最終更新のRSS