Methods Summary |
---|
public void | addMapping(java.lang.String originalName, java.lang.String derivedName)
mDerivedToOriginal.put( derivedName, originalName );
mOriginalToDerived.put( originalName, derivedName );
if ( mUnmappedOriginals.keySet().contains( originalName ) )
{
mUnmappedOriginals.remove( originalName );
}
mDerivedNames.add( derivedName );
|
protected final void | debug(java.lang.Object o)
if ( mDebug != null )
{
mDebug.println( o );
}
|
public java.lang.String | derivedToOriginal(java.lang.String derivedName)
final String original = mDerivedToOriginal.get( derivedName );
return( original );
|
public void | dontMap(java.lang.String originalName)
addMapping( originalName, originalName );
|
public java.util.Set | getDerivedNames()
return( mDerivedNames );
|
public java.util.Set | getUnmappedOriginals()
Set<String> unmapped = Collections.emptySet();
if ( mUnmappedOriginals.keySet().size() != 0 )
{
unmapped = new HashSet<String>( mUnmappedOriginals.values());
}
return unmapped;
|
public java.lang.String | matchName(java.lang.String derivedName, java.lang.String[] candidates)Attempt to match the derived name to one of the candidates.
This facility is used when different runtime conditions
present different original names which must be mapped to the
same derived name.
If a name is matched it is added as a mapping and the
original name is returned, otherwise an exception is thrown.
String result = null;
final String existingOriginal = derivedToOriginal( derivedName );
if ( existingOriginal != null )
{
throw new IllegalArgumentException( "Already mapped: " +
derivedName + " => " + existingOriginal );
}
if ( mUnmappedOriginals.keySet().size() == 0 )
{
throw new IllegalArgumentException(
"There are no unmapped originals, existing mappings: " +
MapUtil.toString( mOriginalToDerived, ", " ) );
}
for( final String candidate : candidates )
{
final String candidateNormalized = normalize( candidate );
if ( mUnmappedOriginals.keySet().contains( candidateNormalized ) )
{
result = mUnmappedOriginals.get( candidateNormalized );
mUnmappedOriginals.remove( candidateNormalized );
addMapping( result, derivedName );
break;
}
}
if ( result == null )
{
final String msg = derivedName + " can't be matched to " +
StringUtil.toString( ", " , (Object[])candidates ) +
", unmapped originals: " +
CollectionUtil.toString( mUnmappedOriginals.values(), ", ") +
", mapped originals: {" + MapUtil.toString( mDerivedToOriginal, ", ") + "}";
throw new IllegalArgumentException( msg );
}
return result;
|
public java.lang.String | matchName(java.lang.String derivedName, java.lang.String candidate1, java.lang.String candidate2)
return matchName( derivedName, new String[] { candidate1, candidate2 } );
|
public java.lang.String | matchName(java.lang.String derivedName, java.lang.String candidate1)
return matchName( derivedName, new String[] { candidate1 } );
|
public void | matchNames(java.lang.String[] derivedNames, java.lang.String[] originalNames)Attempt to match an original name with a derived one by performing
a case-insensitive comparison. It is OK if there are more derived
names than originals, or if there are more original names than
derived names.
final Set<String> originals = GSetUtil.newSet( originalNames );
final Set<String> deriveds = GSetUtil.newSet( derivedNames );
// first, eliminate identical names
for( final String original : originalNames )
{
if ( deriveds.contains( original ) )
{
//System.out.println( "IDENTITY: " + original );
addMapping( original, original );
originals.remove( original );
deriveds.remove( original );
}
}
// now we have remaining only those names that differ.
if ( originals.size() != 0 )
{
final Map<String,String> originalsMap = normalize( originals );
final Map<String,String> derivedsMap = normalize( deriveds );
for( final String originalLowerCase : originalsMap.keySet() )
{
final String original = originalsMap.get( originalLowerCase );
final String derived = derivedsMap.get( originalLowerCase );
if ( derived != null )
{
//System.out.println( "MATCHED: " + original + " => " + derived );
addMapping( original, derived );
}
else
{
// System.out.println( "NO MATCH: " + original );
mUnmappedOriginals.put( normalize( original ), original );
}
}
}
|
private java.lang.String | normalize(java.lang.String s)
return stripDashes( s ).toLowerCase();
|
private java.util.Map | normalize(java.util.Set s)
final Map<String,String> result = new HashMap<String,String>();
for( final String name : s )
{
result.put( normalize( name ), name );
}
return result;
|
public java.lang.String | originalToDerived(java.lang.String originalName)
final String derivedName = mOriginalToDerived.get( originalName );
return( derivedName );
|
public void | setDebugOutput(com.sun.appserv.management.util.misc.Output debugOutput)
mDebug = debugOutput;
|
private java.lang.String | stripDashes(java.lang.String name)
String result = name;
if ( name.indexOf( DASH ) >= 0 )
{
final StringBuilder builder = new StringBuilder();
final int length = name.length();
boolean upperNext = false;
for( int i = 0; i < length; ++i )
{
final char c = name.charAt( i );
if ( c == DASH_CHAR )
{
upperNext = true;
}
else
{
if ( upperNext )
{
builder.append( ("" + c ).toUpperCase() );
upperNext = false;
}
else
{
builder.append( c );
}
}
}
result = builder.toString();
}
return result;
|
public java.lang.String | toString()
final StringBuilder builder = new StringBuilder();
final String LINE_SEPARATOR = System.getProperty( "line.separator" );
for( final String name : getDerivedNames() )
{
builder.append( name );
builder.append( " => " );
builder.append( derivedToOriginal( name ) );
builder.append( LINE_SEPARATOR );
}
return( builder.toString() );
|