Skip to content

Commit

Permalink
Make every field on structures non final
Browse files Browse the repository at this point in the history
  • Loading branch information
jamezrin committed Dec 7, 2018
1 parent c214449 commit c5bad47
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 27 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.jamezrin</groupId>
<artifactId>crtmcards</artifactId>
<version>1.1.1-SNAPSHOT</version>
<artifactId>crtm-cards-java</artifactId>
<version>1.1.2-SNAPSHOT</version>
<name>crtm-cards-java</name>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.jamezrin.crtmcards;

import com.github.jamezrin.crtmcards.types.Card;
import com.github.jamezrin.crtmcards.types.CardRenewal;
import com.github.jamezrin.crtmcards.types.CardType;
import com.github.jamezrin.crtmcards.types.CrtmCard;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
Expand All @@ -21,7 +21,7 @@ public class DocumentExtractor {
public static final Pattern PROFILE_DATE_PATTERN = Pattern.compile("^Perfil (?<type>[\\s\\S]+) caduca: (?<date>[0-9]{2}-[0-9]{2}-[0-9]{4})$");
public static final Pattern PROFILE_LINE_PATTERN = Pattern.compile("<br>(\\s+)?");

public static CrtmCard processCard(Document document) {
public static Card processCard(Document document) {
// Full card number
Element fullNumEl = document.getElementById("ctl00_cntPh_lblNumeroTarjeta");

Expand All @@ -30,13 +30,13 @@ public static CrtmCard processCard(Document document) {
Element resultRowEl = resultsTableEl.getElementsByTag("td").get(1);
Elements resultsEls = resultRowEl.getElementsByTag("span");

// CrtmCard expiration date
// Card expiration date
Element expirationEl = document.getElementById("ctl00_cntPh_lblFechaCaducidadTarjeta");

// CrtmCard relevant profiles w/ exp. dates
// Card relevant profiles w/ exp. dates
Element profilesEl = document.getElementById("ctl00_cntPh_lblInfoDatosDeLaTarjeta");

return new CrtmCard(
return new Card(
fullNumEl.text(),
resultsEls.get(0).text(),
CardType.fromId(resultsEls.get(1).text()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.jamezrin.crtmcards;

import com.github.jamezrin.crtmcards.exceptions.ScraperException;
import com.github.jamezrin.crtmcards.types.CrtmCard;
import com.github.jamezrin.crtmcards.types.Card;
import org.apache.http.HttpResponse;
import org.apache.http.entity.ContentType;
import org.jsoup.Jsoup;
Expand Down Expand Up @@ -40,11 +40,11 @@ public ResponseParser(HttpResponse response) throws IOException, ScraperExceptio
);
}

public CrtmCard parse() throws ScraperException {
public Card parse() throws ScraperException {
// Runs all checks and throws exceptions accordingly
ErrorChecker.checkForErrors(document);

// Extracts properties and creates CrtmCard
// Extracts properties and creates Card
return DocumentExtractor.processCard(document);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
import java.util.Arrays;
import java.util.EnumMap;

public class CrtmCard {
private final String fullNum;
private final String title;
private final CardType type;
public class Card {
private String fullNum;
private String title;
private CardType type;
private CardRenewal[] renewals;
private LocalDate expirationDate;
private EnumMap<CardType, LocalDate> profiles;

private final CardRenewal[] renewals;

private final LocalDate expirationDate;
private final EnumMap<CardType, LocalDate> profiles;

public CrtmCard(String fullNum, String title, CardType type, CardRenewal[] renewals, LocalDate expirationDate, EnumMap<CardType, LocalDate> profiles) {
public Card(String fullNum, String title, CardType type, CardRenewal[] renewals, LocalDate expirationDate, EnumMap<CardType, LocalDate> profiles) {
this.fullNum = fullNum;
this.title = title;
this.type = type;
Expand All @@ -27,29 +25,53 @@ public String getFullNum() {
return fullNum;
}

public void setFullNum(String fullNum) {
this.fullNum = fullNum;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public CardType getType() {
return type;
}

public void setType(CardType type) {
this.type = type;
}

public CardRenewal[] getRenewals() {
return renewals;
}

public void setRenewals(CardRenewal[] renewals) {
this.renewals = renewals;
}

public LocalDate getExpirationDate() {
return expirationDate;
}

public void setExpirationDate(LocalDate expirationDate) {
this.expirationDate = expirationDate;
}

public EnumMap<CardType, LocalDate> getProfiles() {
return profiles;
}

public void setProfiles(EnumMap<CardType, LocalDate> profiles) {
this.profiles = profiles;
}

@Override
public String toString() {
return "CrtmCard{" +
return "Card{" +
"fullNum='" + fullNum + '\'' +
", title='" + title + '\'' +
", type=" + type +
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/com/github/jamezrin/crtmcards/types/CardRenewal.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.time.LocalDate;

public class CardRenewal {
private final LocalDate rechargeDate;
private final LocalDate validityStartDate;
private final LocalDate firstUseDate;
private final LocalDate expirationDate;
private LocalDate rechargeDate;
private LocalDate validityStartDate;
private LocalDate firstUseDate;
private LocalDate expirationDate;

public CardRenewal(LocalDate rechargeDate, LocalDate validityStartDate, LocalDate firstUseDate, LocalDate expirationDate) {
this.rechargeDate = rechargeDate;
Expand All @@ -19,18 +19,34 @@ public LocalDate getRechargeDate() {
return rechargeDate;
}

public void setRechargeDate(LocalDate rechargeDate) {
this.rechargeDate = rechargeDate;
}

public LocalDate getValidityStartDate() {
return validityStartDate;
}

public void setValidityStartDate(LocalDate validityStartDate) {
this.validityStartDate = validityStartDate;
}

public LocalDate getFirstUseDate() {
return firstUseDate;
}

public void setFirstUseDate(LocalDate firstUseDate) {
this.firstUseDate = firstUseDate;
}

public LocalDate getExpirationDate() {
return expirationDate;
}

public void setExpirationDate(LocalDate expirationDate) {
this.expirationDate = expirationDate;
}

@Override
public String toString() {
return "CardRenewal{" +
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/TestScrapCrtm.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.github.jamezrin.crtmcards.exceptions.CurrentlyUnavailableException;
import com.github.jamezrin.crtmcards.exceptions.InactiveCardNumberException;
import com.github.jamezrin.crtmcards.exceptions.InvalidCardNumberException;
import com.github.jamezrin.crtmcards.types.CrtmCard;
import com.github.jamezrin.crtmcards.types.Card;
import org.apache.http.HttpResponse;
import org.junit.jupiter.api.Test;

Expand All @@ -29,7 +29,7 @@ public void testValidCard() throws Exception {
);

ResponseParser parser = new ResponseParser(response);
CrtmCard card = parser.parse();
Card card = parser.parse();

assertNotNull(card);
} catch (CurrentlyUnavailableException | SocketTimeoutException e) {
Expand Down

0 comments on commit c5bad47

Please sign in to comment.