public String remove(Object s) { throw new ConfigException("Config is immutable."); } }
@SuppressWarnings("unchecked") public <T> T getNewInstance(String k) { try { return (T) getClass(k).newInstance(); } catch (Exception e) { throw new ConfigException("Unable to instantiate class.", e); } }
@SuppressWarnings("unchecked") public <T> Class<T> getClass(String k) { if (containsKey(k)) { try { return (Class<T>) Class.forName(get(k)); } catch (Exception e) { throw new ConfigException("Unable to find class.", e); } } else { throw new ConfigException("Missing key " + k + "."); } }
public Date getDate(String k, SimpleDateFormat format) { if (!containsKey(k)) throw new ConfigException("Missing key " + k + "."); try { return format.parse(get(k)); } catch (ParseException e) { throw new ConfigException("Date format exception.", e); } }
@SuppressWarnings("unchecked") public <T> Class<T> getClass(String k) { if (containsKey(k)) { try { return (Class<T>) Class.forName(get(k)); } catch (Exception e) { throw new ConfigException("Unable to find class.", e); } } else { throw new ConfigException("Missing key " + k + "."); } }
public Date getDate(String k, SimpleDateFormat format, Date defaultValue) { if (!containsKey(k)) return defaultValue; try { return format.parse(get(k)); } catch (ParseException e) { throw new ConfigException("Date format exception.", e); } }
public double getDouble(String k) { if (containsKey(k)) return Double.parseDouble(get(k)); else throw new ConfigException("Missing key " + k + "."); }
public boolean getBoolean(String k) { if (containsKey(k)) return "true".equalsIgnoreCase(get(k)); else throw new ConfigException("Missing key " + k + "."); }
public long getLong(String k) { if (containsKey(k)) return Long.parseLong(get(k)); else throw new ConfigException("Missing key " + k + "."); }
public short getShort(String k) { if (containsKey(k)) return Short.parseShort(get(k)); else throw new ConfigException("Missing key " + k + "."); }
public int getInt(String k) { if (containsKey(k)) return Integer.parseInt(get(k)); else throw new ConfigException("Missing key " + k + "."); }
public double getDouble(String k) { if (containsKey(k)) return Double.parseDouble(get(k)); else throw new ConfigException("Missing key " + k + "."); }
public long getLong(String k) { if (containsKey(k)) return Long.parseLong(get(k)); else throw new ConfigException("Missing key " + k + "."); }
public List<String> getList(String k) { if (!containsKey(k)) throw new ConfigException("Missing key " + k + "."); return getList(k, null); }
public String getZkConnect() { if (!containsKey(ZK_CONNECT)) { throw new ConfigException("Missing " + ZK_CONNECT + " config!"); } return get(ZK_CONNECT); }
public String getAzureConnectionString() { if (!containsKey(AZURE_STORAGE_CONNECT)) { throw new ConfigException("Missing " + AZURE_STORAGE_CONNECT + " config!"); } return get(AZURE_STORAGE_CONNECT); }
public List<String> getList(String k) { if (!containsKey(k)) throw new ConfigException("Missing key " + k + "."); return getList(k, null); }
public String getZkConnect() { if (!containsKey(ZK_CONNECT)) { throw new ConfigException("Missing " + ZK_CONNECT + " config!"); } return get(ZK_CONNECT); }
public String getZkConnect() { if (!containsKey(ZK_CONNECT)) { throw new ConfigException("Missing " + ZK_CONNECT + " config!"); } return get(ZK_CONNECT); }
public static Pair<String, String> getJobNameAndId(Config config) { JobConfig jobConfig = new JobConfig(config); Option jobNameOption = jobConfig.getName(); if (jobNameOption.isEmpty()) { throw new ConfigException("Missing job name"); } String jobName = (String) jobNameOption.get(); return new ImmutablePair<>(jobName, jobConfig.getJobId()); }