Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 1996-2001
   * Logica Mobile Networks Limited
   * All rights reserved.
   *
   * This software is distributed under Logica Open Source License Version 1.0
   * ("Licence Agreement"). You shall use it and distribute only in accordance
   * with the terms of the License Agreement.
   *
  */
 package org.smpp.smscsim.util;
 
 import java.util.List;
The class Record represents a set of Attributes. It's used in Table class. It can represent various types of data, e.g. user settings, config parameters etc. When used in Table, different records might have different attributes -- attributes with different names.

Author(s):
Logica Mobile Networks SMPP Open Source Team
Version:
$Revision: 1.2 $
See also:
Table
Attribute
 
 public class Record {
The list of the attributes of this record.
 
 	private List<Attributeattributes = new LinkedList<Attribute>();

Only default constructor present -- the record is empty by default (doesn't contain any attributes).
 
 	public Record() {
 	}

Sets value of the attribute with given name to given value.

Parameters:
name the name (key) of the attribute to set
value the new value of the attribute
See also:
Attribute
 
 	public synchronized void set(String nameString value) {
 		Attribute attr = get(name);
 		if (attr == null) {
 			attr = new Attribute(name);
 			.add(attr);
 		}
 		attr.setValue(value);
 	}

Adds another attribute to the current record. If the attribute is already present in the record, replaces the value of the existing attribute with the value of the provided attribute. Note that this function makes a copy of the provided atribute.

Parameters:
attr the new attribute
See also:
Attribute
 
 	public synchronized void add(Attribute attr) {
 		Attribute existing = get(attr.getName());
 		if (existing != null) {
 			existing.setValue(attr.getValue());
 		} else {
 			.add(new Attribute(attr.getName(), attr.getValue()));
 		}
 	}

Finds an attribute with given name and returns it. If none is found, returns null.

Parameters:
name the name of the attribute to return
Returns:
the attribute whose key is equal to the provided key
See also:
Attribute
 
 	public synchronized Attribute get(String name) {
 		Attribute attr;
 		while (iter.hasNext()) {
 			attr = (Attributeiter.next();
 			if (attr.nameEquals(name)) {
 				return attr;
 			}
 		}
 		return null;
 	}

Returns the value of the attribute with given name. If the attribute is not present in the record, null is returned.

Parameters:
name the name of the attribute to return the value of
Returns:
the value of the atrribute
See also:
Attribute
	public synchronized String getValue(String name) {
		Attribute attr = get(name);
		if (attr != null) {
			return attr.getValue();
else {
			return null;
		}
	}

Return's the ith attribute from the record. The index must be in range 0 - count()-1. This is usefull for outputing the list of all attributes of the record in some way.

Parameters:
i the index of the attribute
Returns:
the attribute on the given position
See also:
get(java.lang.String)
Attribute
	public Attribute get(int i) {
		return (Attribute.get(i);
	}

Returns the count of attributes actually present in the record. Useful in conjuction with get(int).

Returns:
count of the attributes
See also:
get(int)
	public int count() {
		return .size();
	}

Removes an attribute with given name from the record. If the attribute isn't found, nothing will happen.

Parameters:
name the name of attribute to remove
	public synchronized void remove(String name) {
		Attribute toRemove = get(name);
		if (toRemove != null) {
			.remove(toRemove);
		}
	}
/*
 * $Log: not supported by cvs2svn $
 * Revision 1.1  2003/07/23 00:28:39  sverkera
 * Imported
 *
 */
New to GrepCode? Check out our FAQ X