public boolean isValidName() { return !Helper.isEmpty(name); }
public static int countOccurence(String phrase, String splitter) { if (isEmpty(phrase)) return 0; return phrase.trim().split(splitter).length; }
public GHDirectory(String _location, DAType defaultType) { this.defaultType = defaultType; if (isEmpty(_location)) _location = new File("").getAbsolutePath(); if (!_location.endsWith("/")) _location += "/"; location = _location; File dir = new File(location); if (dir.exists() && !dir.isDirectory()) throw new RuntimeException("file '" + dir + "' exists but is not a directory"); }
@Override public String toString() { String str = ""; if (!Helper.isEmpty(name)) { str += name + " "; } return str + "time:" + getSeconds(); }
/** * This file can be any file type supported by the DataReader. E.g. for the OSMReader it is the * OSM xml (.osm), a compressed xml (.osm.zip or .osm.gz) or a protobuf file (.pbf) */ public GraphHopper setDataReaderFile(String dataReaderFileStr) { ensureNotLoaded(); if (isEmpty(dataReaderFileStr)) throw new IllegalArgumentException("Data reader file cannot be empty."); dataReaderFile = dataReaderFileStr; return this; }
public boolean getBool(String key, boolean _default) { String str = get(key); if (!Helper.isEmpty(str)) { try { return Boolean.parseBoolean(str); } catch (Exception ex) { } } return _default; }
public double getDouble(String key, double _default) { String str = get(key); if (!Helper.isEmpty(str)) { try { return Double.parseDouble(str); } catch (Exception ex) { } } return _default; }
public String get(String key, String _default) { String str = get(key); if (Helper.isEmpty(str)) return _default; return str; }
String get(String key) { if (Helper.isEmpty(key)) return ""; // query accepts camelCase and under_score String val = map.get(Helper.camelCaseToUnderScore(key)); if (val == null) return ""; return val; }
PMap merge(Map<String, String> map) { for (Map.Entry<String, String> e : map.entrySet()) { if (Helper.isEmpty(e.getKey())) continue; put(e.getKey(), e.getValue()); } return this; }
public AbstractDataAccess(String name, String location, ByteOrder order) { byteOrder = order; bitUtil = BitUtil.get(order); this.name = name; if (!Helper.isEmpty(location) && !location.endsWith("/")) throw new IllegalArgumentException("Create DataAccess object via its corresponding Directory!"); this.location = location; }
@Override public String tr(String key, Object... params) { String val = map.get(toLowerCase(key)); if (isEmpty(val)) return key; return String.format(Locale.ROOT, val, params); }
public int getInt(String key, int _default) { String str = get(key); if (!Helper.isEmpty(str)) { try { return Integer.parseInt(str); } catch (Exception ex) { } } return _default; }
public float getFloat(String key, float _default) { String str = get(key); if (!Helper.isEmpty(str)) { try { return Float.parseFloat(str); } catch (Exception ex) { } } return _default; }
protected boolean checkBeforeRename(String newName) { if (Helper.isEmpty(newName)) throw new IllegalArgumentException("newName mustn't be empty!"); if (newName.equals(name)) return false; if (isStoring() && new File(location + newName).exists()) throw new IllegalArgumentException("file newName already exists!"); return true; }
public long getLong(String key, long _default) { String str = get(key); if (!Helper.isEmpty(str)) { try { return Long.parseLong(str); } catch (Exception ex) { } } return _default; }
public MatrixResponse route(GHMRequest request) { if (!Helper.isEmpty(key)) { request.getHints().put(KEY, key); } return requester.route(request); } }
private long extractMeter(ReaderWay way, long flags, EncodedDoubleValue valueEncoder, List<String> keys) { String value = way.getFirstPriorityTag(keys); if (isEmpty(value)) return flags; double val; try { val = stringToMeter(value); } catch (Exception ex) { LOG.warn("Unable to extract meter from malformed road attribute '{}' for way (OSM_ID = {}).", value, way.getId(), ex); return flags; } try { flags = valueEncoder.setDoubleValue(flags, val); } catch (IllegalArgumentException e) { LOG.warn("Unable to process value '{}' for way (OSM_ID = {}).", val, way.getId(), e); } return flags; }
private long extractTons(ReaderWay way, long flags, EncodedDoubleValue valueEncoder, List<String> keys) { String value = way.getFirstPriorityTag(keys); if (isEmpty(value)) return flags; double val; try { val = stringToTons(value); } catch (Throwable t) { LOG.warn("Unable to extract tons from malformed road attribute '{}' for way (OSM_ID = {}).", value, way.getId(), t); return flags; } try { flags = valueEncoder.setDoubleValue(flags, val); } catch (IllegalArgumentException e) { LOG.warn("Unable to process tons value '{}' for way (OSM_ID = {}).", val, way.getId(), e); } return flags; }
protected String buildURLNoHints(String path, GHMRequest ghRequest) { // allow per request service URLs String tmpServiceURL = ghRequest.getHints().get(SERVICE_URL, serviceUrl); String url = tmpServiceURL; url += path + "?"; String key = ghRequest.getHints().get(KEY, ""); if (!Helper.isEmpty(key)) { url += "key=" + key; } return url; }