PageAddress.java

00001 package edu.stanford.hci.r3.pattern.coordinates;
00002 
00003 import java.util.regex.Matcher;
00004 import java.util.regex.Pattern;
00005 
00006 import edu.stanford.hci.r3.util.DebugUtils;
00007 
00019 public class PageAddress {
00020 
00024         private static final Pattern PATTERN_ADDRESS = Pattern.compile("(.*?)\\.(.*?)\\.(.*?)\\.(.*)");
00025 
00026         private int book;
00027 
00028         private int page;
00029 
00030         private int segment;
00031 
00032         private int shelf;
00033 
00034         public PageAddress(int theSegment, int theShelf, int theBook, int thePage) {
00035                 segment = theSegment;
00036                 shelf = theShelf;
00037                 book = theBook;
00038                 page = thePage;
00039         }
00040 
00044         public PageAddress(String pageAddress) {
00045                 // extract the segment, shelf, book, and page from the pageAddress
00046                 final Matcher matcherPageAddress = PATTERN_ADDRESS.matcher(pageAddress);
00047                 if (matcherPageAddress.find()) {
00048                         String segmentStr = matcherPageAddress.group(1);
00049                         String shelfStr = matcherPageAddress.group(2);
00050                         String bookStr = matcherPageAddress.group(3);
00051                         String pageStr = matcherPageAddress.group(4);
00052 
00053                         // DebugUtils.println(segmentStr + "_" + shelfStr + "_" + bookStr + "_" + pageStr);
00054 
00055                         segment = Integer.parseInt(segmentStr);
00056                         shelf = Integer.parseInt(shelfStr);
00057                         book = Integer.parseInt(bookStr);
00058                         page = Integer.parseInt(pageStr);
00059                 } else {
00060                         System.err.println("PageAddress: " + pageAddress
00061                                         + " is not a valid logical page address.");
00062                         // do nothing, and leave all the fields blank
00063                 }
00064         }
00065 
00069         public int getBook() {
00070                 return book;
00071         }
00072 
00076         public int getPage() {
00077                 return page;
00078         }
00079 
00083         public int getSegment() {
00084                 return segment;
00085         }
00086 
00090         public int getShelf() {
00091                 return shelf;
00092         }
00093 
00097         public String toString() {
00098                 return segment + "." + shelf + "." + book + "." + page;
00099         }
00100 
00101 }

Generated on Sat Apr 14 18:21:36 2007 for R3 Paper Toolkit by  doxygen 1.4.7