Skip to content

Commit

Permalink
answer to #1726 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindenb committed Oct 29, 2024
1 parent 71727e8 commit 190dc4d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/htsjdk/tribble/gff/Gff3BaseData.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public boolean hasAttribute(final String key) {
* @return <tt>Optional&lt;String&gt;</tt> if this map contains zero or one attribute for the specified key
* @throws IllegalArgumentException if there is more than one value
*/
public Optional<String> getAttr(final String key) {
public Optional<String> getUniqueAttribute(final String key) {
final List<String> atts = getAttribute(key);
switch(atts.size()) {
case 0 : return Optional.empty();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/htsjdk/tribble/gff/Gff3Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ default boolean hasAttribute(final String key) {
* @return <tt>Optional&lt;String&gt;</tt> if this map contains zero or one attribute for the specified key
* @throws IllegalArgumentException if there is more than one value.
*/
default Optional<String> getAttr(final String key) {
return getBaseData().getAttr(key);
default Optional<String> getUniqueAttribute(final String key) {
return getBaseData().getUniqueAttribute(key);
}

default Map<String, List<String>> getAttributes() { return getBaseData().getAttributes();}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/htsjdk/tribble/gff/Gff3CodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void codecFilterOutFieldsTest(final Path inputGff3, final int expectedTot
for(final String key : skip_attributes) {
Assert.assertTrue(feature.getAttribute(key).isEmpty());
Assert.assertFalse(feature.hasAttribute(key));
Assert.assertFalse(feature.getAttr(key).isPresent());
Assert.assertFalse(feature.getUniqueAttribute(key).isPresent());
}
countTotalFeatures++;
}
Expand Down Expand Up @@ -203,8 +203,8 @@ public void urlDecodingTest() throws IOException {
Assert.assertEquals(feature.getAttribute("Another key"), Arrays.asList("Another=value", "And a second, value"));
Assert.assertTrue(feature.hasAttribute("Another key"));
Assert.assertTrue(feature.hasAttribute(Gff3Constants.ID_ATTRIBUTE_KEY));
Assert.assertTrue(feature.getAttr(Gff3Constants.ID_ATTRIBUTE_KEY).isPresent());
Assert.assertFalse(feature.getAttr("missing").isPresent());
Assert.assertTrue(feature.getUniqueAttribute(Gff3Constants.ID_ATTRIBUTE_KEY).isPresent());
Assert.assertFalse(feature.getUniqueAttribute("missing").isPresent());
}


Expand Down

0 comments on commit 190dc4d

Please sign in to comment.