forked from torakiki/pdfsam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close torakiki#198: populate bookmarks combo level with all the valid…
… levels Even incase they are not contiguos
- Loading branch information
Showing
12 changed files
with
208 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
pdfsam-core/src/main/java/org/pdfsam/support/validation/ContainedIntegerValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* This file is part of the PDF Split And Merge source code | ||
* Created on 22 ott 2016 | ||
* Copyright 2013-2014 by Andrea Vacondio ([email protected]). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* 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. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.pdfsam.support.validation; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Validates that a given String represent an integer in a given set | ||
* | ||
* @author Andrea Vacondio | ||
* | ||
*/ | ||
public class ContainedIntegerValidator implements Validator<String> { | ||
private Set<Integer> valid = new HashSet<>(); | ||
|
||
public ContainedIntegerValidator(Set<Integer> validValues) { | ||
ofNullable(validValues).map(valid::addAll); | ||
} | ||
|
||
@Override | ||
public boolean isValid(String input) { | ||
try { | ||
return valid.contains(Integer.parseInt(input)); | ||
} catch (NumberFormatException e) { | ||
// not a valid integer | ||
return false; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
pdfsam-core/src/test/java/org/pdfsam/support/validation/ContainedIntegerValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* This file is part of the PDF Split And Merge source code | ||
* Created on 22 ott 2016 | ||
* Copyright 2013-2014 by Andrea Vacondio ([email protected]). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* 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. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.pdfsam.support.validation; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* @author Andrea Vacondio | ||
* | ||
*/ | ||
public class ContainedIntegerValidatorTest { | ||
private Validator<String> victim = Validators.containedInteger(new HashSet<>(Arrays.asList(-2, 5, 6))); | ||
|
||
@Test | ||
public void testNotContained() { | ||
assertFalse(victim.isValid("50")); | ||
} | ||
|
||
@Test | ||
public void testInvalid() { | ||
assertFalse(victim.isValid("dsdsa")); | ||
} | ||
|
||
@Test | ||
public void testValid() { | ||
assertTrue(victim.isValid("5")); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.