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

标签 java internationalization

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

最佳答案

/**
 *  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/

相关文章:

postgresql - 无法从 postgres 全文搜索中获得正确的结果

unicode - 如何检查字素是否是字母?

android - 在 TextView 中显示日语而不是中文

java - nginx - 我可以在哪里放置 client_max_body_size 属性?

Java 图形用户界面 : Can the JLabel hold an object/class?

c# - ASP.NET MVC,授权后设置文化

qt - lupdate 没有从 QObject 对象获取 tr() 字符串

java - 创建项目时 Eclipse Oxygen 上的 Maven 出现 "Could not resolve archetype"错误

java - LinkedList 上的 removeFirst() remove(0) 之间的区别?

java - 安卓.view.WindowManager$BadTokenException : Unable to add window -- token null is not for an application