incubator-ivy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r543068 - in /incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version: AbstractVersionMatcher.java ChainVersionMatcher.java
Date Thu, 31 May 2007 06:38:25 GMT
Author: xavier
Date: Wed May 30 23:38:24 2007
New Revision: 543068

URL: http://svn.apache.org/viewvc?view=rev&rev=543068
Log:
ChainVersionMatcher: check parameters against nullity, add some javadoc, remove _ prefix

Modified:
    incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version/AbstractVersionMatcher.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version/ChainVersionMatcher.java

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version/AbstractVersionMatcher.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version/AbstractVersionMatcher.java?view=diff&rev=543068&r1=543067&r2=543068
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version/AbstractVersionMatcher.java
(original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version/AbstractVersionMatcher.java
Wed May 30 23:38:24 2007
@@ -23,10 +23,11 @@
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.plugins.IvySettingsAware;
+import org.apache.ivy.util.Checks;
 
 public abstract class AbstractVersionMatcher implements VersionMatcher, IvySettingsAware
{
 	private String _name;
-	private IvySettings _settings;
+	private IvySettings settings;
 	
 	public AbstractVersionMatcher() {
 	}
@@ -65,11 +66,12 @@
     }
 
 	public IvySettings getSettings() {
-		return _settings;
+		return settings;
 	}
 
-	public void setSettings(IvySettings ivy) {
-		_settings = ivy;
+	public void setSettings(IvySettings settings) {
+    	Checks.checkNotNull(settings, "settings");
+		this.settings = settings;
 	}
 
 }

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version/ChainVersionMatcher.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version/ChainVersionMatcher.java?view=diff&rev=543068&r1=543067&r2=543068
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version/ChainVersionMatcher.java
(original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/version/ChainVersionMatcher.java
Wed May 30 23:38:24 2007
@@ -27,25 +27,52 @@
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.plugins.IvySettingsAware;
+import org.apache.ivy.util.Checks;
 
-
+/**
+ * An implementation of {@link VersionMatcher} chaining several
+ * version matchers, and implemeting the {@link VersionMatcher}
+ * interface by returning results from the first matcher in the chain
+ * accepting the version. 
+ */
 public class ChainVersionMatcher extends AbstractVersionMatcher {
-    private List _matchers = new LinkedList();
+	/**
+	 * The list of version matchers in the chain.
+	 * This list will be queried in order, so the last matcher
+	 * will be used only if no other matcher accept the revision
+	 * before.
+	 */
+    private List/*<VersionMatcher>*/ matchers = new LinkedList();
     
+    /**
+     * Unique Constructor.
+     */
     public ChainVersionMatcher() {
     	super("chain");
     }
-    
+
+    /**
+     * Adds a {@link VersionMatcher} to the chain.
+     * 
+     * @param matcher the version matcher to add. Must not be null
+     */
     public void add(VersionMatcher matcher) {
-        _matchers.add(0, matcher);
+    	Checks.checkNotNull(matcher, "matcher");
+        matchers.add(0, matcher);
 		if (getSettings() != null && matcher instanceof IvySettingsAware) {
 			((IvySettingsAware) matcher).setSettings(getSettings());
 		}
     }
     
+    /**
+     * Sets the settings this matcher will use, and set to the matcher in the chain
+     * which implements {@link IvySettingsAware}.
+     * 
+     * @param settings the settings to use in the whole chain. Must not be null.
+     */
     public void setSettings(IvySettings settings) {
     	super.setSettings(settings);
-    	for (Iterator iter = _matchers.iterator(); iter.hasNext();) {
+    	for (Iterator iter = matchers.iterator(); iter.hasNext();) {
 			VersionMatcher matcher = (VersionMatcher) iter.next();
 			if (matcher instanceof IvySettingsAware) {
 				((IvySettingsAware) matcher).setSettings(settings);
@@ -53,13 +80,22 @@
 		}
     }
     
+    /**
+     * Returns the list of matchers in the chain.
+     * <p>
+     * The list is returned as an unmodifiable view on the actual list of matchers,
+     * and will thus reflect futher changes made in the chain.
+     * 
+     * @return the list of matchers in the chain. Is never null.
+     */
     public List getMatchers() {
-    	return Collections.unmodifiableList(_matchers);
+    	return Collections.unmodifiableList(matchers);
     }
     
 
     public boolean isDynamic(ModuleRevisionId askedMrid) {
-        for (Iterator iter = _matchers.iterator(); iter.hasNext();) {
+    	Checks.checkNotNull(askedMrid, "askedMrid");
+        for (Iterator iter = matchers.iterator(); iter.hasNext();) {
             VersionMatcher matcher = (VersionMatcher)iter.next();
             if (matcher.isDynamic(askedMrid)) {
                 return true;
@@ -69,7 +105,10 @@
     }
 
     public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, Comparator
staticComparator) {
-    	for (Iterator iter = _matchers.iterator(); iter.hasNext();) {
+    	Checks.checkNotNull(askedMrid, "askedMrid");
+    	Checks.checkNotNull(foundMrid, "foundMrid");
+    	Checks.checkNotNull(staticComparator, "staticComparator");
+    	for (Iterator iter = matchers.iterator(); iter.hasNext();) {
     		VersionMatcher matcher = (VersionMatcher)iter.next();
     		if (matcher.isDynamic(askedMrid)) {
     			return matcher.compare(askedMrid, foundMrid, staticComparator);
@@ -79,7 +118,9 @@
     }
 
     public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) {
-        for (Iterator iter = _matchers.iterator(); iter.hasNext();) {
+    	Checks.checkNotNull(askedMrid, "askedMrid");
+    	Checks.checkNotNull(foundMrid, "foundMrid");
+        for (Iterator iter = matchers.iterator(); iter.hasNext();) {
             VersionMatcher matcher = (VersionMatcher)iter.next();
             if (!iter.hasNext() || matcher.isDynamic(askedMrid)) {
                 return matcher.accept(askedMrid, foundMrid);
@@ -89,7 +130,9 @@
     }
 
     public boolean needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid)
{
-        for (Iterator iter = _matchers.iterator(); iter.hasNext();) {
+    	Checks.checkNotNull(askedMrid, "askedMrid");
+    	Checks.checkNotNull(foundMrid, "foundMrid");
+        for (Iterator iter = matchers.iterator(); iter.hasNext();) {
             VersionMatcher matcher = (VersionMatcher)iter.next();
             if (!iter.hasNext() || matcher.isDynamic(askedMrid)) {
                 return matcher.needModuleDescriptor(askedMrid, foundMrid);
@@ -99,7 +142,9 @@
     }
 
     public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD) {
-        for (Iterator iter = _matchers.iterator(); iter.hasNext();) {
+    	Checks.checkNotNull(askedMrid, "askedMrid");
+    	Checks.checkNotNull(foundMD, "foundMD");
+        for (Iterator iter = matchers.iterator(); iter.hasNext();) {
             VersionMatcher matcher = (VersionMatcher)iter.next();
             if (!iter.hasNext() || matcher.isDynamic(askedMrid)) {
                 return matcher.accept(askedMrid, foundMD);
@@ -107,5 +152,4 @@
         }
         return false;
     }
-
 }



Mime
View raw message