comparison src/org/tmatesoft/hg/core/HgInvalidRevisionException.java @ 396:0ae53c32ecef

Straighten out exceptions thrown when file access failed - three is too much
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 23 Feb 2012 01:06:24 +0100
parents 6150555eb41d
children 866fc3b597a0
comparison
equal deleted inserted replaced
395:4732fffff58a 396:0ae53c32ecef
1 /* 1 /*
2 * Copyright (c) 2011 TMate Software Ltd 2 * Copyright (c) 2011-2012 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 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 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.core; 17 package org.tmatesoft.hg.core;
18 18
19 import static org.tmatesoft.hg.repo.HgRepository.*;
20
19 import org.tmatesoft.hg.internal.Experimental; 21 import org.tmatesoft.hg.internal.Experimental;
20 import org.tmatesoft.hg.repo.HgRepository;
21 22
22 /** 23 /**
23 * Use of revision or revision local index that is not valid for a given revlog. 24 * Use of revision or revision local index that is not valid for a given revlog.
24 * 25 *
25 * @author Artem Tikhomirov 26 * @author Artem Tikhomirov
27 */ 28 */
28 @SuppressWarnings("serial") 29 @SuppressWarnings("serial")
29 @Experimental(reason="1) Whether to use checked or runtime exception is not yet decided. 2) Perhaps, its use not bound to wrong arguments") 30 @Experimental(reason="1) Whether to use checked or runtime exception is not yet decided. 2) Perhaps, its use not bound to wrong arguments")
30 public class HgInvalidRevisionException extends IllegalArgumentException { 31 public class HgInvalidRevisionException extends IllegalArgumentException {
31 private Nodeid rev; 32 private Nodeid rev;
32 private Integer revIdx; 33 private Integer revIdx = BAD_REVISION;
33 // next two make sense only when revIdx is present 34 // next two make sense only when revIdx is present
34 private int rangeLeftBoundary = -1, rangeRightBoundary = -1; 35 private int rangeLeftBoundary = -1, rangeRightBoundary = -1;
35 36
36 /** 37 /**
37 * 38 *
73 // int, not Integer is on purpose, not to clear exception completely 74 // int, not Integer is on purpose, not to clear exception completely
74 public HgInvalidRevisionException setRevisionIndex(int revisionIndex) { 75 public HgInvalidRevisionException setRevisionIndex(int revisionIndex) {
75 revIdx = revisionIndex; 76 revIdx = revisionIndex;
76 return this; 77 return this;
77 } 78 }
78 79
79 public HgInvalidRevisionException setRevisionIndex(int revisionIndex, int rangeLeft, int rangeRight) { 80 public HgInvalidRevisionException setRevisionIndex(int revisionIndex, int rangeLeft, int rangeRight) {
80 revIdx = revisionIndex; 81 revIdx = revisionIndex;
81 rangeLeftBoundary = rangeLeft; 82 rangeLeftBoundary = rangeLeft;
82 rangeRightBoundary = rangeRight; 83 rangeRightBoundary = rangeRight;
83 return this; 84 return this;
85 }
86
87 public boolean isRevisionSet() {
88 return rev != null;
89 }
90
91 public boolean isRevisionIndexSet() {
92 return revIdx != BAD_REVISION;
84 } 93 }
85 94
86 @Override 95 @Override
87 public String getMessage() { 96 public String getMessage() {
88 String msg = super.getMessage(); 97 String msg = super.getMessage();
96 sb.append(' '); 105 sb.append(' ');
97 } 106 }
98 if (revIdx != null) { 107 if (revIdx != null) {
99 String sr; 108 String sr;
100 switch (revIdx) { 109 switch (revIdx) {
101 case HgRepository.BAD_REVISION : sr = "UNKNOWN"; break; 110 case BAD_REVISION : sr = "UNKNOWN"; break;
102 case HgRepository.TIP : sr = "TIP"; break; 111 case TIP : sr = "TIP"; break;
103 case HgRepository.WORKING_COPY: sr = "WORKING-COPY"; break; 112 case WORKING_COPY: sr = "WORKING-COPY"; break;
104 default : sr = revIdx.toString(); 113 default : sr = revIdx.toString();
105 } 114 }
106 if (rangeLeftBoundary != -1 || rangeRightBoundary != -1) { 115 if (rangeLeftBoundary != -1 || rangeRightBoundary != -1) {
107 sb.append(String.format("%s is not from [%d..%d]", sr, rangeLeftBoundary, rangeRightBoundary)); 116 sb.append(String.format("%s is not from [%d..%d]", sr, rangeLeftBoundary, rangeRightBoundary));
108 } else { 117 } else {