changeset 454:36fd1fd06492

oth.util.Status renamed to Outcome as the noun is too overloaded, especially in scm
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 13 Jun 2012 21:07:39 +0200
parents 7b883bf03b14
children 909306e412e2
files cmdline/org/tmatesoft/hg/console/Status.java src/org/tmatesoft/hg/core/HgChangesetFileSneaker.java src/org/tmatesoft/hg/core/HgStatusCommand.java src/org/tmatesoft/hg/core/HgStatusHandler.java src/org/tmatesoft/hg/util/Outcome.java src/org/tmatesoft/hg/util/Status.java test/org/tmatesoft/hg/test/TestStatus.java
diffstat 7 files changed, 88 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/cmdline/org/tmatesoft/hg/console/Status.java	Wed Jun 13 18:18:37 2012 +0200
+++ b/cmdline/org/tmatesoft/hg/console/Status.java	Wed Jun 13 21:07:39 2012 +0200
@@ -86,7 +86,7 @@
 				}
 			}
 			
-			public void error(Path file, org.tmatesoft.hg.util.Status s) {
+			public void error(Path file, org.tmatesoft.hg.util.Outcome s) {
 				System.out.printf("FAILURE: %s %s\n", s.getMessage(), file);
 				s.getException().printStackTrace(System.out);
 			}
--- a/src/org/tmatesoft/hg/core/HgChangesetFileSneaker.java	Wed Jun 13 18:18:37 2012 +0200
+++ b/src/org/tmatesoft/hg/core/HgChangesetFileSneaker.java	Wed Jun 13 21:07:39 2012 +0200
@@ -23,7 +23,7 @@
 import org.tmatesoft.hg.repo.HgRepository;
 import org.tmatesoft.hg.repo.HgRuntimeException;
 import org.tmatesoft.hg.util.Path;
-import org.tmatesoft.hg.util.Status;
+import org.tmatesoft.hg.util.Outcome;
 
 /**
  * Primary purpose is to provide information about file revisions at specific changeset. Multiple {@link #check(Path)} calls 
@@ -55,7 +55,7 @@
 	private ManifestRevision cachedManifest;
 	private HgFileRevision fileRevision;
 	private boolean renamed;
-	private Status checkResult;
+	private Outcome checkResult;
 
 	public HgChangesetFileSneaker(HgRepository hgRepo) {
 		repo = hgRepo;
@@ -90,7 +90,7 @@
 	}
 
 	/**
-	 * Shortcut to perform {@link #check(Path)} and {@link #exists()}. Result of the check may be accessed via {@link #getCheckStatus()}.
+	 * Shortcut to perform {@link #check(Path)} and {@link #exists()}. Result of the check may be accessed via {@link #getCheckResult()}.
 	 * Errors during the check, if any, are reported through exception.
 	 * 
 	 * @param file name of the file in question
@@ -114,11 +114,11 @@
 	 * Find file (or its origin, if {@link #followRenames(boolean)} was set to <code>true</code>) among files known at specified {@link #changeset(Nodeid)}.
 	 * 
 	 * @param file name of the file in question
-	 * @return status object that describes outcome, {@link Status#isOk() Ok} status indicates successful completion of the operation, but doesn't imply
+	 * @return status object that describes outcome, {@link Outcome#isOk() Ok} status indicates successful completion of the operation, but doesn't imply
 	 * file existence, use {@link #exists()} for that purpose. Message of the status may provide further hints on what exactly had happened. 
 	 * @throws IllegalArgumentException if {@link #changeset(Nodeid)} not specified or file argument is bad.
 	 */
-	public Status check(Path file) {
+	public Outcome check(Path file) {
 		fileRevision = null;
 		checkResult = null;
 		renamed = false;
@@ -127,7 +127,7 @@
 		}
 		HgDataFile dataFile = repo.getFileNode(file);
 		if (!dataFile.exists()) {
-			checkResult = new Status(Status.Kind.OK, String.format("File named %s is not known in the repository", file));
+			checkResult = new Outcome(Outcome.Kind.Success, String.format("File named %s is not known in the repository", file));
 			return checkResult;
 		}
 		Nodeid toExtract = null;
@@ -153,22 +153,29 @@
 				}
 			}
 		} catch (HgRuntimeException ex) {
-			checkResult = new Status(Status.Kind.ERROR, phaseMsg, ex);
+			checkResult = new Outcome(Outcome.Kind.Failure, phaseMsg, ex);
 			return checkResult;
 		}
 		if (toExtract != null) {
 			fileRevision = new HgFileRevision(repo, toExtract, extractRevFlags, dataFile.getPath());
-			checkResult = new Status(Status.Kind.OK, String.format("File %s, revision %s found at changeset %s", dataFile.getPath(), toExtract.shortNotation(), cset.shortNotation()));
+			checkResult = new Outcome(Outcome.Kind.Success, String.format("File %s, revision %s found at changeset %s", dataFile.getPath(), toExtract.shortNotation(), cset.shortNotation()));
 			return checkResult;
 		} 
