diff --git a/src/main/java/net/sf/jabref/model/entry/BibtexEntry.java b/src/main/java/net/sf/jabref/model/entry/BibtexEntry.java index 6636b2b6025..10728152fb0 100644 --- a/src/main/java/net/sf/jabref/model/entry/BibtexEntry.java +++ b/src/main/java/net/sf/jabref/model/entry/BibtexEntry.java @@ -494,13 +494,7 @@ public void putKeywords(ArrayList 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; } diff --git a/src/main/java/net/sf/jabref/model/entry/EntryUtil.java b/src/main/java/net/sf/jabref/model/entry/EntryUtil.java index 9483e368b15..40c9e2beb7a 100644 --- a/src/main/java/net/sf/jabref/model/entry/EntryUtil.java +++ b/src/main/java/net/sf/jabref/model/entry/EntryUtil.java @@ -62,24 +62,6 @@ public static List getRemainder(List all, List 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 diff --git a/src/test/java/net/sf/jabref/model/entry/BibtexEntryTests.java b/src/test/java/net/sf/jabref/model/entry/BibtexEntryTests.java index a6ad6fc069a..2287ce570ab 100644 --- a/src/test/java/net/sf/jabref/model/entry/BibtexEntryTests.java +++ b/src/test/java/net/sf/jabref/model/entry/BibtexEntryTests.java @@ -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()); + } }