Consider the following:
class Parent {
...
private final int firstRound;
/**
* @return the first round to display
*/
public final int getFirstRound(@UnknownInitialization(BracketInfo.class) BracketInfo this) {
return firstRound;
}
private final int lastRound;
/**
* @return the last round to display
*/
public final int getLastRound(@UnknownInitialization(BracketInfo.class) BracketInfo this) {
return lastRound;
}
}
class Sub extends Parent {
Sub(...) {
this.bracketData = new TreeMap<Integer, SortedMap<Integer, BracketDataType>>();
for (int i = getFirstRound(); i <= getLastRound(); i++) {
bracketData.put(i, new TreeMap<Integer, BracketDataType>());
}
}
public int getNumRows() {
try {
if (getFirstRound() < finalsRound
&& getLastRound() >= finalsRound) {
final int sfr = bracketData.get(finalsRound).lastKey();
final int fr = bracketData.get(getFirstRound()).lastKey();
return sfr > fr ? sfr : fr;
} else {
return bracketData.get(getFirstRound()).lastKey().intValue();
}
} catch (final NoSuchElementException e) {
return 0;
}
}
}
The constructor of Sub ensures that all integers in the range [firstRound, lastRound] are keys in bracketData.
If I make bracketData unmodifiable (Collections.unmodifiableSortedMap) is there a way to add annotation so that checker recognizes that the code in getNumRows cannot receive a null when accessing bracketData?