is there a tool that tells me redundant keys and values that are there in my one or many 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.
ArrayList allows duplicate values while HashSet doesn't allow duplicates values.
/**
* 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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With