Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BeanGenerator
- {
- StringBuilder beanGen;
- Pattern character;
- Pattern image;
- ArrayList<CharBean> charBeanList; //Will use this as a placeholder.
- private LinkedHashMap<Coordinate, ArrayList<CharBean>> beanMap = new LinkedHashMap<Coordinate, ArrayList<CharBean>>();
- public BeanGenerator(String s)
- {
- beanGen = new StringBuilder(s);
- character = Pattern.compile(RegexHelper.charRegex);
- }
- public LinkedHashMap<Coordinate, ArrayList<CharBean>> getBeanMap() {
- return beanMap;
- }
- public BeanGenerator()
- {
- beanGen = new StringBuilder("");
- }
- public void makeBeans()
- {
- String groups = "";
- String getScan = null;
- //lines = beanGen.split("\\r?\\n"); //Get all lines in an array.
- //for(int i = 0; i < lines.length; i++)
- //Scanner scan = new Scanner(beanGen.toString());
- //scan.useDelimiter("^" + character.pattern());
- BufferedReader io = new BufferedReader(new StringReader(beanGen.toString()));
- try
- {
- while((getScan = io.readLine()) != null)
- {
- Matcher m = character.matcher(getScan);
- if(m.find())
- {
- Coordinate coord = new Coordinate(m.group(5));
- groups = m.group(3) + "," + m.group(5) + "," + m.group(9)
- + "," + m.group(13) + "," + m.group(17) + ","
- + m.group(21) + "," + m.group(25) + "," + m.group(27);
- if(getBeanMap().containsKey(coord)) //If the map already contains this coordinate object
- {
- getBeanMap().get(coord).add(new CharBean(groups)); //Simply add the CharBean to the ArrayList indexed by this Coordinate object.
- }
- else
- {
- charBeanList = new ArrayList<CharBean>();
- charBeanList.add(new CharBean(groups));
- getBeanMap().put(coord, charBeanList);
- }
- }
- groups = "";
- }
- System.out.print("Pointless debug statement");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- static class RegexHelper
- {
- static String words = "((?:[a-z][a-z]+))";
- static String singleChar = "(.)";
- static String floatNum = "([+-]?\\d*\\.\\d+)(?![-+0-9.])";
- static String space = "\\s";
- static String notLineEnd = "([^\r?\n])";
- static String charRegex = words + singleChar + floatNum
- + singleChar + floatNum + space + words
- + singleChar + floatNum + space + words
- + singleChar + floatNum + space + words
- + singleChar + floatNum + space + words
- + singleChar + floatNum + space + words
- + singleChar + floatNum + singleChar + singleChar;
- }
- }
- /* TEST CASE
- Input Line -> String[129.72401,94.0 fs=12.0 xscale=12.0 height=7.992 space=3.0 width=3.0],
- groups(String) = "129.72401,94.0,12.0,12.0,7.992,3.0,3.0"
- Input Line -> String[135.72401,94.0 fs=12.0 xscale=12.0 height=7.992 space=3.0 width=6.671997]h
- groups(String) = "135.72401,94.0,12.0,12.0,7.992,3.0,6.671997,h"
- Notice the difference in how the letter 'h' is matched but ',' is not.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement