記事の最後に載せたプログラムのコメントにも書きましたが、ポイントは2つあります。
- 基準日の年と生年の差
- 基準日がその年の誕生日よりも前のときは1を減算する
2015/8/31
NARITA Shoさんから「Excel 界隈では「基準日」という語が使われているみたいですね。」とのコメントを頂きました。ありがとうございました。
以下、xyzzy lispとC#での実装を記載します。
2015/9/2
C#での実装例を追加しました。
String regex = "\\[([0-9]+)\\]";
String src = "[1] [2] [3] [4] [5]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(src);
String result1 = matcher.replaceAll("($1)");
System.out.println(result1);
// => (1) (2) (3) (4) (5)
String regex = "\\[([0-9]+)\\]";
String src = "[1] [2] [3] [4] [5]";
String[] kan = {"一", "ニ", "三", "四", "五"};
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(src);
StringBuilder result2 = new StringBuilder();
int lastEnd = 0;
String outOfMatch = "";
while(matcher.find()) {
outOfMatch = src.substring(lastEnd, matcher.start());
String group = matcher.group(1);
int n = Integer.parseInt(group);
String kanN = kan[n-1];
result2.append(outOfMatch);
result2.append("(" + kanN + ")");
lastEnd = matcher.end();
}
outOfMatch = src.substring(lastEnd);
result2.append(outOfMatch);
System.out.println(result2);
// => (一) (ニ) (三) (四) (五)
import java.awt.Font;
import java.awt.FontMetrics;
import sun.font.FontDesignMetrics;
public class Program {
public static void main(String[] args) {
// Fontオブジェクトをインスタンス化する
// FontオブジェクトからFontMetricsオブジェクトを取得する
// FontMetrics#stringWidthメソッドで文字列の幅を取得する
Font font = new Font("Monospace", Font.PLAIN, 12);
FontMetrics fontMetrics = FontDesignMetrics.getMetrics(font);
String data = "Hello FontMetrics";
int width = fontMetrics.stringWidth(data);
System.out.println(width);
}
}
import java.util.List;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
public class Program {
public static void main(String[] args) throws Exception {
ExecutorService svc = Executors.newFixedThreadPool(3);
try {
List<Callable<Integer>> listCallable = new ArrayList<>();
for (String ipAddress : args) {
listCallable.add(new PingCommand(ipAddress));
}
List<Future<Integer>> listFuture = svc.invokeAll(listCallable);
for (Future<Integer> future : listFuture) {
System.out.println(future.get());
}
} finally {
svc.shutdown();
}
}
private static class PingCommand implements Callable<Integer> {
private final String ipAddress;
private PingCommand(String ipAddress) {
this.ipAddress = ipAddress;
}
public Integer call() {
try {
String[] args = {"ping", ipAddress, "-c", "3"};
Process proc = new ProcessBuilder(args).start();
return proc.waitFor();
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
}
}
Import-Csv -Path .\Book1.csv -Encoding Default
Get-Content .\Book1.csv | ConvertFrom-Csv
(ns myawt)
(import '(java.awt Frame)
'(java.awt.event WindowListener))
(def window-width 600)
(def window-height 480)
(doto (Frame.)
(.addWindowListener
(proxy [WindowListener] []
(windowActivated [e])
(windowClosed [e] (System/exit 0))
(windowClosing [e] (.dispose (.getWindow e)))
(windowDeactivated [e])
(windowDeiconified [e])
(windowIconified [e])
(windowOpened [e])))
(.setSize window-width window-height)
(.setVisible true))
windowClosedとwindowClosingのイベントハンドラを実装するのがポイントです。