Skip to content

Commit

Permalink
Used String.join and added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Nov 20, 2015
1 parent 18198e1 commit 9de5da8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
8 changes: 1 addition & 7 deletions src/main/java/net/sf/jabref/model/entry/BibtexEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,7 @@ public void putKeywords(ArrayList<String> keywords) {
String oldValue = this.getField("keywords");
String newValue;
if (!keywords.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (String keyword : keywords) {
sb.append(keyword);
sb.append(", ");
}
sb.delete(sb.length() - 2, sb.length());
newValue = sb.toString();
newValue = String.join(", ", keywords);
} else {
newValue = null;
}
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/net/sf/jabref/model/entry/EntryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,6 @@ public static List<String> getRemainder(List<String> all, List<String> subset) {
return al;
}

/**
* Concatenate two String arrays
*
* @param array1
* the first string array
* @param array2
* the second string array
* @return The concatenation of array1 and array2
*/
public static String[] arrayConcat(String[] array1, String[] array2) {
int len1 = array1.length;
int len2 = array2.length;
String[] union = new String[len1 + len2];
System.arraycopy(array1, 0, union, 0, len1);
System.arraycopy(array2, 0, union, len1, len2);
return union;
}

/**
* @param keywords a String of keywords
* @return an ArrayList containing the keywords. An emtpy list if keywords are null or empty
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/net/sf/jabref/model/entry/BibtexEntryTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,41 @@ public void testKeywordMethods() {
Assert.assertArrayEquals(expected2, be.getSeparatedKeywords().toArray());

BibtexEntry be2 = new BibtexEntry();
Assert.assertTrue(be2.getSeparatedKeywords().isEmpty());
be2.addKeyword("");
Assert.assertTrue(be2.getSeparatedKeywords().isEmpty());
be2.addKeywords(be.getSeparatedKeywords());
Assert.assertArrayEquals(expected2, be2.getSeparatedKeywords().toArray());
}

@Test
public void testGroupAndSearchHits() {
BibtexEntry be = new BibtexEntry();
be.setGroupHit(true);
Assert.assertTrue(be.isGroupHit());
be.setGroupHit(false);
Assert.assertFalse(be.isGroupHit());
be.setSearchHit(true);
Assert.assertTrue(be.isSearchHit());
be.setSearchHit(false);
Assert.assertFalse(be.isSearchHit());

}

@Test
public void testCiteKeyAndID() {
BibtexEntry be = new BibtexEntry();
Assert.assertFalse(be.hasCiteKey());
be.setField("author", "Albert Einstein");
be.setField(BibtexEntry.KEY_FIELD, "Einstein1931");
Assert.assertTrue(be.hasCiteKey());
Assert.assertEquals("Einstein1931", be.getCiteKey());
Assert.assertEquals("Albert Einstein", be.getField("author"));
be.clearField("author");
Assert.assertNull(be.getField("author"));

String id = IdGenerator.next();
be.setId(id);
Assert.assertEquals(id, be.getId());
}
}

0 comments on commit 9de5da8

Please sign in to comment.