FileDocCategorySizeDatePackage
ObjectNameQueryImpl.javaAPI DocGlassfish v2 API7269Fri May 04 22:25:00 BST 2007com.sun.cli.jmx.util

ObjectNameQueryImpl

public class ObjectNameQueryImpl extends Object implements ObjectNameQuery

Fields Summary
Constructors Summary
public ObjectNameQueryImpl()

	
Methods Summary
java.util.regex.Pattern[]createPatterns(java.lang.String[] patternStrings, int numItems)

		final Pattern []	patterns	= new Pattern [ numItems ];
		
		if ( patternStrings == null )
		{
			for( int i = 0; i < numItems; ++i )
			{
				patterns[ i ]	= null;
			}
			
			return( patterns );
		}
			
		
		for( int i = 0; i < numItems; ++i )
		{
			// consider null to match anything
			
			if ( patternStrings[ i ] == null )
			{
				patterns[ i ]	= null;
			}
			else
			{
				patterns[ i ]	= Pattern.compile( patternStrings[ i ] );
			}
		}
		
		return( patterns );
	
booleanmatch(java.util.Hashtable properties, java.util.regex.Pattern propertyPattern, java.util.regex.Pattern valuePattern)

		final Iterator	keys	= new EnumerationIterator( properties.keys() );
		boolean	matches	= false;
		
		while ( keys.hasNext() )
		{
			final String	key	= (String)keys.next();
			
			if ( propertyPattern == null || propertyPattern.matcher( key ).matches() )
			{
				if ( valuePattern == null )
				{
					matches	= true;
					break;
				}

				// see if value matches
				final String	value	= (String)properties.get( key );
				
				if ( valuePattern.matcher( value ).matches() )
				{
					matches	= true;
					break;
				}
			}
		}
		
		return( matches );
	
booleanmatchAll(javax.management.ObjectName name, java.util.regex.Pattern[] propertyPatterns, java.util.regex.Pattern[] valuePatterns)

		boolean	matches	= true;
		
		final Hashtable	properties	= name.getKeyPropertyList();
		
		for( int i = 0; i < propertyPatterns.length; ++i )
		{
			if ( ! match( properties, propertyPatterns[ i ], valuePatterns[ i ] ) )
			{
				matches	= false;
				break;
			}
		}
		
		return( matches );
	
public java.util.SetmatchAll(java.util.Set startingSet, java.lang.String[] regexNames, java.lang.String[] regexValues)

		return( matchEither( new MatchAllMatcher(), startingSet, regexNames, regexValues ) );
	
booleanmatchAny(javax.management.ObjectName name, java.util.regex.Pattern[] propertyPatterns, java.util.regex.Pattern[] valuePatterns)

		boolean	matches	= false;
		
		final Hashtable	properties	= name.getKeyPropertyList();
		
		for( int i = 0; i < propertyPatterns.length; ++i )
		{
			if ( match( properties, propertyPatterns[ i ], valuePatterns[ i ] ) )
			{
				matches	= true;
				break;
			}
		}
		
		return( matches );
	
public java.util.SetmatchAny(java.util.Set startingSet, java.lang.String[] regexNames, java.lang.String[] regexValues)

		return( matchEither( new MatchAnyMatcher(), startingSet, regexNames, regexValues ) );
	
java.util.SetmatchEither(com.sun.cli.jmx.util.ObjectNameQueryImpl$Matcher matcher, java.util.Set startingSet, java.lang.String[] regexNames, java.lang.String[] regexValues)

		if ( regexNames == null && regexValues == null )
		{
			// both null => matches entire original set
			return( startingSet );
		}
		
		final Iterator	iter	= startingSet.iterator();
		final Set		results	= new HashSet();
		
		int	numMatches	= 0;
		if ( regexNames != null )
		{
			numMatches	= regexNames.length;
		}
		else
		{
			numMatches	= regexValues.length;
		}

		final Pattern []	namePatterns	= createPatterns( regexNames, numMatches );
		final Pattern []	valuePatterns	= createPatterns( regexValues, numMatches );
		
		while ( iter.hasNext() )
		{
			final ObjectName	name	= (ObjectName)iter.next();
			
			if ( matcher.match( name, namePatterns, valuePatterns ) )
			{
				results.add( name );
			}
		}

		return( results );
	
voidp(java.lang.Object o)

		System.out.println( o.toString() );