-		checkResult = new Status(Status.Kind.OK, String.format("File %s nor its origins were known at repository %s revision", file, cset.shortNotation()));
+		checkResult = new Outcome(Outcome.Kind.Success, String.format("File %s nor its origins were known at repository %s revision", file, cset.shortNotation()));
 		return checkResult;
 	}
 	
 	/**
+	 * @deprecated use {@link #getCheckResult()} instead
+	 */
+	@Deprecated
+	public Outcome getCheckStatus() {
+		return getCheckResult();
+	}
+	/**
 	 * Re-get latest check status object
 	 */
-	public Status getCheckStatus() {
+	public Outcome getCheckResult() {
 		assertCheckRan();
 		return checkResult;
 	}
--- a/src/org/tmatesoft/hg/core/HgStatusCommand.java	Wed Jun 13 18:18:37 2012 +0200
+++ b/src/org/tmatesoft/hg/core/HgStatusCommand.java	Wed Jun 13 21:07:39 2012 +0200
@@ -32,7 +32,7 @@
 import org.tmatesoft.hg.util.CancelSupport;
 import org.tmatesoft.hg.util.CancelledException;
 import org.tmatesoft.hg.util.Path;
-import org.tmatesoft.hg.util.Status;
+import org.tmatesoft.hg.util.Outcome;
 
 /**
  * Command to obtain file status information, 'hg status' counterpart. 
@@ -321,7 +321,7 @@
 		
 		public void invalid(Path fname, Exception err) {
 			try {
-				handler.error(fname, new Status(Status.Kind.ERROR, "Failed to get file status", err));
+				handler.error(fname, new Outcome(Outcome.Kind.Failure, "Failed to get file status", err));
 				handlerCancelSupport.checkCancelled();
 			} catch (HgCallbackTargetException ex) {
 				failure = ex;
--- a/src/org/tmatesoft/hg/core/HgStatusHandler.java	Wed Jun 13 18:18:37 2012 +0200
+++ b/src/org/tmatesoft/hg/core/HgStatusHandler.java	Wed Jun 13 21:07:39 2012 +0200
@@ -18,7 +18,7 @@
 
 import org.tmatesoft.hg.internal.Callback;
 import org.tmatesoft.hg.util.Path;
-import org.tmatesoft.hg.util.Status;
+import org.tmatesoft.hg.util.Outcome;
 
 /**
  * Callback to process {@link HgStatus} objects.
@@ -43,5 +43,5 @@
 	 * @param s error description object
 	 * @throws HgCallbackTargetException wrapper for any exception user code may produce
 	 */
-	void error(Path file, Status s) throws HgCallbackTargetException;
+	void error(Path file, Outcome s) throws HgCallbackTargetException;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/tmatesoft/hg/util/Outcome.java	Wed Jun 13 21:07:39 2012 +0200
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2011-2012 TMate Software Ltd
+ *  
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * For information on how to redistribute this software under
+ * the terms of a license other than GNU General Public License
+ * contact TMate Software at support@hg4j.com
+ */
+package org.tmatesoft.hg.util;
+
+/**
+ * Success/failure descriptor. When exception is too much.
+ * 
+ * @author Artem Tikhomirov
+ * @author TMate Software Ltd.
+ */
+public class Outcome {
+	// XXX perhaps private enum and factory method createError() and createOk()?
+	public enum Kind {
+		Success, Failure;
+	}
+
+	private final Kind kind;
+	private final String message;
+	private final Exception error;
+
+	public Outcome(Kind k, String msg) {
+		this(k, msg, null);
+	}
+	
+	public Outcome(Kind k, String msg, Exception err) {
+		kind = k;
+		message = msg;
+		error = err;
+	}
+	
+	public boolean isOk() {
+		return kind == Kind.Success;
+	}
+	
+	public Kind getKind() {
+		return kind;
+	}
+
+	public String getMessage() {
+		return message;
+	}
+	
+	public Exception getException() {
+		return error;
+	}
+}
--- a/src/org/tmatesoft/hg/util/Status.java	Wed Jun 13 18:18:37 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2011 TMate Software Ltd
- *  
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * For information on how to redistribute this software under
- * the terms of a license other than GNU General Public License
- * contact TMate Software at support@hg4j.com
- */
-package org.tmatesoft.hg.util;
-
-import org.tmatesoft.hg.internal.Experimental;
-
-/**
- * Success/failure descriptor. When exception is too much.
- * 
- * @author Artem Tikhomirov
- * @author TMate Software Ltd.
- */
-@Experimental(reason="Accidental use, does not justify dedicated class, perhaps.")
-public class Status {
-	// XXX perhaps private enum and factory method createError() and createOk()?
-	public enum Kind {
-		OK, ERROR;
-	}
-
-	private final Kind kind;
-	private final String message;
-	private final Exception error;
-
-	public Status(Kind k, String msg) {
-		this(k, msg, null);
-	}
-	
-	public Status(Kind k, String msg, Exception err) {
-		kind = k;
-		message = msg;
-		error = err;
-	}
-	
-	public boolean isOk() {
-		return kind == Kind.OK;
-	}
-	
-	public Kind getKind() {
-		return kind;
-	}
-
-	public String getMessage() {
-		return message;
-	}
-	
-	public Exception getException() {
-		return error;
-	}
-}
--- a/test/org/tmatesoft/hg/test/TestStatus.java	Wed Jun 13 18:18:37 2012 +0200
+++ b/test/org/tmatesoft/hg/test/TestStatus.java	Wed Jun 13 21:07:39 2012 +0200
@@ -48,7 +48,7 @@
 import org.tmatesoft.hg.repo.HgStatusCollector;
 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector;
 import org.tmatesoft.hg.util.Path;
-import org.tmatesoft.hg.util.Status;
+import org.tmatesoft.hg.util.Outcome;
 
 /**
  * 
@@ -181,7 +181,7 @@
 	static class StatusCollector implements HgStatusHandler {
 		private final Map<Kind, List<Path>> kind2names = new TreeMap<Kind, List<Path>>();
 		private final Map<Path, List<Kind>> name2kinds = new TreeMap<Path, List<Kind>>();
-		private final Map<Path, Status> name2error = new LinkedHashMap<Path, Status>();
+		private final Map<Path, Outcome> name2error = new LinkedHashMap<Path, Outcome>();
 		private final Map<Path, Path> new2oldName = new LinkedHashMap<Path, Path>();
 
 		public void status(HgStatus s) {
@@ -201,7 +201,7 @@
 			k.add(s.getKind());
 		}
 
-		public void error(Path file, Status s) {
+		public void error(Path file, Outcome s) {
 			name2error.put(file, s);
 		}
 
@@ -215,7 +215,7 @@
 			return rv == null ? Collections.<Kind> emptyList() : rv;
 		}
 
-		public Map<Path, Status> getErrors() {
+		public Map<Path, Outcome> getErrors() {
 			return name2error;
 		}
 
@@ -605,7 +605,7 @@
 		cmd.execute(sc);
 		// shall pass without exception
 		//
-		for (Map.Entry<Path, Status> e : sc.getErrors().entrySet()) {
+		for (Map.Entry<Path, Outcome> e : sc.getErrors().entrySet()) {
 			System.out.printf("%s : (%s %s)\n", e.getKey(), e.getValue().getKind(), e.getValue().getMessage());
 		}
 		assertTrue(sc.getErrors().isEmpty());
@@ -636,7 +636,7 @@
 		cmd.execute(sc);
 		// shall pass without exception
 		//
-		for (Map.Entry<Path, Status> e : sc.getErrors().entrySet()) {
+		for (Map.Entry<Path, Outcome> e : sc.getErrors().entrySet()) {
 			System.out.printf("%s : (%s %s)\n", e.getKey(), e.getValue().getKind(), e.getValue().getMessage());
 		}
 		assertTrue(sc.getErrors().isEmpty());