/** * Get dependencies of a source file. * * @param path The canonical path of source file. * @return Path of dependencies. */ private ArrayList<String> getDependencies(String path) { if (!dependenceMap.containsKey(path)) { ArrayList<String> dependencies = new ArrayList<String>(); Matcher m = PATTERN_REQUIRE.matcher(read(path, charset)); while (m.find()) { // Decide which root path to use. // Path wrapped in <> is related to root path. // Path wrapped in "" is related to parent folder of the source file. String root = null; if (m.group(1).equals("<")) { root = this.root; } else { root = new File(path).getParent(); } // Get path of required file. String required = m.group(2); File f = new File(root, required); if (f.exists()) { dependencies.add(canonize(f)); } else { App.exit("Cannot find required file " + required + " in " + path); } } dependenceMap.put(path, dependencies); } return dependenceMap.get(path); }
/** * Provides a "smart" integer parsing routine that allows (decimal) numbers in string form with * all kind of trailing characters to be parsed into an integer. Some trailing characters are * understood as being part of the number, like "k" to denote a value in thousands, or "m" to * denote a value in millions. * * @param aText the text to parse into an integer value, cannot be <code>null</code>; * @param aUnitDefinition the unit definition for "k" and "M" characters, should be either SI * (units of 1000) or BINARY (units of 1024); * @param aDefault the default value to return in case the given text couldn't be parsed into a * valid number. * @return the integer value part of the given text, or the given default value if the text * couldn't be parsed. */ public static int smartParseInt( final String aText, final UnitDefinition aUnitDefinition, final int aDefault) { // Avoid NPEs when given a null argument; also when an empty // string is given, we can be fairly quick in our conclusion... if ((aText == null) || aText.trim().isEmpty()) { return aDefault; } final Matcher matcher = SMART_INT_PATTERN.matcher(aText); if (matcher.matches()) { final String number = matcher.group(1); final String unit = matcher.group(2); int result = Integer.parseInt(number); if (unit != null) { result *= parseUnit(unit, aUnitDefinition); } return result; } return aDefault; }