001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.beans; 018 019import java.util.Arrays; 020import java.util.Iterator; 021import java.util.Spliterator; 022import java.util.Spliterators; 023import java.util.stream.Stream; 024import java.util.stream.StreamSupport; 025 026import org.springframework.lang.Nullable; 027 028/** 029 * Holder containing one or more {@link PropertyValue} objects, 030 * typically comprising one update for a specific target bean. 031 * 032 * @author Rod Johnson 033 * @author Juergen Hoeller 034 * @since 13 May 2001 035 * @see PropertyValue 036 */ 037public interface PropertyValues extends Iterable<PropertyValue> { 038 039 /** 040 * Return an {@link Iterator} over the property values. 041 * @since 5.1 042 */ 043 @Override 044 default Iterator<PropertyValue> iterator() { 045 return Arrays.asList(getPropertyValues()).iterator(); 046 } 047 048 /** 049 * Return a {@link Spliterator} over the property values. 050 * @since 5.1 051 */ 052 @Override 053 default Spliterator<PropertyValue> spliterator() { 054 return Spliterators.spliterator(getPropertyValues(), 0); 055 } 056 057 /** 058 * Return a sequential {@link Stream} containing the property values. 059 * @since 5.1 060 */ 061 default Stream<PropertyValue> stream() { 062 return StreamSupport.stream(spliterator(), false); 063 } 064 065 /** 066 * Return an array of the PropertyValue objects held in this object. 067 */ 068 PropertyValue[] getPropertyValues(); 069 070 /** 071 * Return the property value with the given name, if any. 072 * @param propertyName the name to search for 073 * @return the property value, or {@code null} if none 074 */ 075 @Nullable 076 PropertyValue getPropertyValue(String propertyName); 077 078 /** 079 * Return the changes since the previous PropertyValues. 080 * Subclasses should also override {@code equals}. 081 * @param old the old property values 082 * @return the updated or new properties. 083 * Return empty PropertyValues if there are no changes. 084 * @see Object#equals 085 */ 086 PropertyValues changesSince(PropertyValues old); 087 088 /** 089 * Is there a property value (or other processing entry) for this property? 090 * @param propertyName the name of the property we're interested in 091 * @return whether there is a property value for this property 092 */ 093 boolean contains(String propertyName); 094 095 /** 096 * Does this holder not contain any PropertyValue objects at all? 097 */ 098 boolean isEmpty(); 099 100}