/** * 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; }
/** * 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 }
/** * Determines if the specified permission is implied by this permission. * <p> * This method returns {@code false} if and only if at least one of the * following conditions are fulfilled for the specified permission: * <ul> * <li>it is not a {@code MonitorPermission}</li> * <li>it has a broader set of actions allowed than this one</li> * <li>it allows initiating time based monitoring jobs with a lower minimal * sampling interval</li> * <li>the target set of {@code Monitorable}s is not the same nor a subset * of the target set of {@code Monitorable}s of this permission</li> * <li>the target set of {@code StatusVariable}s is not the same nor a * subset of the target set of {@code StatusVariable}s of this permission</li> * </ul> * * @param p the permission to be checked * @return {@code true} if the given permission is implied by this * permission */ public boolean implies(Permission p) { if (!(p instanceof MonitorPermission)) return false; MonitorPermission other = (MonitorPermission) p; if ((mask & other.mask) != other.mask) return false; if ((other.mask & STARTJOB_FLAG) != 0 && minJobInterval > other.minJobInterval) return false; return implies(monId, prefixMonId, other.monId, other.prefixMonId) && implies(varId, prefixVarId, other.varId, other.prefixVarId); }
varId = statusVariable.substring(sep + 1, prefixVarId ? len - 1 : len); checkId(monId, "Monitorable ID part of the target"); checkId(varId, "Status Variable ID part of the target"); String action = st.nextToken().trim(); if (action.equalsIgnoreCase(READ)) { addToMask(READ_FLAG, READ); } else if (action.equalsIgnoreCase(RESET)) { addToMask(RESET_FLAG, RESET); } else if (action.equalsIgnoreCase(PUBLISH)) { addToMask(PUBLISH_FLAG, PUBLISH); } else if (action.equalsIgnoreCase(SWITCHEVENTS)) { addToMask(SWITCHEVENTS_FLAG, SWITCHEVENTS); } else if (action.toLowerCase().startsWith(STARTJOB)) { addToMask(STARTJOB_FLAG, STARTJOB); } else throw new IllegalArgumentException("Invalid action '" + action + "'");
/** * Get the action string associated with this permission. The actions are * returned in the following order: {@code read}, {@code reset}, * {@code publish}, {@code startjob}, {@code switchevents}. * * @return the allowed actions separated by commas, cannot be {@code null} */ public String getActions() { StringBuffer sb = new StringBuffer(); appendAction(sb, READ_FLAG, READ); appendAction(sb, RESET_FLAG, RESET); appendAction(sb, PUBLISH_FLAG, PUBLISH); appendAction(sb, STARTJOB_FLAG, STARTJOB); appendAction(sb, SWITCHEVENTS_FLAG, SWITCHEVENTS); return sb.toString(); }
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(); }
/** * 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 }
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."); }
/** * 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; }
/** * Get the action string associated with this permission. The actions are * returned in the following order: <code>read</code>, <code>reset</code>, * <code>publish</code>, <code>startjob</code>, <code>switchevents</code>. * * @return the allowed actions separated by commas, cannot be * <code>null</code> */ public String getActions() { StringBuffer sb = new StringBuffer(); appendAction(sb, READ_FLAG, READ); appendAction(sb, RESET_FLAG, RESET); appendAction(sb, PUBLISH_FLAG, PUBLISH); appendAction(sb, STARTJOB_FLAG, STARTJOB); appendAction(sb, SWITCHEVENTS_FLAG, SWITCHEVENTS); return sb.toString(); }
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(); }
/** * 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 }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Constructor for a <code>StatusVariable</code> of <code>boolean</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>boolean</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, boolean data) { setCommon(id, cm); type = TYPE_BOOLEAN; booleanData = data; }
/** * Constructor for a <code>StatusVariable</code> of <code>String</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>String</code> value of the * <code>StatusVariable</code>, can be <code>null</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, String data) { setCommon(id, cm); type = TYPE_STRING; stringData = data; }
/** * Constructor for a <code>StatusVariable</code> of <code>float</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>float</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, float data) { setCommon(id, cm); type = TYPE_FLOAT; floatData = data; }