Class PropDiff

java.lang.Object
  |
  +--PropDiff

public class PropDiff
extends java.lang.Object

PropDiff is a utility for comparing and combining property files that can find the union, intersection, and difference. See java.util.Properties for more information about property files.

Run this with no arguments to see the usage/help that looks like:

 Usage: [flags] properties-file1 properties-file2 [-f filenameOrPathPrefixForResults]
   flags:
     -c  property settings that are common to both p1 and p2, where p2 take precedence
     -u  union p1 and p2 where p2 has higher precedence
     -1  properties settings that are only in p1
     -2  properties settings that are only in p2
     -d  intersection of properties in p1 and p2 that have different values
     -e  intersection of properties in p1 and p2 that have equal values
 
   The flags can either be combined or separate.
   When no flags are used, all 6 property file combinations are produced.
 
   Use:  -f -  
     to stream output to console (stdout)
 
   Usage Examples:
     dump all variants to console:
       p1.properties p2.properties -f -
     combine two property files where first is default:
       -u p1.properties p2.properties
   Input property files are not modified.
 

Version:
1.0
Author:
peb@baclace.net
See Also:
PropDiff home
License:
 Copyright (C) 2001 Step.com Communications, Inc.
 Copyright (C) 2002 Paul E. Baclace 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  SUCH DAMAGE. 

Constructor Summary
PropDiff(java.util.Properties p1, java.lang.String filenamep1, java.util.Properties p2, java.lang.String filenamep2, boolean toStdout)
          Create a PropDiff that will operate on the Properties objects p1 and p2.
 
Method Summary
 java.util.Properties commonProps()
          Return properties that are common (same name).
 java.util.Properties intersect(boolean intersectValues)
          Return properties that have the same name and equal or different values.
static void main(java.lang.String[] args)
          The main method with a commandline interface.
 java.util.Properties onlyIn(int which)
          Return properties only in one of the Properties objects.
 java.util.Properties union()
          Return union of properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropDiff

public PropDiff(java.util.Properties p1,
                java.lang.String filenamep1,
                java.util.Properties p2,
                java.lang.String filenamep2,
                boolean toStdout)
Create a PropDiff that will operate on the Properties objects p1 and p2. Entries in p2 take precedence over p1 (that is, p1 is the default of p2). The filenames are used when generating comments and as a prefix when creating output files and are neither modified nor read here.

Parameters:
p1 - a default or lower precedence Properties object.
p2 - a higher precedence Properties object than p1.
filenamep1 - filename (with or without full path) corresponding to p1.
filenamep2 - filename (with or without full path) corresponding to p2.
toStdout - if true, send results to System.out instead of creating property files as output.
Method Detail

main

public static void main(java.lang.String[] args)
The main method with a commandline interface. Run this with no arguments to see the usage/help.


intersect

public java.util.Properties intersect(boolean intersectValues)
Return properties that have the same name and equal or different values. The returned properties that are common (same name) with or without the same values, depending on intersectValues. (p1 is default for p2).

Parameters:
intersectValues - if true, then return props that also have the same value. Otherwise, return only properties that have different values.
Returns:
properties in p1 and p2 that have the same name with the added condition intersectValues.

commonProps

public java.util.Properties commonProps()
Return properties that are common (same name). The returned properties that are common to p1 and p2, where p1 is default for p2 (said another way, p2 overrides p1).

Returns:
properties that are in both p1 and p2 where p1 is default for p2.

union

public java.util.Properties union()
Return union of properties.

Returns:
union of properties, where p2 overrides p1

onlyIn

public java.util.Properties onlyIn(int which)
Return properties only in one of the Properties objects. The values of property items are not considered in this case.

Parameters:
which - either 1 or 2.
Returns:
properties only in one of the Properties objects.