spring复习:(29)MutablePropertyValues

该类通过成员变量 propertyValueList 来保存多个PropertyValue对象。

public class MutablePropertyValues implements PropertyValues, Serializable {private final List<PropertyValue> propertyValueList;@Nullableprivate Set<String> processedProperties;private volatile boolean converted = false;/*** Creates a new empty MutablePropertyValues object.* <p>Property values can be added with the {@code add} method.* @see #add(String, Object)*/public MutablePropertyValues() {this.propertyValueList = new ArrayList<>(0);}/*** Deep copy constructor. Guarantees PropertyValue references* are independent, although it can't deep copy objects currently* referenced by individual PropertyValue objects.* @param original the PropertyValues to copy* @see #addPropertyValues(PropertyValues)*/public MutablePropertyValues(@Nullable 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.propertyValueList = new ArrayList<>(pvs.length);for (PropertyValue pv : pvs) {this.propertyValueList.add(new PropertyValue(pv));}}else {this.propertyValueList = new ArrayList<>(0);}}/*** Construct a new MutablePropertyValues object from a Map.* @param original a Map with property values keyed by property name Strings* @see #addPropertyValues(Map)*/public MutablePropertyValues(@Nullable Map<?, ?> original) {// We can optimize this because it's all new:// There is no replacement of existing property values.if (original != null) {this.propertyValueList = new ArrayList<>(original.size());original.forEach((attrName, attrValue) -> this.propertyValueList.add(new PropertyValue(attrName.toString(), attrValue)));}else {this.propertyValueList = new ArrayList<>(0);}}/*** Construct a new MutablePropertyValues object using the given List of* PropertyValue objects as-is.* <p>This is a constructor for advanced usage scenarios.* It is not intended for typical programmatic use.* @param propertyValueList a List of PropertyValue objects*/public MutablePropertyValues(@Nullable List<PropertyValue> propertyValueList) {this.propertyValueList =(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.* <p>This is an accessor for optimized access to all PropertyValue objects.* It is not intended for typical programmatic use.*/public List<PropertyValue> getPropertyValueList() {return this.propertyValueList;}/*** Return the number of PropertyValue entries in the list.*/public int size() {return this.propertyValueList.size();}/*** 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.* @param other the PropertyValues to copy* @return this in order to allow for adding multiple property values in a chain*/public MutablePropertyValues addPropertyValues(@Nullable PropertyValues other) {if (other != null) {PropertyValue[] pvs = other.getPropertyValues();for (PropertyValue pv : pvs) {addPropertyValue(new PropertyValue(pv));}}return this;}/*** Add all property values from the given Map.* @param other a Map with property values keyed by property name,* which must be a String* @return this in order to allow for adding multiple property values in a chain*/public MutablePropertyValues addPropertyValues(@Nullable Map<?, ?> other) {if (other != null) {other.forEach((attrName, attrValue) -> addPropertyValue(new PropertyValue(attrName.toString(), attrValue)));}return this;}/*** Add a PropertyValue object, replacing any existing one for the* corresponding property or getting merged with it (if applicable).* @param pv the PropertyValue object to add* @return this in order to allow for adding multiple property values in a chain*/public MutablePropertyValues addPropertyValue(PropertyValue pv) {for (int i = 0; i < this.propertyValueList.size(); i++) {PropertyValue currentPv = this.propertyValueList.get(i);if (currentPv.getName().equals(pv.getName())) {pv = mergeIfRequired(pv, currentPv);setPropertyValueAt(pv, i);return this;}}this.propertyValueList.add(pv);return this;}/*** Overloaded version of {@code addPropertyValue} that takes* a property name and a property value.* <p>Note: As of Spring 3.0, we recommend using the more concise* and chaining-capable variant {@link #add}.* @param propertyName name of the property* @param propertyValue value of the property* @see #addPropertyValue(PropertyValue)*/public void addPropertyValue(String propertyName, Object propertyValue) {addPropertyValue(new PropertyValue(propertyName, propertyValue));}/*** Add a PropertyValue object, replacing any existing one for the* corresponding property or getting merged with it (if applicable).* @param propertyName name of the property* @param propertyValue value of the property* @return this in order to allow for adding multiple property values in a chain*/public MutablePropertyValues add(String propertyName, @Nullable Object propertyValue) {addPropertyValue(new PropertyValue(propertyName, propertyValue));return this;}/*** Modify a PropertyValue object held in this object.* Indexed from 0.*/public void setPropertyValueAt(PropertyValue pv, int i) {this.propertyValueList.set(i, pv);}/*** Merges the value of the supplied 'new' {@link PropertyValue} with that of* the current {@link PropertyValue} if merging is supported and enabled.* @see Mergeable*/private PropertyValue mergeIfRequired(PropertyValue newPv, PropertyValue currentPv) {Object value = newPv.getValue();if (value instanceof Mergeable) {Mergeable mergeable = (Mergeable) value;if (mergeable.isMergeEnabled()) {Object merged = mergeable.merge(currentPv.getValue());return new PropertyValue(newPv.getName(), merged);}}return newPv;}/*** Remove the given PropertyValue, if contained.* @param pv the PropertyValue to remove*/public void removePropertyValue(PropertyValue pv) {this.propertyValueList.remove(pv);}/*** Overloaded version of {@code removePropertyValue} that takes a property name.* @param propertyName name of the property* @see #removePropertyValue(PropertyValue)*/public void removePropertyValue(String propertyName) {this.propertyValueList.remove(getPropertyValue(propertyName));}@Overridepublic Iterator<PropertyValue> iterator() {return Collections.unmodifiableList(this.propertyValueList).iterator();}@Overridepublic Spliterator<PropertyValue> spliterator() {return Spliterators.spliterator(this.propertyValueList, 0);}@Overridepublic Stream<PropertyValue> stream() {return this.propertyValueList.stream();}@Overridepublic PropertyValue[] getPropertyValues() {return this.propertyValueList.toArray(new PropertyValue[0]);}@Override@Nullablepublic PropertyValue getPropertyValue(String propertyName) {for (PropertyValue pv : this.propertyValueList) {if (pv.getName().equals(propertyName)) {return pv;}}return null;}/*** Get the raw property value, if any.* @param propertyName the name to search for* @return the raw property value, or {@code null} if none found* @since 4.0* @see #getPropertyValue(String)* @see PropertyValue#getValue()*/@Nullablepublic Object get(String propertyName) {PropertyValue pv = getPropertyValue(propertyName);return (pv != null ? pv.getValue() : null);}@Overridepublic PropertyValues changesSince(PropertyValues old) {MutablePropertyValues changes = new MutablePropertyValues();if (old == this) {return changes;}// for each property value in the new setfor (PropertyValue newPv : this.propertyValueList) {// if there wasn't an old one, add itPropertyValue pvOld = old.getPropertyValue(newPv.getName());if (pvOld == null || !pvOld.equals(newPv)) {changes.addPropertyValue(newPv);}}return changes;}@Overridepublic boolean contains(String propertyName) {return (getPropertyValue(propertyName) != null ||(this.processedProperties != null && this.processedProperties.contains(propertyName)));}@Overridepublic boolean isEmpty() {return this.propertyValueList.isEmpty();}/*** Register the specified property as "processed" in the sense* of some processor calling the corresponding setter method* outside of the PropertyValue(s) mechanism.* <p>This will lead to {@code true} being returned from* a {@link #contains} call for the specified property.* @param propertyName the name of the property.*/public void registerProcessedProperty(String propertyName) {if (this.processedProperties == null) {this.processedProperties = new HashSet<>(4);}this.processedProperties.add(propertyName);}/*** Clear the "processed" registration of the given property, if any.* @since 3.2.13*/public void clearProcessedProperty(String propertyName) {if (this.processedProperties != null) {this.processedProperties.remove(propertyName);}}/*** Mark this holder as containing converted values only* (i.e. no runtime resolution needed anymore).*/public void setConverted() {this.converted = true;}/*** Return whether this holder contains converted values only ({@code true}),* or whether the values still need to be converted ({@code false}).*/public boolean isConverted() {return this.converted;}@Overridepublic boolean equals(@Nullable Object other) {return (this == other || (other instanceof MutablePropertyValues &&this.propertyValueList.equals(((MutablePropertyValues) other).propertyValueList)));}@Overridepublic int hashCode() {return this.propertyValueList.hashCode();}@Overridepublic String toString() {PropertyValue[] pvs = getPropertyValues();if (pvs.length > 0) {return "PropertyValues: length=" + pvs.length + "; " + StringUtils.arrayToDelimitedString(pvs, "; ");}return "PropertyValues: length=0";}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/3012.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SQL进阶(2)——SQL语句类型 增删改查CRUD 事务初步 表关联关系 视图 +索引

目录 引出SQL语句类型1.DML数据操纵语言&#xff08;重点&#xff09;2.DQL数据查询语言&#xff08;重点&#xff09;3.DDL(Data Definition Language了解)4.DCL(Data Control Language了解)5.TCL 事务控制语言 运算符和其他函数1.运算符2.其它函数增删改查CRUD 视图索引事务1…

基于Python的用户和项目协同过滤算法实现与解析——以余弦相似度和最近邻居为基础的推荐系统构建

基于Python的用户和项目协同过滤算法实现与解析——以余弦相似度和最近邻居为基础的推荐系统构建 摘要 本篇文章主要讲解如何使用Python来编写基于用户的协同过滤算法和基于项目的协同过滤算法。我们首先了解这两种协同过滤算法的概念和原理,接着通过Python代码实现这两种算…

如何克服Leetcode做题的困境

文章目录 如何克服Leetcode做题的困境问题背景克服困境的建议实践与理论结合切忌死记硬背分析解题思路不要过早看答案迭代式学习寻求帮助坚持与耐心查漏补缺 结论 如何克服Leetcode做题的困境 问题背景 明明自觉学会了不少知识&#xff0c;可真正开始做Leetcode题目时&#x…

内存参数问题导致内存溢出

问题&#xff1a;内存参数问题导致内存溢出 1、文件过大&#xff0c;进行分块 2、 运行参数&#xff0c;使用最大内存配置2时&#xff0c;导致空指针异常。 3、获取详细报错信息-内存溢出 多线程捕获Throwable异常 修改代码&#xff0c;捕获Throwable&#xff0c;获取异常 异…

vue中预览pdf

情况一 如果后端返回的pdf地址&#xff0c;粘贴到浏览器的url框中&#xff0c;可以在浏览器中直接进行预览的&#xff0c;那么我们就用window.open&#xff0c;或 a标签&#xff0c;或iframe标签通过设置src进行预览即可 法1&#xff1a;可以直接使用window.open&#xff08;…

leetcode100.相同的树

⭐️ 题目描述 &#x1f31f; leetcode链接&#xff1a;相同的树 1️⃣ 代码&#xff1a; bool isSameTree(struct TreeNode* p, struct TreeNode* q){// 判断两棵树当前结点是否为空if (p NULL && q NULL) {// 说明是相同的return true;}// 来到这里有几种情况// …

【裸辞转行】是告别,也是新的开始

一年多了没有更新&#xff0c;是因为去年身体加心理因素辞职了&#xff0c;并且大概率不会再做程序员了&#xff0c;嗯。本来觉得可能再也不会打开 CSDN 了&#xff0c;想了想&#xff0c;还是来做个告别吧&#xff0c;任何事情都该有始有终才对。 回忆碎碎念 是在去年的 11 …

【实战篇】docker-compose部署go项目

一、场景&#xff1a; 二、需求 三、实操 Stage 1&#xff1a;GoLand 中 build 生成二进制文件 Stage 2&#xff1a;编写 Dockerfile Stage 3&#xff1a;编写 docker-compose.yaml Stage 4&#xff1a;文件上传到 ubuntu 服务器上&#xff0c;并设置文件读写权限 Stage…

前端 | (二)各种各样的常用标签 | 尚硅谷前端html+css零基础教程2023最新

学习来源&#xff1a;尚硅谷前端htmlcss零基础教程&#xff0c;2023最新前端开发html5css3视频 文章目录 &#x1f4da;HTML排版标签&#x1f4da;HTML语义化标签&#x1f4da;块级元素与行内元素&#x1f4da;文本标签&#x1f407;常用的文本标签&#x1f407;不常用的文本标…

erlang 虚拟机优化参数

sbwt none 将CPU忙等待关闭将有助于降低系统显示的CPU使用率&#xff0c;因为开启了忙等待的BEAM&#xff0c;CPU负载并不代表真实的工作情况&#xff1b; K true 开启epoll IO模型 swt low Sets scheduler wakeup threshold. Defaults to medium. The thresh…

Kubernetes Service的过程

文章目录 Kubernetes Service的实现基础内容1. 命令 ip route show table all2. DNAT3. IPVS和iptables4. Service Service的实现简述 Kubernetes Service的实现 基础内容 在了解Service之前,需要先了解一些额外的知识: 命令: ip route show table allDNATIPVS和iptables基础…

idea不小心push的文件夹怎么处理?

第一种方式&#xff0c;把不小心push上去的人解决掉。 第二种方式&#xff0c;以我自身为例&#xff0c;同事不小心push了.idea文件夹 首先打开git bash git rm --cached .idea/ -r 然后查看一下状态 git status 接着提交修改 git commit -m "cancel track .idea file&q…

【Redis】高可用之三:集群(cluster)

本文是Redis系列第6篇&#xff0c;前5篇欢迎移步 【Redis】不卡壳的 Redis 学习之路&#xff1a;从十大数据类型开始入手_AQin1012的博客-CSDN博客关于Redis的数据类型&#xff0c;各个文章总有些小不同&#xff0c;我们这里讨论的是Redis 7.0&#xff0c;为确保准确&#xf…

linux编程-telnet

我是使用WSL的linux系统与主机windows系统进行通信。 1.安装telnet linux&#xff1a; 在终端中运行以下命令&#xff1a; sudo apt-get install telnet windows&#xff1a; 在命令行中运行以下命令&#xff1a; DISM /Online /Enable-Feature /FeatureName:TelnetClien…

【代码随想录刷题记录】 647. 回文子串 、 516.最长回文子序列

647. 回文子串 1、题目 给你一个字符串 s &#xff0c;请你统计并返回这个字符串中 回文子串 的数目。 题目链接&#xff1a;https://leetcode.cn/problems/palindromic-substrings/ 2、代码 class Solution { public: //判断字符串是否为回文bool IsPalindrome(string s, …

Linux基础(三)端口、进程及主机状态管理、环境变量、文件管理

目录 端口 nmap netstat 进程管理 查看进程 关闭进程 主机状态监控 系统资源top命令 磁盘信息监控 网络状态监控 环境变量 $符号 自己设置环境变量 自定义环境变量PATH Linux的文件和下载 压缩和解压 tar命令 zip和unzip命令 端口 每个电脑有一个ip地址&#xff…

Vue项目实现在线预览pdf,并且可以批量打印pdf

最近遇到一个需求,就是要在页面上呈现pdf内容,并且还能用打印机批量打印pdf,最终效果如下: 当用户在列表页面,勾选中两条数据后,点击“打印表单”按钮之后,会跳到如下的预览页面: 预览页面顶部有个吸顶的效果,然后下方就展示出了2个pdf文件对应的内容,我们接着点击“…

echarts 地图点击常见问题

echats 散点图不支持缩放 echarts 地图点击激活label如何去除 高德loca 1.4版本热力图报错 绘制的颜色区间是 0 --1 高德地图销毁不生效 自己傻逼&#xff0c;每次没有清空数组导致叠加数据&#xff0c;约点数据越多。 为何用高德地图district.search查询不到别的省数据&…

[微信小程序] movable-view 可移动视图容器 - 范围问题

movable-view 可移动视图容器 可移动视图容器&#xff0c;在页面中可以拖拽滑动。movable-view必须在 movable-area 组件中&#xff0c;并且必须是直接子节点 <view><movable-area style"width: 750rpx;height: 200rpx;background-color: gainsboro;">&l…

Java的数据结构-Map集合

文章目录 Map概述Map常用方法Map遍历元素的方法1.方法一&#xff1a;keySet()2.方法二&#xff1a;entrySet() HashMap Map概述 1、Map和collection没有继承关系2、Map集合以key和value的方式存储数据&#xff1a;键值对key和value都是引用数据类型。key和value都是存储对象的…