Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/bin/
/build/
/target/
**/target/
/download/
*~
*.swp
*.swo

# IDE files #
######################
.classpath
.project
.settings/
*.iml
.idea/

# Logs and databases #
######################
*.log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -135,7 +136,7 @@ private boolean validateFormat(X509Certificate certificate, List<String> violati
*/
private boolean validateValidity(X509Certificate certificate, List<String> violations) {
try {
Date now = new Date();
Instant now = Instant.now();
Date notBefore = certificate.getNotBefore();
Date notAfter = certificate.getNotAfter();

Expand All @@ -149,17 +150,17 @@ private boolean validateValidity(X509Certificate certificate, List<String> viola
return false;
}

if (now.before(notBefore)) {
if (now.isBefore(notBefore.toInstant())) {
violations.add("Certificate is not yet valid (notBefore: " + notBefore + ")");
return false;
}

if (now.after(notAfter)) {
if (now.isAfter(notAfter.toInstant())) {
violations.add("Certificate has expired (notAfter: " + notAfter + ")");
return false;
}

certificate.checkValidity(now);
certificate.checkValidity(Date.from(now));
LOGGER.debug("Certificate validity period validation passed");
return true;

Expand Down
2 changes: 1 addition & 1 deletion BulkDownloader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk7</artifactId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.6.7</version>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public List<HttpUrl> fetchLinks(String url, String linkPrefix, String suffix) th
* @throws IOException
*/
public List<HttpUrl> fetchLinks(HttpUrl url, String linkPrefix, String suffix) throws IOException {
List<HttpUrl> list = new ArrayList<HttpUrl>();
List<HttpUrl> list = new ArrayList<>();

//String matchPrefix = "/?" + linkPrefix;

Expand Down Expand Up @@ -141,7 +141,7 @@ public LocalDate parseFileDate(String filename) {
}

public List<HttpUrl> fetchLinks(Source source) throws IOException { // method currently used by Download class.
List<HttpUrl> list = new ArrayList<HttpUrl>();
List<HttpUrl> list = new ArrayList<>();

Request request = new Request.Builder().url(source.getDownload().getScrapeUrl()).build();
Response response = client.newCall(request).execute();
Expand Down Expand Up @@ -184,7 +184,7 @@ public List<HttpUrl> fetchLinks(Source source) throws IOException { // method cu

public List<HttpUrl> fetchLinks(HttpUrl url, List<DateRange> dateMatches, String suffix) throws IOException {
// method currently used by BulkData class.
List<HttpUrl> list = new ArrayList<HttpUrl>();
List<HttpUrl> list = new ArrayList<>();

Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public List<HttpUrl> getDownloadURLs() throws IOException {

public DownloadJob downloadRandom(int limit) throws IOException {
List<HttpUrl> urls = fetchLinks(0);
List<HttpUrl> randomUrls = new ArrayList<HttpUrl>();
List<HttpUrl> randomUrls = new ArrayList<>();

Random random = new Random();
for (int i = 0; i < limit; i++) {
Expand Down Expand Up @@ -140,7 +140,7 @@ public DownloadJob downloadRestore() throws IOException {

private List<HttpUrl> fetchLinks() throws IOException {
if (source.getDownload().getDownloadUrl() != null) {
List<HttpUrl> urls = new ArrayList<HttpUrl>(1);
List<HttpUrl> urls = new ArrayList<>(1);
urls.add(source.getDownload().getDownloadUrl());
return urls;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public List<HttpUrl> getDownloadURLs() throws IOException {

public DownloadJob downloadRandom(int limit) throws IOException {
List<HttpUrl> urls = fetchLinks();
List<HttpUrl> randomUrls = new ArrayList<HttpUrl>();
List<HttpUrl> randomUrls = new ArrayList<>();

Random random = new Random();
for (int i = 0; i < limit; i++) {
Expand Down Expand Up @@ -155,7 +155,7 @@ public DownloadJob downloadRestore() throws IOException {
}

private List<HttpUrl> fetchLinks() throws IOException {
List<HttpUrl> urls = new LinkedList<HttpUrl>();
List<HttpUrl> urls = new LinkedList<>();
while (yearIterator.hasNext()) {
String year = yearIterator.next();
//String fileRegex = "[A-z]{3,6}" + yearMap.get(year) + ".*?" + "\\." + dataType.getSuffix() + "$";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public static void main(String... args) throws IOException, XPathExpressionExcep

LOGGER.info("Request: {}", yearMap);

List<PatentClassification> wantedClasses = new ArrayList<PatentClassification>();
List<PatentClassification> wantedClasses = new ArrayList<>();
List<String> cpcs = Splitter.on(',').omitEmptyStrings().trimResults().splitToList(cpc);
for (String cpcStr : cpcs) {
CpcClassification cpcClass = new CpcClassification();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jdk7.Jdk7Module;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import okhttp3.HttpUrl;

@JsonSerialize
Expand All @@ -34,7 +34,7 @@ public class DownloadJob implements Serializable, Iterable<DownloadFile> {

private static ObjectMapper JSON_MAPPER = new ObjectMapper();
static {
JSON_MAPPER.registerModule(new Jdk7Module());
JSON_MAPPER.registerModule(new Jdk8Module());
}

private Path downloadDir;
Expand All @@ -46,7 +46,7 @@ public DownloadJob(HttpUrl url, Path downloadDir) throws IOException {
this.downloadDir = downloadDir;
this.taskTotal = 1;

this.downloadTasks = new ArrayList<DownloadFile>();
this.downloadTasks = new ArrayList<>();
DownloadFile download = new DownloadFile(url, downloadDir);
downloadTasks.add(download);
}
Expand All @@ -55,7 +55,7 @@ public DownloadJob(Collection<HttpUrl> urls, Path downloadDir) throws IOExceptio
this.downloadDir = downloadDir;
this.taskTotal = urls.size();

this.downloadTasks = new ArrayList<DownloadFile>();
this.downloadTasks = new ArrayList<>();
for (HttpUrl url : urls) {
DownloadFile download = new DownloadFile(url, downloadDir);
downloadTasks.add(download);
Expand All @@ -80,15 +80,7 @@ public int getTaskTotal() {
}

public int getTaskCompleted() {
int count = 0;

for (DownloadFile task : downloadTasks) {
if (task.isComplete()) {
count++;
}
}

return count;
return (int) downloadTasks.stream().filter(DownloadFile::isComplete).count();
}

public boolean isComplete() {
Expand Down Expand Up @@ -123,7 +115,7 @@ public void save() throws IOException {
Writer outFile = new OutputStreamWriter(new FileOutputStream(downloadStatusFile));

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk7Module());
mapper.registerModule(new Jdk8Module());
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.writeValue(outFile, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class PatternMatcher {
private static final Logger LOGGER = LoggerFactory.getLogger(PatternMatcher.class);

private List<XPathMatch> patterns = new ArrayList<XPathMatch>();
private List<XPathMatch> patterns = new ArrayList<>();
private DocumentBuilder docBuilder;
private XPathMatch lastMatchedPattern;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class PatternXPath extends MatchXPath {
private static final Logger LOGGER = LoggerFactory.getLogger(PatternXPath.class);

private final List<XPathExpression> xPaths = new ArrayList<XPathExpression>();
private final List<XPathExpression> xPaths = new ArrayList<>();
private String[] xPathExpressions;

public PatternXPath(String... xPathExpressions) throws XPathExpressionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class PatternXpathValueRegex extends MatchXPath {

private List<Pattern> regexs = new ArrayList<Pattern>();
private List<Pattern> regexs = new ArrayList<>();
private Pattern pattern = Pattern.compile("");
private XPathExpression xPathExpression;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static Iterator<File> getFileIterator(String... filePathStrings) throws
* @return
*/
private static Iterator<File> getFileIterator(Collection<String> fileNames) throws FileNotFoundException {
List<File> filenames = new ArrayList<File>(fileNames.size());
List<File> filenames = new ArrayList<>(fileNames.size());
for (String filename : fileNames) {
File file = new File(filename);
if (file.isFile() && file.canRead()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class DateRangeStringFilter implements FileFilter, StringFilter {
private DateRange dateRange;
private List<Pattern> nameDateRegexs = new ArrayList<Pattern>();
private List<Pattern> nameDateRegexs = new ArrayList<>();

public DateRangeStringFilter(DateRange dateRange, String... regexes) {
this.dateRange = dateRange;
Expand Down
9 changes: 2 additions & 7 deletions Common/src/main/java/gov/uspto/common/filter/EqualFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ public EqualFilter(String... wanted) {

@Override
public boolean accept(String valueStr) {
for (String wantedValue : wanted) {
if (wantedValue.equals(valueStr)) {
return true;
}
}
return false;
return Arrays.stream(wanted).anyMatch(w -> w.equals(valueStr));
}

@Override
Expand All @@ -35,4 +30,4 @@ public String toString() {
return "EqualFilter [wanted=" + Arrays.toString(wanted) + "]";
}

}
}
13 changes: 3 additions & 10 deletions Common/src/main/java/gov/uspto/common/filter/FileFilterChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,15 @@
*/
public class FileFilterChain implements FileFilter {

public List<FileFilter> matchRules = new ArrayList<FileFilter>();
public List<FileFilter> matchRules = new ArrayList<>();

public void addRule(FileFilter... rules) {
for (FileFilter rule : rules) {
matchRules.add(rule);
}
java.util.Collections.addAll(matchRules, rules);
}

@Override
public boolean accept(File file) {
for (FileFilter rule : matchRules) {
if (!rule.accept(file)) {
return false;
}
}
return true;
return matchRules.stream().allMatch(rule -> rule.accept(file));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ public PrefixFilter(String... prefixes) {

@Override
public boolean accept(String valueStr) {
for (String prefix : prefixes) {
if (valueStr.startsWith(prefix)) {
return true;
}
}
return false;
return Arrays.stream(prefixes).anyMatch(valueStr::startsWith);
}

@Override
Expand All @@ -30,4 +25,4 @@ public boolean accept(File file) {
public String toString() {
return "PrefixFilter [prefixes=" + Arrays.toString(prefixes) + "]";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.regex.Pattern;

public class RegexFilter implements FileFilter, StringFilter {
private List<Pattern> regexes = new ArrayList<Pattern>();
private List<Pattern> regexes = new ArrayList<>();

public RegexFilter(String... regexes) {
for (String regex : regexes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,15 @@
*/
public class StringFilterChain implements StringFilter {

public List<StringFilter> filters = new ArrayList<StringFilter>();
public List<StringFilter> filters = new ArrayList<>();

public void addRule(StringFilter... rules) {
for (StringFilter rule : rules) {
filters.add(rule);
}
java.util.Collections.addAll(filters, rules);
}

@Override
public boolean accept(String filename) {
for (StringFilter rule : filters) {
if (!rule.accept(filename)) {
return false;
}
}
return true;
return filters.stream().allMatch(rule -> rule.accept(filename));
}

@Override
Expand Down
10 changes: 3 additions & 7 deletions Common/src/main/java/gov/uspto/common/filter/SuffixFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ public SuffixFilter(String... suffixes) {

@Override
public boolean accept(String valueStr) {
for (String suffix : suffixes) {
if (valueStr.toLowerCase().endsWith(suffix)) {
return true;
}
}
return false;
String lowerVal = valueStr.toLowerCase();
return Arrays.stream(suffixes).anyMatch(lowerVal::endsWith);
}

@Override
Expand All @@ -30,4 +26,4 @@ public boolean accept(File file) {
public String toString() {
return "SuffixFilter [suffixes=" + Arrays.toString(suffixes) + "]";
}
}
}
Loading
Loading