Skip to content

Instantly share code, notes, and snippets.

@hapo31
Created April 21, 2016 14:41
Show Gist options
  • Save hapo31/f379fe395fa4424e185b522bd01604eb to your computer and use it in GitHub Desktop.
Save hapo31/f379fe395fa4424e185b522bd01604eb to your computer and use it in GitHub Desktop.
/**
* コメント書くの力尽きたので適当にC++版のと見比べてください♨
* https://gist.github.com/happou31/bd87cc83b4d57d3ad233c257f6d423e3
*/
import java.io.*;
import java.util.*;
import java.nio.file.*;
import java.nio.charset.Charset;
public class Jyusyo
{
public static void main(String[] args) throws Exception
{
final String filename = "KEN_ALL.CSV";
BufferedReader file = Files.newBufferedReader(FileSystems.getDefault().getPath(filename), Charset.forName("Shift-JIS"));
List<Addr> addrs = new ArrayList<>();
StopWatch stopWatch = new StopWatch();
System.out.print(filename + "...");
stopWatch.Start();
String line;
while((line = file.readLine()) != null)
{
line = line.replaceAll("\"", "");
String[] splited = line.split(",");
String number = splited[2];
StringBuilder addr = new StringBuilder();
Arrays.asList(splited).subList(6, 9).forEach(s -> addr.append(s));
addrs.add(new Addr(number, addr.toString()));
}
stopWatch.Stop();
System.out.println(addrs.size() + "lines loaded.");
System.out.println("time:" + (stopWatch.GetDuration()) + "ms");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while(true)
{
System.out.print("[s] search [q] quit>");
String input = in.readLine();
if("q".equals(input)) break;
if("s".equals(input))
{
System.out.print("search number>");
input = in.readLine();
stopWatch.Start();
List<Addr> finds = new ArrayList<>();
for(Addr addr : addrs)
{
if(addr.getNumber().indexOf(input) >= 0)
{
finds.add(addr);
}
}
stopWatch.Stop();
for(Addr addr : finds)
{
System.out.println( addr.getAddr());
}
System.out.println("time:" + stopWatch.GetDuration());
}
}
}
public static class Addr
{
public Addr(String number, String addr)
{
this.number = number;
this.addr = addr;
}
private String number;
private String addr;
public String getAddr() { return addr; }
public String getNumber() { return number; }
}
public static class StopWatch
{
public StopWatch(){ this.Reset(); }
public void Start(){ start = System.currentTimeMillis(); }
public void Stop() { end = System.currentTimeMillis(); }
public void Reset() { start = 0; end = 0; }
public long GetDuration() { return end - start; }
private long start;
private long end;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment