private void setCommon(String id, int cm) throws IllegalArgumentException, NullPointerException { checkId(id, "StatusVariable ID"); if (cm != CM_CC && cm != CM_DER && cm != CM_GAUGE && cm != CM_SI) throw new IllegalArgumentException("Unknown data collection method constant '" + cm + "'."); this.id = id; this.cm = cm; timeStamp = new Date(); }
private static void checkId(String id, String idName) throws IllegalArgumentException, NullPointerException { if (id == null) throw new NullPointerException(idName + " is null."); if (id.length() == 0) throw new IllegalArgumentException(idName + " is empty."); byte[] nameBytes; try { nameBytes = id.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { // never happens, "UTF-8" must always be supported throw new IllegalStateException(e.getMessage()); } if (nameBytes.length > MAX_ID_LENGTH) throw new IllegalArgumentException(idName + " is too long " + "(over " + MAX_ID_LENGTH + " bytes in UTF-8 encoding)."); if (id.equals(".") || id.equals("..")) throw new IllegalArgumentException(idName + " is invalid."); if (!containsValidChars(id)) throw new IllegalArgumentException(idName + " contains invalid characters."); }
/** * Compares the specified object with this {@code StatusVariable}. Two * {@code StatusVariable} objects are considered equal if their full path, * collection method and type are identical, and the data (selected by their * type) is equal. * * @param obj the object to compare with this {@code StatusVariable} * @return {@code true} if the argument represents the same * {@code StatusVariable} as this object */ public boolean equals(Object obj) { if (!(obj instanceof StatusVariable)) return false; StatusVariable other = (StatusVariable) obj; if (!equals(id, other.id) || cm != other.cm || type != other.type) return false; switch (type) { case TYPE_INTEGER : return intData == other.intData; case TYPE_FLOAT : return floatData == other.floatData; case TYPE_STRING : return equals(stringData, other.stringData); case TYPE_BOOLEAN : return booleanData == other.booleanData; } return false; // never reached }
/** * Constructor for a {@code StatusVariable} of {@code float} type. * * @param id the identifier of the {@code StatusVariable} * @param cm the collection method, one of the {@code CM_} constants * @param data the {@code float} value of the {@code StatusVariable} * @throws java.lang.IllegalArgumentException if the given {@code id} is not * a valid {@code StatusVariable} name, or if {@code cm} is not one * of the collection method constants * @throws java.lang.NullPointerException if the {@code id} parameter is * {@code null} */ public StatusVariable(String id, int cm, float data) { setCommon(id, cm); type = TYPE_FLOAT; floatData = data; }
/** * Returns the hash code value for this {@code StatusVariable}. The hash * code is calculated based on the full path, collection method and value of * the {@code StatusVariable}. * * @return the hash code of this object */ public int hashCode() { int hash = hashCode(id) ^ cm; switch (type) { case TYPE_INTEGER : return hash ^ intData; case TYPE_FLOAT : return hash ^ hashCode(new Float(floatData)); case TYPE_BOOLEAN : return hash ^ hashCode(new Boolean(booleanData)); case TYPE_STRING : return hash ^ hashCode(stringData); } return 0; // never reached }
/** * Constructor for a {@code StatusVariable} of {@code boolean} type. * * @param id the identifier of the {@code StatusVariable} * @param cm the collection method, one of the {@code CM_} constants * @param data the {@code boolean} value of the {@code StatusVariable} * @throws java.lang.IllegalArgumentException if the given {@code id} is not * a valid {@code StatusVariable} name, or if {@code cm} is not one * of the collection method constants * @throws java.lang.NullPointerException if the {@code id} parameter is * {@code null} */ public StatusVariable(String id, int cm, boolean data) { setCommon(id, cm); type = TYPE_BOOLEAN; booleanData = data; }
/** * Returns the hash code value for this <code>StatusVariable</code>. The * hash code is calculated based on the full path, collection method and * value of the <code>StatusVariable</code>. * * @return the hash code of this object */ public int hashCode() { int hash = hashCode(id) ^ cm; switch (type) { case TYPE_INTEGER: return hash ^ intData; case TYPE_FLOAT: return hash ^ hashCode(new Float(floatData)); case TYPE_BOOLEAN: return hash ^ hashCode(new Boolean(booleanData)); case TYPE_STRING: return hash ^ hashCode(stringData); } return 0; // never reached }
/** * Constructor for a {@code StatusVariable} of {@code String} type. * * @param id the identifier of the {@code StatusVariable} * @param cm the collection method, one of the {@code CM_} constants * @param data the {@code String} value of the {@code StatusVariable}, can * be {@code null} * @throws java.lang.IllegalArgumentException if the given {@code id} is not * a valid {@code StatusVariable} name, or if {@code cm} is not one * of the collection method constants * @throws java.lang.NullPointerException if the {@code id} parameter is * {@code null} */ public StatusVariable(String id, int cm, String data) { setCommon(id, cm); type = TYPE_STRING; stringData = data; }
private void setCommon(String id, int cm) throws IllegalArgumentException, NullPointerException { checkId(id, "StatusVariable ID"); if (cm != CM_CC && cm != CM_DER && cm != CM_GAUGE && cm != CM_SI) throw new IllegalArgumentException( "Unknown data collection method constant '" + cm + "'."); this.id = id; this.cm = cm; timeStamp = new Date(); }
private static void checkId(String id, String idName) throws IllegalArgumentException, NullPointerException { if (id == null) throw new NullPointerException(idName + " is null."); if(id.length() == 0) throw new IllegalArgumentException(idName + " is empty."); byte[] nameBytes; try { nameBytes = id.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { // never happens, "UTF-8" must always be supported throw new IllegalStateException(e.getMessage()); } if(nameBytes.length > MAX_ID_LENGTH) throw new IllegalArgumentException(idName + " is too long " + "(over " + MAX_ID_LENGTH + " bytes in UTF-8 encoding)."); if(id.equals(".") || id.equals("..")) throw new IllegalArgumentException(idName + " is invalid."); if(!containsValidChars(id)) throw new IllegalArgumentException(idName + " contains invalid characters."); }
/** * Returns the hash code value for this {@code StatusVariable}. The * hash code is calculated based on the full path, collection method and * value of the {@code StatusVariable}. * * @return the hash code of this object */ public int hashCode() { int hash = hashCode(id) ^ cm; switch (type) { case TYPE_INTEGER: return hash ^ intData; case TYPE_FLOAT: return hash ^ hashCode(new Float(floatData)); case TYPE_BOOLEAN: return hash ^ hashCode(new Boolean(booleanData)); case TYPE_STRING: return hash ^ hashCode(stringData); } return 0; // never reached }
/** * Compares the specified object with this <code>StatusVariable</code>. * Two <code>StatusVariable</code> objects are considered equal if their * full path, collection method and type are identical, and the data * (selected by their type) is equal. * * @param obj the object to compare with this <code>StatusVariable</code> * @return <code>true</code> if the argument represents the same * <code>StatusVariable</code> as this object */ public boolean equals(Object obj) { if (!(obj instanceof StatusVariable)) return false; StatusVariable other = (StatusVariable) obj; if (!equals(id, other.id) || cm != other.cm || type != other.type) return false; switch (type) { case TYPE_INTEGER: return intData == other.intData; case TYPE_FLOAT: return floatData == other.floatData; case TYPE_STRING: return equals(stringData, other.stringData); case TYPE_BOOLEAN: return booleanData == other.booleanData; } return false; // never reached }
/** * Constructor for a {@code StatusVariable} of {@code int} type. * * @param id the identifier of the {@code StatusVariable} * @param cm the collection method, one of the {@code CM_} constants * @param data the {@code int} value of the {@code StatusVariable} * @throws java.lang.IllegalArgumentException if the given {@code id} is not * a valid {@code StatusVariable} name, or if {@code cm} is not one * of the collection method constants * @throws java.lang.NullPointerException if the {@code id} parameter is * {@code null} */ public StatusVariable(String id, int cm, int data) { setCommon(id, cm); type = TYPE_INTEGER; intData = data; }
private void setCommon(String id, int cm) throws IllegalArgumentException, NullPointerException { checkId(id, "StatusVariable ID"); if (cm != CM_CC && cm != CM_DER && cm != CM_GAUGE && cm != CM_SI) throw new IllegalArgumentException("Unknown data collection method constant '" + cm + "'."); this.id = id; this.cm = cm; timeStamp = new Date(); }
private static void checkId(String id, String idName) throws IllegalArgumentException, NullPointerException { if (id == null) throw new NullPointerException(idName + " is null."); if (id.length() == 0) throw new IllegalArgumentException(idName + " is empty."); byte[] nameBytes; try { nameBytes = id.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { // never happens, "UTF-8" must always be supported throw new IllegalStateException(e.getMessage()); } if (nameBytes.length > MAX_ID_LENGTH) throw new IllegalArgumentException(idName + " is too long " + "(over " + MAX_ID_LENGTH + " bytes in UTF-8 encoding)."); if (id.equals(".") || id.equals("..")) throw new IllegalArgumentException(idName + " is invalid."); if (!containsValidChars(id)) throw new IllegalArgumentException(idName + " contains invalid characters."); }
/** * Returns the hash code value for this {@code StatusVariable}. The * hash code is calculated based on the full path, collection method and * value of the {@code StatusVariable}. * * @return the hash code of this object */ public int hashCode() { int hash = hashCode(id) ^ cm; switch (type) { case TYPE_INTEGER: return hash ^ intData; case TYPE_FLOAT: return hash ^ hashCode(new Float(floatData)); case TYPE_BOOLEAN: return hash ^ hashCode(new Boolean(booleanData)); case TYPE_STRING: return hash ^ hashCode(stringData); } return 0; // never reached }
/** * Compares the specified object with this {@code StatusVariable}. Two * {@code StatusVariable} objects are considered equal if their full path, * collection method and type are identical, and the data (selected by their * type) is equal. * * @param obj the object to compare with this {@code StatusVariable} * @return {@code true} if the argument represents the same * {@code StatusVariable} as this object */ @Override public boolean equals(Object obj) { if (!(obj instanceof StatusVariable)) return false; StatusVariable other = (StatusVariable) obj; if (!equals(id, other.id) || cm != other.cm || type != other.type) return false; switch (type) { case TYPE_INTEGER : return intData == other.intData; case TYPE_FLOAT : return floatData == other.floatData; case TYPE_STRING : return equals(stringData, other.stringData); case TYPE_BOOLEAN : return booleanData == other.booleanData; } return false; // never reached }
/** * Constructor for a <code>StatusVariable</code> of <code>int</code> * type. * * @param id the identifier of the <code>StatusVariable</code> * @param cm the collection method, one of the <code>CM_</code> constants * @param data the <code>int</code> value of the * <code>StatusVariable</code> * @throws java.lang.IllegalArgumentException if the given <code>id</code> * is not a valid <code>StatusVariable</code> name, or if * <code>cm</code> is not one of the collection method constants * @throws java.lang.NullPointerException if the <code>id</code> * parameter is <code>null</code> */ public StatusVariable(String id, int cm, int data) { setCommon(id, cm); type = TYPE_INTEGER; intData = data; }
private void setCommon(String id, int cm) throws IllegalArgumentException, NullPointerException { checkId(id, "StatusVariable ID"); if (cm != CM_CC && cm != CM_DER && cm != CM_GAUGE && cm != CM_SI) throw new IllegalArgumentException( "Unknown data collection method constant '" + cm + "'."); this.id = id; this.cm = cm; timeStamp = new Date(); }
private static void checkId(String id, String idName) throws IllegalArgumentException, NullPointerException { if (id == null) throw new NullPointerException(idName + " is null."); if (id.length() == 0) throw new IllegalArgumentException(idName + " is empty."); byte[] nameBytes; try { nameBytes = id.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { // never happens, "UTF-8" must always be supported throw new IllegalStateException(e.getMessage()); } if (nameBytes.length > MAX_ID_LENGTH) throw new IllegalArgumentException(idName + " is too long " + "(over " + MAX_ID_LENGTH + " bytes in UTF-8 encoding)."); if (id.equals(".") || id.equals("..")) throw new IllegalArgumentException(idName + " is invalid."); if (!containsValidChars(id)) throw new IllegalArgumentException(idName + " contains invalid characters."); }