Skip to content

Commit

Permalink
Add getKeyValuePairsAsList method
Browse files Browse the repository at this point in the history
  • Loading branch information
ppouchin committed Sep 19, 2024
1 parent 2764557 commit 7c3670c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/main/java/fr/igred/omero/AnnotatableWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,29 @@ public Map<String, String> getKeyValuePairs(Client client)
}


/**
* Gets the List of Key-Value pairs associated to an object.
*
* @param client The client handling the connection.
*
* @return See above.
*
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
*
* @deprecated This method will be renamed to {@link #getKeyValuePairs(Client)} ()} in a future version.
*/
@Deprecated
public List<Map.Entry<String, String>> getKeyValuePairsAsList(Client client)
throws ServiceException, AccessException, ExecutionException {
return getMapAnnotations(client).stream()
.map(MapAnnotationWrapper::getContentAsEntryList)
.flatMap(List::stream)
.collect(toList());
}


/**
* Gets the value from a Key-Value pair associated to the object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ private static NamedValue toNamedValue(Entry<String, String> entry) {
* Gets the List of NamedValue contained in the map annotation.
*
* @return MapAnnotationData content.
*
* @deprecated This method will be removed in a future version.
*/
@Deprecated
@SuppressWarnings("unchecked")
public List<NamedValue> getContent() {
return (List<NamedValue>) data.getContent();
Expand Down
13 changes: 12 additions & 1 deletion src/test/java/fr/igred/omero/repository/ImageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
import java.util.NoSuchElementException;

import static java.lang.Math.abs;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
Expand Down Expand Up @@ -147,13 +150,21 @@ void testGetAnnotations() throws Exception {


@Test
void testGetKeyValuePair1() throws Exception {
void testGetKeyValuePair0() throws Exception {
ImageWrapper image = client.getImage(IMAGE1.id);
Map<String, String> pairs = image.getKeyValuePairs(client);
assertEquals(2, pairs.size());
}


@Test
void testGetKeyValuePair1() throws Exception {
ImageWrapper image = client.getImage(IMAGE1.id);
List<Map.Entry<String, String>> pairs = image.getKeyValuePairsAsList(client);
assertEquals(2, pairs.size());
}


@Test
void testGetKeyValuePair2() throws Exception {
ImageWrapper image = client.getImage(IMAGE1.id);
Expand Down

0 comments on commit 7c3670c

Please sign in to comment.