Qwylt

java.lang.module
Class AttributeMatcher

java.lang.Object
  extended by java.lang.module.AttributeSource
      extended by java.lang.module.AttributeMatcher
All Implemented Interfaces:
Matcher<AttributeSource>

public abstract class AttributeMatcher
extends AttributeSource
implements Matcher<AttributeSource>

A Matcher for AttributeSources.

Since:
Dec 21, 2009
Author:
Bryan Atsatt. Copyright (c) 2010 Oracle.

Field Summary
 
Fields inherited from class java.lang.module.AttributeSource
NO_ATTRIBUTES, SERVICE_IMPLEMENTATION_KEY
 
Constructor Summary
protected AttributeMatcher(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> attributes)
          Constructor.
 
Method Summary
static AttributeMatcher anyMatcher()
          Returns an @AttributeMatcher that matches any attributes.
 boolean containsAttribute(java.lang.String key)
          Returns true if the specified attribute is present in this instance.
static AttributeMatcher containsMatcher(java.util.Map<java.lang.String,java.lang.String> attributes)
          Returns an AttributeMatcher that matches if all specified attributes are contained in the target AttributeSource.
static AttributeMatcher containsMatcher(java.lang.String... keyValuePairs)
          Returns an AttributeMatcher that matches if all specified attributes are contained in the target AttributeSource.
static AttributeMatcher equalsMatcher(java.util.Map<java.lang.String,java.lang.String> attributes)
          Returns an AttributeMatcher that matches if the specified attributes are equal to those of the target AttributeSource.
static AttributeMatcher equalsMatcher(java.lang.String... keyValuePairs)
          Returns an AttributeMatcher that matches if the specified attributes are equal to those of the AttributeSource.
 java.lang.String getAttribute(java.lang.String key)
          Returns the attribute value.
 java.util.List<java.lang.String> getAttributeAsList(java.lang.String key)
          Returns the attribute value as a list.
 java.util.Set<java.lang.String> getAttributeKeys()
          Returns an unmodifiable set of the attribute keys.
 java.util.Map<java.lang.String,java.lang.String> getAttributes()
          Returns an unmodifiable map of the attributes.
 java.lang.String getName()
          Returns the name of this instance.
abstract  boolean matches(AttributeSource target)
          Tests if the specified target matches this instance.
static java.util.Map<java.lang.String,java.lang.String> newAttributes(java.lang.String... keyValuePairs)
          Returns a new attribute map.
 java.lang.String toString()
          Returns a string representation of this matcher.
 
Methods inherited from class java.lang.module.AttributeSource
appendAttributes, asList, containsAttributes, modifiableList, unmodifiableMap, unmodifiableMap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttributeMatcher

protected AttributeMatcher(java.lang.String name,
                           java.util.Map<java.lang.String,java.lang.String> attributes)
Constructor.

Parameters:
name - A descriptor for this matcher.
attributes - The attributes to match.
Method Detail

newAttributes

public static java.util.Map<java.lang.String,java.lang.String> newAttributes(java.lang.String... keyValuePairs)
Returns a new attribute map.

Parameters:
keyValuePairs - The key/value pairs.
Returns:
The map.
Throws:
java.lang.IllegalArgumentException - if keyValuePairs.length is odd.

equalsMatcher

public static AttributeMatcher equalsMatcher(java.lang.String... keyValuePairs)
Returns an AttributeMatcher that matches if the specified attributes are equal to those of the AttributeSource.

Parameters:
keyValuePairs - The key/value pairs.
Returns:
The matcher.
Throws:
java.lang.IllegalArgumentException - if keyValuePairs.length is odd.

equalsMatcher

public static AttributeMatcher equalsMatcher(java.util.Map<java.lang.String,java.lang.String> attributes)
Returns an AttributeMatcher that matches if the specified attributes are equal to those of the target AttributeSource.

Parameters:
attributes - The attributes to match.
Returns:
The matcher.

containsMatcher

public static AttributeMatcher containsMatcher(java.lang.String... keyValuePairs)
Returns an AttributeMatcher that matches if all specified attributes are contained in the target AttributeSource.

Parameters:
keyValuePairs - The key/value pairs.
Returns:
The matcher.
Throws:
java.lang.IllegalArgumentException - if keyValuePairs.length is odd.

containsMatcher

public static AttributeMatcher containsMatcher(java.util.Map<java.lang.String,java.lang.String> attributes)
Returns an AttributeMatcher that matches if all specified attributes are contained in the target AttributeSource.

Parameters:
attributes - The attributes to match.
Returns:
The matcher.

anyMatcher

public static AttributeMatcher anyMatcher()
Returns an @AttributeMatcher that matches any attributes.

Returns:
The matcher.

getName

public java.lang.String getName()
Returns the name of this instance.

Specified by:
getName in class AttributeSource
Returns:
the name of this instance.

containsAttribute

public boolean containsAttribute(java.lang.String key)
Returns true if the specified attribute is present in this instance.

Specified by:
containsAttribute in class AttributeSource
Parameters:
key - The attribute key.
Returns:
true if the attribute is present.

getAttribute

public java.lang.String getAttribute(java.lang.String key)
Returns the attribute value.

Specified by:
getAttribute in class AttributeSource
Parameters:
key - The attribute key.
Returns:
The attribute value or null if none.

getAttributeAsList

public java.util.List<java.lang.String> getAttributeAsList(java.lang.String key)
Returns the attribute value as a list. Same as calling asList(getAttribute(key)); however, subclasses may override and change the list format.

Overrides:
getAttributeAsList in class AttributeSource
Parameters:
key - The attribute key.
Returns:
The attribute values. Will be empty if none.

getAttributeKeys

public java.util.Set<java.lang.String> getAttributeKeys()
Returns an unmodifiable set of the attribute keys.

Specified by:
getAttributeKeys in class AttributeSource
Returns:
an unmodifiable set of attribute keys.

getAttributes

public java.util.Map<java.lang.String,java.lang.String> getAttributes()
Returns an unmodifiable map of the attributes.

Specified by:
getAttributes in class AttributeSource
Returns:
an unmodifiable map of attributes.

matches

public abstract boolean matches(AttributeSource target)
Tests if the specified target matches this instance.

Specified by:
matches in interface Matcher<AttributeSource>
Parameters:
target - The target instance.
Returns:
true if the specified target matches this instance; false otherwise.

toString

public java.lang.String toString()
Returns a string representation of this matcher.

Overrides:
toString in class java.lang.Object
Returns:
The string.

Qwylt

Send comments or questions to Bryan Atsatt