gpt4 book ai didi

java - 在属性文件中查找重复键和值的工具

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:00:43 46 4
gpt4 key购买 nike

有没有一种工具可以告诉我一个或多个属性文件中的冗余键和值。

最佳答案

/**
* Purpose: Properties doesn't detect duplicate keys. So this exists.
* @author shaned
*/
package com.naehas.tests.configs;

import java.util.Properties;

import org.apache.log4j.Logger;

public class NaehasProperties extends Properties
{
private static final long serialVersionUID = 1L;

private static final Logger log = Logger.getLogger(NaehasProperties.class);

public NaehasProperties()
{
super();
}

/**
* @param defaults
*/
public NaehasProperties(Properties defaults)
{
super(defaults);
}

/**
* Overriding the HastTable put() so we can check for duplicates
*
*/
public synchronized Object put(Object key, Object value)
{
// Have we seen this key before?
//
if (get(key) != null)
{
StringBuffer message = new StringBuffer("Duplicate key found: " + key + " with value: " + value);
message.append(". Original value is: " + (String) get(key));

log.error(message.toString());

// Setting key to null will generate an exception and cause an exit.
// Can not change the signature by adding a throws as it's not compatible
// with HashTables put().
//
// If you commented out this line, you will see all the occurrences of the duplicate key
// as the put will overwrite the past encounter.
//
key = null;
}

return super.put(key, value);
}
}

关于java - 在属性文件中查找重复键和值的工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1779196/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com