Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool to find duplicate keys and value in properties file

is there a tool that tells me redundant keys and values that are there in my one or many properties file.

like image 629
Santosh Gokak Avatar asked Nov 22 '09 16:11

Santosh Gokak


People also ask

How to find duplicate keys in properties file?

Simple and easy way..get codePro AnalytiX from google, its a eclipse plugin. You can audit your code, it will find all the duplicate key in properties file.

Which collection can have duplicate keys?

ArrayList allows duplicate values while HashSet doesn't allow duplicates values.


1 Answers

/**
 *  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);
   }
}
like image 94
Shane Avatar answered Nov 15 '22 00:11

Shane