public static Comparable<Object> getComparable(Object object) { final Boolean b = toBoolean(object); return new Comparable<Object>() { public int compareTo(Object o) { return _instance.compare(b, o); } @Override public String toString() { return "BooleanComparable[boolean=" + b + "]"; } }; }
public int compareTo(Object o) { return _instance.compare(b, o); }
@SuppressWarnings("unchecked") public Comparator getComparator() { if (isTimeBased()) { return TimeComparator.getComparator(); } if (isNumber()) { return NumberComparator.getComparator(); } if (isLiteral()) { return ToStringComparator.getComparator(); } return ObjectComparator.getComparator(); }
private Comparable getComparable(ColumnType type, String value) throws IllegalArgumentException { try { if (type != null) { if (type.isLiteral()) { return ToStringComparator.getComparable(value); } if (type.isNumber()) { return NumberComparator.getComparable(value); } if (type.isTimeBased()) { return TimeComparator.getComparable(value); } if (type.isBoolean()) { return BooleanComparator.getComparable(value); } } return ObjectComparator.getComparable(value); } catch (Exception e) { if (e instanceof IllegalArgumentException) { throw (IllegalArgumentException) e; } throw new IllegalArgumentException(e); } }
public static BufferedReader getBufferedReader(File file) { return new BufferedReader(getReader(file)); }
return NumberComparator.getComparator().compare(o1, o2); if (isTimeBased(o1) || isTimeBased(o2)) { return TimeComparator.getComparator().compare(o1, o2); return ToStringComparator.getComparator().compare(o1, o2);
/** * @param obj1 * @param obj2 * @return the highest of the two objects. can be null if the objects cant * be compared or are null. */ public static Object getHighestObject(Object obj1, Object obj2) { if (obj1 == null && obj2 == null) { return null; } int compareResult = ObjectComparator.getComparator() .compare(obj1, obj2); if (compareResult > 0) { return obj1; } return obj2; }
public static String readFileAsString(File file) { try { BufferedReader br = getBufferedReader(file); StringBuilder sb = new StringBuilder(); boolean firstLine = true; for (String line = br.readLine(); line != null; line = br .readLine()) { if (firstLine) { firstLine = false; } else { sb.append('\n'); } sb.append(line); } br.close(); return sb.toString(); } catch (Exception e) { throw new RuntimeException(e); } } }
public static BufferedWriter getBufferedWriter(File file) { return new BufferedWriter(getWriter(file)); }
public static void writeStringAsFile(File file, String string) { try { BufferedWriter bw = getBufferedWriter(file); bw.write(string); bw.close(); } catch (Exception e) { throw new RuntimeException(e); } }
public static void saveToFile(List<NamedRegex> regexes, File file) { StringBuilder sb = new StringBuilder(); sb.append("#Regex registrations for DataCleaner\n"); if (regexes != null) { for (NamedRegex namedRegex : regexes) { sb.append(namedRegex.getName() + "=" + namedRegex.getExpression() + "\n"); } } FileHelper.writeStringAsFile(file, sb.toString()); } }
if (_booleanPossible) { try { BooleanComparator.parseBoolean(valueAsString); } catch (IllegalArgumentException e) { _booleanPossible = false;
/** * Creates an XML DataContext strategy based on a file. * * @param file * the file to parse * @param autoFlattenTables * a parameter indicating whether or not tags with only text * content or a single attribute should be flattened with it's * parent table * * @throws IllegalArgumentException * if the file does not exist */ public XmlDataContextStrategy(File file, boolean autoFlattenTables) throws IllegalArgumentException { this(new InputSource(FileHelper.getReader(file)), file.getName(), autoFlattenTables); }
public int compare(Entry<String, Long> o1, Entry<String, Long> o2) { Long o1count = o1.getValue(); Long o2count = o2.getValue(); int compareTo = o2count.compareTo(o1count); if (compareTo == 0) { compareTo = ObjectComparator.getComparator() .compare(o1.getKey(), o2.getKey()); } return compareTo; } });
public static List<NamedRegex> loadFromFile(File file) { List<NamedRegex> result = new ArrayList<NamedRegex>(); BufferedReader reader = FileHelper.getBufferedReader(file); try { for (String line = reader.readLine(); line != null; line = reader .readLine()) { line = line.trim(); if (!line.startsWith("#")) { int seperatorIndex = line.indexOf('='); String name = line.substring(0, seperatorIndex); String expression = line.substring(seperatorIndex + 1, line .length()); result.add(new NamedRegex(name, expression)); } } } catch (IOException e) { throw new IllegalArgumentException(e); } return result; }
private void initWordlist() { if (_dictionaryFile == null) { throw new IllegalStateException( "Cannot validate without dictionaryFile."); } try { BufferedReader br = new BufferedReader(FileHelper .getReader(_dictionaryFile)); _wordList = new ArrayList<String>(); for (String line = br.readLine(); line != null; line = br .readLine()) { line = line.trim(); _wordList.add(line); } br.close(); } catch (IOException e) { _log.error(e); throw new RuntimeException(e); } Collections.sort(_wordList); }
@Override public boolean equals(Object obj) { if (obj instanceof Row) { Row that = (Row) obj; EqualsBuilder eb = new EqualsBuilder(); eb.append(this._values.length, that._values.length); Comparator<Object> comparator = ObjectComparator.getComparator(); for (int i = 0; i < _values.length; i++) { eb.appendSuper(0 == comparator.compare(this._values[i], that._values[i])); } eb.append(this._items, that._items); return eb.isEquals(); } return false; }
schema.addTable(table); reader = new CSVReader(FileHelper.getReader(_file), _separatorChar, _quoteChar); String[] columnHeaders = reader.readNext();