📄 aid.java
字号:
public void addUserDefinedSlot(String key, String value){
userDefSlots.setProperty(key, value);
}
/**
* To remove a user defined slot.
* @param key the name of the property
* @return true if the property has been found and removed, false otherwise
*/
public boolean removeUserDefinedSlot(String key){
return (userDefSlots.remove(key) != null);
}
/**
* Returns an array of string containing all the addresses of the agent
*/
public String[] getAddressesArray() {
//#MIDP_EXCLUDE_BEGIN
Object[] objs = addresses.toArray();
String[] result = new String[objs.length];
System.arraycopy(objs, 0, result, 0, objs.length);
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
String[] result = new String[addresses.size()];
addresses.copyInto(result);
#MIDP_INCLUDE_END*/
return result;
}
// For persistence service
private void setAddressesArray(String[] arr) {
//#MIDP_EXCLUDE_BEGIN
addresses.clear();
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
addresses.removeAllElements();
#MIDP_INCLUDE_END*/
for(int i = 0; i < arr.length; i++) {
addAddresses(arr[i]);
}
}
/**
* Returns an array containing all the AIDs of the resolvers.
*/
public AID[] getResolversArray() {
//#MIDP_EXCLUDE_BEGIN
Object[] objs = resolvers.toArray();
AID[] result = new AID[objs.length];
System.arraycopy(objs, 0, result, 0, objs.length);
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
AID[] result = new AID[resolvers.size()];
resolvers.copyInto(result);
#MIDP_INCLUDE_END*/
return result;
}
// For persistence service
private void setResolversArray(AID[] arr) {
//#MIDP_EXCLUDE_BEGIN
resolvers.clear();
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
resolvers.removeAllElements();
#MIDP_INCLUDE_END*/
for(int i = 0; i < arr.length; i++) {
addResolvers(arr[i]);
}
}
/**
* Returns the user-defined slots as properties.
* @return all the user-defined slots as a <code>jade.util.leap.Properties</code> java Object.
* @see jade.util.leap.Properties
*/
public Properties getAllUserDefinedSlot(){
return userDefSlots;
}
/**
* Converts this agent identifier into a readable string.
* @return the String full representation of this AID
**/
public String toString() {
StringBuffer s = new StringBuffer("( agent-identifier ");
//#MIDP_EXCLUDE_BEGIN
jade.lang.acl.StringACLCodec.appendACLExpression(s,":name",name);
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
s.append(":name ");
s.append(SimpleSLTokenizer.isAWord(name) ? name : SimpleSLTokenizer.quoteString(name));
#MIDP_INCLUDE_END*/
if (addresses.size()>0)
s.append(" :addresses (sequence ");
for (int i=0; i<addresses.size(); i++)
try {
//#MIDP_EXCLUDE_BEGIN
s.append((String)addresses.get(i));
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
s.append((String)addresses.elementAt(i));
#MIDP_INCLUDE_END*/
s.append(" ");
}
catch (IndexOutOfBoundsException e) {e.printStackTrace();}
if (addresses.size()>0)
s.append(")");
if (resolvers.size()>0)
s.append(" :resolvers (sequence ");
for (int i=0; i<resolvers.size(); i++) {
try {
//#MIDP_EXCLUDE_BEGIN
s.append(resolvers.get(i).toString());
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
s.append(resolvers.elementAt(i).toString());
#MIDP_INCLUDE_END*/
}
catch (IndexOutOfBoundsException e) {e.printStackTrace();}
s.append(" ");
}
if (resolvers.size()>0)
s.append(")");
Enumeration e = userDefSlots.propertyNames();
String key, value;
while (e.hasMoreElements()) {
key = (String)e.nextElement();
value = userDefSlots.getProperty(key);
s.append(" :X-");
//#MIDP_EXCLUDE_BEGIN
jade.lang.acl.StringACLCodec.appendACLExpression(s,key,value);
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
s.append(key);
s.append(" ");
s.append(SimpleSLTokenizer.isAWord(value) ? value : SimpleSLTokenizer.quoteString(value));
#MIDP_INCLUDE_END*/
}
s.append(")");
return s.toString();
}
/**
* Clone the AID object.
*/
public synchronized Object clone() {
AID result = new AID(this.name, ISGUID);
result.persistentID = null;
//#MIDP_EXCLUDE_BEGIN
result.addresses = (ArrayList)((ArrayList)addresses).clone();
result.resolvers = (ArrayList)((ArrayList)resolvers).clone();
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
result.addresses = new Vector(addresses.size());
for (int i=0; i<addresses.size(); i++)
result.addresses.addElement(addresses.elementAt(i));
result.resolvers = new Vector(resolvers.size());
for (int i=0; i<resolvers.size(); i++)
result.resolvers.addElement(resolvers.elementAt(i));
#MIDP_INCLUDE_END*/
// Copying user defined slots
//Enumeration enum = userDefSlots.propertyNames();
//while (enum.hasMoreElements()) {
// String key = (String) enum.nextElement();
// result.addUserDefinedSlot(key,
// (String) userDefSlots.getProperty(key));
//}
result.userDefSlots = (Properties) userDefSlots.clone();
return result;
}
/**
Equality operation. This method compares an <code>AID</code> object with
another or with a Java <code>String</code>. The comparison is case
insensitive.
@param o The Java object to compare this <code>AID</code> to.
@return <code>true</code> if one of the following holds:
<ul>
<li> The argument <code>o</code> is an <code>AID</code> object
with the same <em>GUID</em> in its name slot (apart from
differences in case).
<li> The argument <code>o</code> is a <code>String</code> that is
equal to the <em>GUID</em> contained in the name slot of this
Agent ID (apart from differences in case).
</ul>
*/
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o instanceof AID) {
return CaseInsensitiveString.equalsIgnoreCase(name, ((AID) o).name);
}
if(o instanceof String) {
return CaseInsensitiveString.equalsIgnoreCase(name, (String)o);
}
return false;
}
/**
Comparison operation. This operation imposes a total order
relationship over Agent IDs.
@param o Another <code>AID</code> object, that will be compared
with the current <code>AID</code>.
@return -1, 0 or 1 according to the lexicographical order of the
<em>GUID</em> of the two agent IDs, apart from differences in
case.
*/
public int compareTo(Object o) {
AID id = (AID)o;
return name.toLowerCase().toUpperCase().compareTo(id.name.toLowerCase().toUpperCase());
}
/**
Hash code. This method returns an hash code in such a way that two
<code>AID</code> objects with equal names or with names differing
only in case have the same hash code.
@return The hash code for this <code>AID</code> object.
*/
public int hashCode() {
return hashCode;
}
/**
* Returns the local name of the agent (without the HAP).
* If the agent is not local, then the method returns its GUID.
*/
public String getLocalName() {
int atPos = name.lastIndexOf('@');
if(atPos == -1)
return name;
else
return name.substring(0, atPos);
}
/**
Returns the HAP of the agent or null if the GUID of this
<code>AID</code> is not of the form <local-name>@<platform-name>
*/
public String getHap() {
int atPos = name.lastIndexOf('@');
if(atPos == -1)
return null;
else
return name.substring(atPos + 1);
}
// For persistence service
private transient Long persistentID;
// For persistence service
private Long getPersistentID() {
return persistentID;
}
// For persistence service
private void setPersistentID(Long l) {
persistentID = l;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -