Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2005 the original author or authors.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.springframework.beans;
 
 import java.util.Map;
 
Default implementation of the PropertyValues interface. Allows simple manipulation of properties, and provides constructors to support deep copy and construction from a Map.

Author(s):
Rod Johnson
Since:
13 May 2001
 
 public class MutablePropertyValues implements PropertyValuesSerializable {

List of PropertyValue objects
 
 	private final ArrayList propertyValueList;

Creates a new empty MutablePropertyValues object. Property values can be added with the addPropertyValue methods.

 
 	public MutablePropertyValues() {
 		this. = new ArrayList();
 	}

Deep copy constructor. Guarantees PropertyValue references are independent, although it can't deep copy objects currently referenced by individual PropertyValue objects.

Parameters:
source the PropertyValues to copy
See also:
addPropertyValues(org.springframework.beans.PropertyValues)
 
 		// We can optimize this because it's all new:
 		// There is no replacement of existing property values.
 		if (source != null) {
 			PropertyValue[] pvs = source.getPropertyValues();
 			this. = new ArrayList(pvs.length);
 			for (int i = 0; i < pvs.lengthi++) {
 				PropertyValue newPv = new PropertyValue(pvs[i].getName(), pvs[i].getValue());
 				this..add(newPv);
 			}
 		}
 		else {
 			this. = new ArrayList(0);
 		}
 	}

Construct a new PropertyValues object from a Map.

Parameters:
source Map with property values keyed by property name, which must be a String
See also:
addPropertyValues(java.util.Map)
 
 	public MutablePropertyValues(Map source) {
 		// We can optimize this because it's all new:
 		// There is no replacement of existing property values.
 		if (source != null) {
 			this. = new ArrayList(source.size());
 			Iterator it = source.entrySet().iterator();
 			while (it.hasNext()) {
 				Map.Entry entry = (Map.Entryit.next();
 				PropertyValue newPv = new PropertyValue((Stringentry.getKey(), entry.getValue());
 				this..add(newPv);
 			}
 		}
 		else {
 			this. = new ArrayList(0);
 		}
 	}

Copy all given PropertyValues into this object. Guarantees PropertyValue references are independent, although it can't deep copy objects currently referenced by individual PropertyValue objects.

Parameters:
source the PropertyValues to copy
Returns:
this object to allow creating objects, adding multiple PropertyValues in a single statement
		if (source != null) {
			PropertyValue[] pvs = source.getPropertyValues();
			for (int i = 0; i < pvs.lengthi++) {
				PropertyValue newPv = new PropertyValue(pvs[i].getName(), pvs[i].getValue());
			}
		}
		return this;
	}

Add all property values from the given Map.

Parameters:
source Map with property values keyed by property name, which must be a String
Returns:
this object to allow creating objects, adding multiple PropertyValues in a single statement
		if (source != null) {
			Iterator it = source.entrySet().iterator();
			while (it.hasNext()) {
				Map.Entry entry = (Map.Entryit.next();
				PropertyValue newPv = new PropertyValue((Stringentry.getKey(), entry.getValue());
			}
		}
		return this;
	}

Add a PropertyValue object, replacing any existing one for the corresponding property.

Parameters:
pv PropertyValue object to add
Returns:
this object to allow creating objects, adding multiple PropertyValues in a single statement
		for (int i = 0; i < this..size(); i++) {
			if (currentPv.getName().equals(pv.getName())) {
				return this;
			}
		}
		return this;
	}

Overloaded version of addPropertyValue that takes a property name and a property value.

Parameters:
propertyName name of the property
propertyValue value of the property
See also:
addPropertyValue(org.springframework.beans.PropertyValue)
	public void addPropertyValue(String propertyNameObject propertyValue) {
		addPropertyValue(new PropertyValue(propertyNamepropertyValue));
	}

Remove the given PropertyValue, if contained.

Parameters:
pv the PropertyValue to remove
	public void removePropertyValue(PropertyValue pv) {
	}

Overloaded version of removePropertyValue that takes a property name.

Parameters:
propertyName name of the property
See also:
removePropertyValue(org.springframework.beans.PropertyValue)
	public void removePropertyValue(String propertyName) {
	}

Modify a PropertyValue object held in this object. Indexed from 0.
	public void setPropertyValueAt(PropertyValue pvint i) {
		this..set(ipv);
	}
		return (PropertyValue[])
	}
	public PropertyValue getPropertyValue(String propertyName) {
		for (int i = 0; i < this..size(); i++) {
			if (pv.getName().equals(propertyName)) {
				return pv;
			}
		}
		return null;
	}
	public boolean contains(String propertyName) {
		return (getPropertyValue(propertyName) != null);
	}
		if (old == this) {
			return changes;
		}
		// for each property value in the new set
		for (Iterator it = this..iterator(); it.hasNext();) {
			PropertyValue newPv = (PropertyValueit.next();
			// if there wasn't an old one, add it
			PropertyValue pvOld = old.getPropertyValue(newPv.getName());
			if (pvOld == null) {
				changes.addPropertyValue(newPv);
			}
			else if (!pvOld.equals(newPv)) {
				// it's changed
				changes.addPropertyValue(newPv);
			}
		}
		return changes;
	}
	public String toString() {
		StringBuffer sb = new StringBuffer("PropertyValues: length=" + pvs.length + "; ");
		sb.append(StringUtils.arrayToDelimitedString(pvs"; "));
		return sb.toString();
	}
New to GrepCode? Check out our FAQ X