Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2008 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.List;
 import java.util.Map;
 import java.util.Set;
 
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
Juergen Hoeller
Rob Harrop
Since:
13 May 2001
 
 public class MutablePropertyValues implements PropertyValuesSerializable {

List of PropertyValue objects
 
 	private final List propertyValueList;
 
 
 	private volatile boolean converted = false;


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:
original the PropertyValues to copy
See also:
addPropertyValues(org.springframework.beans.PropertyValues)
 
 	public MutablePropertyValues(PropertyValues original) {
 		// We can optimize this because it's all new:
 		// There is no replacement of existing property values.
 		if (original != null) {
 			PropertyValue[] pvs = original.getPropertyValues();
 			this. = new ArrayList(pvs.length);
 			for (int i = 0; i < pvs.lengthi++) {
 				PropertyValue newPv = new PropertyValue(pvs[i]);
 				this..add(newPv);
 			}
 		}
 		else {
 			this. = new ArrayList(0);
 		}
 	}

Construct a new MutablePropertyValues object from a Map.

Parameters:
original Map with property values keyed by property name Strings
See also:
addPropertyValues(java.util.Map)
 
 	public MutablePropertyValues(Map original) {
 		// We can optimize this because it's all new:
 		// There is no replacement of existing property values.
 		if (original != null) {
 			this. = new ArrayList(original.size());
 			Iterator it = original.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);
		}
	}

Construct a new MutablePropertyValues object using the given List of PropertyValue objects as-is.

This is a constructor for advanced usage scenarios. It is not intended for typical programmatic use.

Parameters:
propertyValueList List of PropertyValue objects
	public MutablePropertyValues(List propertyValueList) {
		this. = (propertyValueList != null ? propertyValueList : new ArrayList());
	}


Return the underlying List of PropertyValue objects in its raw form. The returned List can be modified directly, although this is not recommended.

This is an accessor for optimized access to all PropertyValue objects. It is not intended for typical programmatic use.

		return this.;
	}

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:
other the PropertyValues to copy
Returns:
this object to allow creating objects, adding multiple PropertyValues in a single statement
		if (other != null) {
			PropertyValue[] pvs = other.getPropertyValues();
			for (int i = 0; i < pvs.lengthi++) {
				PropertyValue newPv = new PropertyValue(pvs[i]);
			}
		}
		return this;
	}

Add all property values from the given Map.

Parameters:
other 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 (other != null) {
			Iterator it = other.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())) {
				pv = mergeIfRequired(pvcurrentPv);
				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));
	}

Modify a PropertyValue object held in this object. Indexed from 0.
	public void setPropertyValueAt(PropertyValue pvint i) {
		this..set(ipv);
	}

Merges the value of the supplied 'new' PropertyValue with that of the current PropertyValue if merging is supported and enabled.

See also:
Mergeable
	private PropertyValue mergeIfRequired(PropertyValue newPvPropertyValue currentPv) {
		Object value = newPv.getValue();
		if (value instanceof Mergeable) {
			Mergeable mergeable = (Mergeablevalue;
			if (mergeable.isMergeEnabled()) {
				Object merged = mergeable.merge(currentPv.getValue());
				return new PropertyValue(newPv.getName(), merged);
			}
		}
		return newPv;
	}

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) {
	}

Remove the given PropertyValue, if contained.

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

Clear this holder, removing all PropertyValues.
	public void clear() {
	}
		return (PropertyValue[])
	}
	public PropertyValue getPropertyValue(String propertyName) {
		for (int i = 0; i < this..size(); i++) {
			if (pv.getName().equals(propertyName)) {
				return pv;
			}
		}
		return null;
	}

Register the specified property as "processed" in the sense of some processor calling the corresponding setter method outside of the PropertyValue(s) mechanism.

This will lead to true being returned from a contains(java.lang.String) call for the specified property.

Parameters:
propertyName the name of the property.
	public void registerProcessedProperty(String propertyName) {
		if (this. == null) {
		}
		this..add(propertyName);
	}
	public boolean contains(String propertyName) {
		return (getPropertyValue(propertyName) != null ||
				(this. != null && this..contains(propertyName)));
	}
	public boolean isEmpty() {
		return this..isEmpty();
	}
	public int size() {
		return this..size();
	}
		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;
	}


Mark this holder as containing converted values only (i.e. no runtime resolution needed anymore).
	public void setConverted() {
		this. = true;
	}

Return whether this holder contains converted values only (true), or whether the values still need to be converted (false).
	public boolean isConverted() {
		return this.;
	}
	public boolean equals(Object other) {
		if (this == other) {
			return true;
		}
		if (!(other instanceof MutablePropertyValues)) {
			return false;
		}
		return this..equals(that.propertyValueList);
	}
	public int hashCode() {
	}
	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