ezvcard
Class ValidationWarnings

java.lang.Object
  extended by ezvcard.ValidationWarnings
All Implemented Interfaces:
Iterable<Map.Entry<VCardProperty,List<Warning>>>

public class ValidationWarnings
extends Object
implements Iterable<Map.Entry<VCardProperty,List<Warning>>>

Holds the validation warnings of a vCard.

Examples:

 //validate a vCard object according to the rules of a specific version
 ValidationWarnings warnings = vcard.validate(VCardVersion.V3_0);
 
 //print all warnings to a string:
 System.out.println(warnings.toString());
 //sample output:
 //W01: A FormattedName property is required for vCard versions 3.0 and 4.0.
 //[Gender] | W02: Property is not supported in this vCard version.  Supported versions are: [4.0]
 
 //iterate over the warnings
 for (Map.Entry<VCardProperty, List<Warning>> entry : warnings) {
        //the property that caused the warning(s)
        VCardProperty property = entry.getKey();
 
        //the list of warnings that belong to this property
        List<Warning> propWarnings = entry.getValue();
 
        if (property == null) {
                //it's a warning about the vCard as a whole
        }
 
        //each warning message has a numeric code
        //this allows you to programmatically respond to specific warning messages
        List<Warning> propWarnings = entry.getValue();
        for (Warning w : propWarnings) {
                System.out.println("Code: " + w.getCode());
                System.out.printkn("Message: " + w.getMessage());
        }
 }
 
 //you can also get the warnings of specific property classes
 List<Warnings> telWarnings = warnings.getByProperty(Telephone.class);
 

Author:
Michael Angstadt
See Also:
VCard.validate(ezvcard.VCardVersion)

Constructor Summary
ValidationWarnings()
           
 
Method Summary
 void add(VCardProperty property, List<Warning> warnings)
          Adds a property's validation warnings.
 void add(VCardProperty property, Warning warning)
          Adds a validation warning.
 List<Warning> getByProperty(Class<? extends VCardProperty> propertyClass)
          Gets all validation warnings that belong to a property of a specific class.
 ListMultimap<VCardProperty,Warning> getWarnings()
          Gets all of the validation warnings.
 boolean isEmpty()
          Determines whether or not the warnings list is empty.
 Iterator<Map.Entry<VCardProperty,List<Warning>>> iterator()
           
 String toString()
           Outputs all validation warnings as a newline-delimited string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ValidationWarnings

public ValidationWarnings()
Method Detail

add

public void add(VCardProperty property,
                Warning warning)
Adds a validation warning.

Parameters:
property - the property that caused the warning
warning - the warning

add

public void add(VCardProperty property,
                List<Warning> warnings)
Adds a property's validation warnings.

Parameters:
property - the property that caused the warnings
warnings - the warnings

getWarnings

public ListMultimap<VCardProperty,Warning> getWarnings()
Gets all of the validation warnings.

Returns:
the validation warnings

isEmpty

public boolean isEmpty()
Determines whether or not the warnings list is empty.

Returns:
true if there are no warnings, false if there is at least one warning

getByProperty

public List<Warning> getByProperty(Class<? extends VCardProperty> propertyClass)
Gets all validation warnings that belong to a property of a specific class.

Parameters:
propertyClass - the property class (e.g. Telephone.class) or null to get the warnings that apply to the vCard as a whole
Returns:
the validation warnings

toString

public String toString()

Outputs all validation warnings as a newline-delimited string. For example:

 W01: A FormattedName property is required for vCard versions 3.0 and 4.0.
 [Gender] | W02: Property is not supported in this vCard version.  Supported versions are: [4.0]
 

Overrides:
toString in class Object

iterator

public Iterator<Map.Entry<VCardProperty,List<Warning>>> iterator()
Specified by:
iterator in interface Iterable<Map.Entry<VCardProperty,List<Warning>>>


Copyright © 2012-2014 Michael Angstadt. All Rights Reserved.