package tim.prune.load; import tim.prune.I18nManager; import tim.prune.data.Field; import tim.prune.data.Latitude; import tim.prune.data.Longitude; import tim.prune.data.Timestamp; /** * Class to try to match data with field names, * using a variety of guessing techniques */ public abstract class FieldGuesser { /** * Try to guess whether the given line is a header line or data * @param inValues array of values from first non-blank line of file * @return true if it looks like a header row, false if it looks like data */ private static boolean isHeaderRow(String[] inValues) { // Loop over values looking for a Latitude value if (inValues != null) { for (int v=0; v 0 && intValue < 100000); } catch (NumberFormatException nfe) {} return false; } } /** * Check whether the given String looks like a waypoint name * @param inValue value from file * @param inIsHeader true if this is a header line, false for data * @return true if it could be a name */ private static boolean fieldLooksLikeName(String inValue, boolean inIsHeader) { if (inValue == null || inValue.equals("")) {return false;} if (inIsHeader) { // This is a header line so look for english or local text String upperValue = inValue.toUpperCase(); return (upperValue.equals("NAME") || upperValue.equals("LABEL") || upperValue.equals(I18nManager.getText("fieldname.waypointname").toUpperCase())); } else { // Look for at least two letters in it int numLetters = 0; for (int i=0; i= 2; } } /** * Check whether the given String looks like a timestamp * @param inValue value from file * @param inIsHeader true if this is a header line, false for data * @return true if it could be a timestamp */ private static boolean fieldLooksLikeTimestamp(String inValue, boolean inIsHeader) { if (inValue == null || inValue.equals("")) {return false;} if (inIsHeader) { String upperValue = inValue.toUpperCase(); // This is a header line so look for english or local text return (upperValue.equals("TIMESTAMP") || upperValue.equals("TIME") || upperValue.equals(I18nManager.getText("fieldname.timestamp").toUpperCase())); } else { // must be at least 7 characters long if (inValue.length() < 7) {return false;} Timestamp stamp = new Timestamp(inValue); return stamp.isValid(); } } }