Skip to content

Commit

Permalink
Change isTest to strict
Browse files Browse the repository at this point in the history
  • Loading branch information
Musa Talluzi authored and ge0ffrey committed Aug 3, 2018
1 parent 1a98b26 commit 41da122
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
Expand Up @@ -68,16 +68,15 @@

public class ConferenceSchedulingXlsxFileIO extends AbstractXlsxSolutionFileIO<ConferenceSolution> {

private static boolean isTest;
private static boolean strict;

public ConferenceSchedulingXlsxFileIO() {
super();
this.isTest = false;
this(true);
}

public ConferenceSchedulingXlsxFileIO(boolean isTest) {
public ConferenceSchedulingXlsxFileIO(boolean strict) {
super();
this.isTest = isTest;
this.strict = strict;
}

@Override
Expand Down Expand Up @@ -123,7 +122,7 @@ private void readConfiguration() {
nextRow();
readHeaderCell("Conference name");
solution.setConferenceName(nextStringCell().getStringCellValue());
if (!VALID_NAME_PATTERN.matcher(solution.getConferenceName()).matches()) {
if (strict && !VALID_NAME_PATTERN.matcher(solution.getConferenceName()).matches()) {
throw new IllegalStateException(currentPosition() + ": The conference name (" + solution.getConferenceName()
+ ") must match to the regular expression (" + VALID_NAME_PATTERN + ").");
}
Expand Down Expand Up @@ -228,7 +227,7 @@ private void readTimeslotList() {
if (talkType == null) {
talkType = new TalkType(talkTypeId);
talkTypeId++;
if (!isTest && !VALID_TAG_PATTERN.matcher(talkTypeName).matches()) {
if (strict && !VALID_TAG_PATTERN.matcher(talkTypeName).matches()) {
throw new IllegalStateException(currentPosition()
+ ": The timeslot (" + timeslot + ")'s talkType (" + talkTypeName
+ ") must match to the regular expression (" + VALID_TAG_PATTERN + ").");
Expand All @@ -251,7 +250,7 @@ private void readTimeslotList() {
timeslot.setTagSet(Arrays.stream(nextStringCell().getStringCellValue().split(", "))
.filter(tag -> !tag.isEmpty()).collect(toCollection(LinkedHashSet::new)));
for (String tag : timeslot.getTagSet()) {
if (!isTest && !VALID_TAG_PATTERN.matcher(tag).matches()) {
if (strict && !VALID_TAG_PATTERN.matcher(tag).matches()) {
throw new IllegalStateException(currentPosition()
+ ": The timeslot (" + timeslot + ")'s tag (" + tag
+ ") must match to the regular expression (" + VALID_TAG_PATTERN + ").");
Expand Down Expand Up @@ -282,7 +281,7 @@ private void readRoomList() {
Room room = new Room();
room.setId(id++);
room.setName(nextStringCell().getStringCellValue());
if (!isTest && !VALID_NAME_PATTERN.matcher(room.getName()).matches()) {
if (strict && !VALID_NAME_PATTERN.matcher(room.getName()).matches()) {
throw new IllegalStateException(currentPosition() + ": The room name (" + room.getName()
+ ") must match to the regular expression (" + VALID_NAME_PATTERN + ").");
}
Expand Down Expand Up @@ -312,7 +311,7 @@ private void readRoomList() {
room.setTagSet(Arrays.stream(nextStringCell().getStringCellValue().split(", "))
.filter(tag -> !tag.isEmpty()).collect(toCollection(LinkedHashSet::new)));
for (String tag : room.getTagSet()) {
if (!isTest && !VALID_TAG_PATTERN.matcher(tag).matches()) {
if (strict && !VALID_TAG_PATTERN.matcher(tag).matches()) {
throw new IllegalStateException(currentPosition() + ": The room (" + room + ")'s tag (" + tag
+ ") must match to the regular expression (" + VALID_TAG_PATTERN + ").");
}
Expand Down Expand Up @@ -365,7 +364,7 @@ private void readSpeakerList() {
Speaker speaker = new Speaker();
speaker.setId(id++);
speaker.setName(nextStringCell().getStringCellValue());
if (!isTest && !VALID_NAME_PATTERN.matcher(speaker.getName()).matches()) {
if (strict && !VALID_NAME_PATTERN.matcher(speaker.getName()).matches()) {
throw new IllegalStateException(currentPosition() + ": The speaker name (" + speaker.getName()
+ ") must match to the regular expression (" + VALID_NAME_PATTERN + ").");
}
Expand Down Expand Up @@ -449,7 +448,7 @@ private void readTalkList() {
Talk talk = new Talk();
talk.setId(id++);
talk.setCode(nextStringCell().getStringCellValue());
if (!isTest && !VALID_CODE_PATTERN.matcher(talk.getCode()).matches()) {
if (strict && !VALID_CODE_PATTERN.matcher(talk.getCode()).matches()) {
throw new IllegalStateException(currentPosition() + ": The talk code (" + talk.getCode()
+ ") must match to the regular expression (" + VALID_CODE_PATTERN + ").");
}
Expand All @@ -475,37 +474,37 @@ private void readTalkList() {
talk.setThemeTrackTagSet(Arrays.stream(nextStringCell().getStringCellValue().split(", "))
.filter(tag -> !tag.isEmpty()).collect(toCollection(LinkedHashSet::new)));
for (String tag : talk.getThemeTrackTagSet()) {
if (!isTest && !VALID_TAG_PATTERN.matcher(tag).matches()) {
if (strict && !VALID_TAG_PATTERN.matcher(tag).matches()) {
throw new IllegalStateException(currentPosition() + ": The talk (" + talk + ")'s theme tag (" + tag
+ ") must match to the regular expression (" + VALID_TAG_PATTERN + ").");
}
}
talk.setSectorTagSet(Arrays.stream(nextStringCell().getStringCellValue().split(", "))
.filter(tag -> !tag.isEmpty()).collect(toCollection(LinkedHashSet::new)));
for (String tag : talk.getSectorTagSet()) {
if (!isTest && !VALID_TAG_PATTERN.matcher(tag).matches()) {
if (strict && !VALID_TAG_PATTERN.matcher(tag).matches()) {
throw new IllegalStateException(currentPosition() + ": The talk (" + talk + ")'s sector tag (" + tag
+ ") must match to the regular expression (" + VALID_TAG_PATTERN + ").");
}
}
talk.setAudienceTypeSet(Arrays.stream(nextStringCell().getStringCellValue().split(", "))
.filter(tag -> !tag.isEmpty()).collect(toCollection(LinkedHashSet::new)));
for (String audienceType : talk.getAudienceTypeSet()) {
if (!isTest && !VALID_TAG_PATTERN.matcher(audienceType).matches()) {
if (strict && !VALID_TAG_PATTERN.matcher(audienceType).matches()) {
throw new IllegalStateException(currentPosition() + ": The talk (" + talk + ")'s audience type (" + audienceType
+ ") must match to the regular expression (" + VALID_TAG_PATTERN + ").");
}
}
double audienceLevelDouble = nextNumericCell().getNumericCellValue();
if (!isTest && (audienceLevelDouble <= 0 || audienceLevelDouble != Math.floor(audienceLevelDouble))) {
if (strict && (audienceLevelDouble <= 0 || audienceLevelDouble != Math.floor(audienceLevelDouble))) {
throw new IllegalStateException(currentPosition() + ": The talk with code (" + talk.getCode()
+ ")'s has an audience level (" + audienceLevelDouble + ") that isn't a strictly positive integer number.");
}
talk.setAudienceLevel((int) audienceLevelDouble);
talk.setContentTagSet(Arrays.stream(nextStringCell().getStringCellValue().split(", "))
.filter(tag -> !tag.isEmpty()).collect(toCollection(LinkedHashSet::new)));
for (String tag : talk.getContentTagSet()) {
if (!isTest && !VALID_TAG_PATTERN.matcher(tag).matches()) {
if (strict && !VALID_TAG_PATTERN.matcher(tag).matches()) {
throw new IllegalStateException(currentPosition() + ": The talk (" + talk + ")'s content tag (" + tag
+ ") must match to the regular expression (" + VALID_TAG_PATTERN + ").");
}
Expand Down
Expand Up @@ -87,7 +87,7 @@ public static Collection testSheetParameters() {
File testFile = new File(ConferenceSchedulingScoreRulesXlsxTest.class.getResource(testFileName).getFile());
try (InputStream in = new BufferedInputStream(new FileInputStream(testFile))) {
XSSFWorkbook workbook = new XSSFWorkbook(in);
ConferenceSolution initialSolution = new ConferenceSchedulingXlsxFileIO(true).read(testFile);
ConferenceSolution initialSolution = new ConferenceSchedulingXlsxFileIO(false).read(testFile);
TestConferenceSchedulingScoreRulesReader testFileReader = new TestConferenceSchedulingScoreRulesReader(workbook, initialSolution);

Object[] currentParameterList;
Expand Down

0 comments on commit 41da122

Please sign in to comment.