// CSE 373, Winter 2013, Marty Stepp // This program shows some other Guava features with our presidents example // such as the ability to search for presidents by ranges using RangeMap. import java.io.*; import java.util.*; import com.google.common.collect.*; public class Lecture06Guava { public static void main(String[] args) throws FileNotFoundException { RangeMap range = TreeRangeMap.create(); Scanner input = new Scanner(new File("prez.txt")); while (input.hasNextLine()) { Scanner tokens = new Scanner(input.nextLine()); tokens.useDelimiter(":"); String prez = tokens.next(); String[] parts = prez.split(" "); String firstName = parts[0]; String party = tokens.next(); int startYear = tokens.nextInt(); int endYear = tokens.nextInt(); String vp = tokens.next(); // TODO: finish range.put(Range.closed(startYear, endYear), prez); } System.out.println(range); range.subRangeMap(Range.closedOpen(1800, 1900)).clear(); System.out.println(range); System.out.println("president in 1841 was " + range.get(1841)); } }