63 Star 428 Fork 156

huifer/Code-Analysis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
docs
beans
AbstractNestablePropertyAccessor
BeanDefinition
BeanInfoFactory
BeanMetadataElement
BeanReference
Mergeable
images
Readme.md
Spring-AliasDefinition.md
Spring-AutowireCandidateQualifier.md
Spring-BeanComponentDefinition.md
Spring-BeanDefinitionHolder.md
Spring-BeanMetadataAttribute.md
Spring-ConstructorArgumentValues.ValueHolder.md
Spring-DocumentDefaultsDefinition.md
Spring-ImportDefinition.md
Spring-ManagedList.md
Spring-ManagedMap.md
Spring-ManagedProperties.md
Spring-ManagedSet.md
Spring-MethodOverride.md
Spring-TypedStringValue.md
BeanWrapper
CachedIntrospectionResults
ComponentDefinition
ConfigurablePropertyAccessor
GenericTypeAwarePropertyDescriptor
Property
PropertyAccessor
Scope
factory
propertyEditor
register
core
env
other
utils
release
.gitattributes
.gitignore
CHANGELOG.MD
LICENSE
Notice
README.md
_coverpage.md
index.html
summary.md
todo.md
克隆/下载
Spring-ManagedSet.md 1.27 KB
一键复制 编辑 原始数据 按行查看 历史

Spring ManagedSet

  • 类全路径: org.springframework.beans.factory.support.ManagedSet

  • 类图: ManagedSet.png

  • 对应标签 <set>

      <property name="someSet">
          <set>
              <value>just some string</value>
              <ref bean="myDataSource" />
          </set>
      </property>
    
    • 解析xml的处理方法: org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseSetElement 这里不做具体展开

方法列表

merge

  • ManagedSet 作为Mergeable的实现类, 其操作的对象为LinkedHashSet, 想到合并可以联想到 LinkedHashSet#addAll => java.util.Set.addAll Spring 中也正是如此进行操作的. 详细代码如下
	@Override
	@SuppressWarnings("unchecked")
	public Set<E> merge(@Nullable Object parent) {
		if (!this.mergeEnabled) {
			throw new IllegalStateException("Not allowed to merge when the 'mergeEnabled' property is set to 'false'");
		}
		if (parent == null) {
			return this;
		}
		if (!(parent instanceof Set)) {
			throw new IllegalArgumentException("Cannot merge with object of type [" + parent.getClass() + "]");
		}
		Set<E> merged = new ManagedSet<>();
		merged.addAll((Set<E>) parent);
		merged.addAll(this);
		return merged;
	}

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/pychfarm_admin/code-analysis.git
git@gitee.com:pychfarm_admin/code-analysis.git
pychfarm_admin
code-analysis
Code-Analysis
v0.0.15

搜索帮助