Skip to content

Commit

Permalink
Handle empty values better
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgw committed Aug 27, 2023
1 parent a3a530f commit dabde8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
public class PublicationXref extends BiopaxNode {
static final String PUBMED_URL = "http://www.ncbi.nlm.nih.gov/pubmed/";
static final String DOI_URL = "http://doi.org/";
static final String EMPTY_VALUE_STRING = "NA";

public PublicationXref() {
super();
Expand Down Expand Up @@ -82,19 +83,21 @@ public void setYear(String year) {
}

public String getDb() {
return getPropertyValue(PropertyType.DB);
String db = getPropertyValue(PropertyType.DB);
return db.equals(EMPTY_VALUE_STRING) ? "" : db;
}

public void setDb(String db) {
setPropertyValue(PropertyType.DB, db.equals("") ? "NA" : db);
setPropertyValue(PropertyType.DB, Utils.isEmpty(db) ? EMPTY_VALUE_STRING : db);
}

public String getPubmedId() {
return getPropertyValue(PropertyType.ID);
String id = getPropertyValue(PropertyType.ID);
return id.equals(EMPTY_VALUE_STRING) ? "" : id;
}

public void setPubmedId(String id) {
setPropertyValue(PropertyType.ID, id.equals("") ? "NA" : id);
setPropertyValue(PropertyType.ID, Utils.isEmpty(id) ? EMPTY_VALUE_STRING : id);
}

public List<String> getAuthors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ private void setText(String text, JTextComponent field) {
}

protected void refresh() {
if (input.getDb() != null) {
db.setSelectedIndex(java.util.Arrays.asList(DB_OPTIONS).indexOf(input.getDb()));
} else {
String selectedDb = input.getDb();
int selectedDbIndex = java.util.Arrays.asList(DB_OPTIONS).indexOf(selectedDb);
if (selectedDb == null) {
db.setSelectedIndex(0);
} else if (selectedDbIndex > -1) {
db.setSelectedIndex(selectedDbIndex);
} else {
db.setSelectedItem(selectedDb);
}
setText(input.getPubmedId(), pmId);
setText(input.getTitle(), title);
Expand Down

0 comments on commit dabde8f

Please sign in to comment.