Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/ExceptionInfo.java @ 403:2747b0723867
FIXMEs: work on exceptions and javadoc
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 05 Mar 2012 14:50:51 +0100 |
parents | |
children | 9c9c442b5f2e |
comparison
equal
deleted
inserted
replaced
402:1fcc7f7b6d65 | 403:2747b0723867 |
---|---|
1 /* | |
2 * Copyright (c) 2012 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.internal; | |
18 | |
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; | |
20 | |
21 import java.io.File; | |
22 | |
23 import org.tmatesoft.hg.core.Nodeid; | |
24 import org.tmatesoft.hg.repo.HgRepository; | |
25 import org.tmatesoft.hg.util.Path; | |
26 | |
27 /** | |
28 * Extras to record with exception to describe it better. | |
29 * XXX perhaps, not only with exception, may utilize it with status object? | |
30 * | |
31 * @author Artem Tikhomirov | |
32 * @author TMate Software Ltd. | |
33 */ | |
34 public class ExceptionInfo<T> { | |
35 protected final T owner; | |
36 protected int revNumber = BAD_REVISION; | |
37 protected Nodeid revision; | |
38 protected Path filename; | |
39 protected File localFile; | |
40 | |
41 /** | |
42 * @param owner instance to return from setters | |
43 */ | |
44 public ExceptionInfo(T owner) { | |
45 this.owner = owner; | |
46 } | |
47 | |
48 /** | |
49 * @return not {@link HgRepository#BAD_REVISION} only when revision index was supplied at the construction time | |
50 */ | |
51 public int getRevisionIndex() { | |
52 return revNumber; | |
53 } | |
54 | |
55 public T setRevisionIndex(int rev) { | |
56 revNumber = rev; | |
57 return owner; | |
58 } | |
59 | |
60 public boolean isRevisionIndexSet() { | |
61 return revNumber != BAD_REVISION; | |
62 } | |
63 | |
64 /** | |
65 * @return non-null only when revision was supplied at construction time | |
66 */ | |
67 public Nodeid getRevision() { | |
68 return revision; | |
69 } | |
70 | |
71 public T setRevision(Nodeid r) { | |
72 revision = r; | |
73 return owner; | |
74 } | |
75 | |
76 public boolean isRevisionSet() { | |
77 return revision != null; | |
78 } | |
79 | |
80 /** | |
81 * @return non-null only if file name was set at construction time | |
82 */ | |
83 public Path getFileName() { | |
84 return filename; | |
85 } | |
86 | |
87 public T setFileName(Path name) { | |
88 filename = name; | |
89 return owner; | |
90 } | |
91 | |
92 public T setFile(File file) { | |
93 localFile = file; | |
94 return owner; | |
95 } | |
96 | |
97 /** | |
98 * @return file object that causes troubles, or <code>null</code> if specific file is unknown | |
99 */ | |
100 public File getFile() { | |
101 return localFile; | |
102 } | |
103 | |
104 public StringBuilder appendDetails(StringBuilder sb) { | |
105 if (filename != null) { | |
106 sb.append("path:'"); | |
107 sb.append(filename); | |
108 sb.append('\''); | |
109 sb.append(';'); | |
110 sb.append(' '); | |
111 } | |
112 sb.append("rev:"); | |
113 if (revNumber != BAD_REVISION) { | |
114 sb.append(revNumber); | |
115 if (revision != null) { | |
116 sb.append(':'); | |
117 } | |
118 } | |
119 if (revision != null) { | |
120 sb.append(revision.shortNotation()); | |
121 } | |
122 if (localFile != null) { | |
123 sb.append(';'); | |
124 sb.append(' '); | |
125 sb.append(" file:"); | |
126 sb.append(localFile.getPath()); | |
127 sb.append(','); | |
128 if (localFile.exists()) { | |
129 sb.append("EXISTS"); | |
130 } else { | |
131 sb.append("DOESN'T EXIST"); | |
132 } | |
133 } | |
134 return sb; | |
135 } | |
136 } |