Skip to content

Commit

Permalink
implementing factory-methods on SimpleOrderedMap
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoh committed Jan 10, 2025
1 parent 7bcb2d9 commit e1ab4a7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ public SimpleOrderedMap<Object> getFacetFieldCounts() throws IOException, Syntax
String[] facetFs = global.getParams(FacetParams.FACET_FIELD);

if (null == facetFs) {
return SimpleOrderedMap.empty();
return SimpleOrderedMap.of();
}

// Passing a negative number for FACET_THREADS implies an unlimited number of threads is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,37 @@ public SimpleOrderedMap<T> clone() {
* Returns a shared, empty, and immutable instance of SimpleOrderedMap.
* @return empty SimpleOrderedMap (immutable)
*/
public static SimpleOrderedMap<Object> empty() {
public static SimpleOrderedMap<Object> of() {
return EMPTY;
}

/**
* Returns an immutable instance of SimpleOrderedMap with a single element.
* @return List containing the elements
*/
public static SimpleOrderedMap<Object> of(Object o1) {
return new SimpleOrderedMap<>(List.of(o1));
}

/**
* Returns an immutable instance of SimpleOrderedMap with two elements.
* @return List containing the elements
*/
public static SimpleOrderedMap<Object> of(Object o1, Object o2) {
return new SimpleOrderedMap<>(List.of(o1,o2));
}

/**
* Returns an immutable instance of SimpleOrderedMap with an arbitrary number of elements.
* @return List containing the elements
*/
public static SimpleOrderedMap<Object> of(Object... elements) {
return switch (elements.length) {
case 0 -> of();
case 1 -> of(elements[0]);
case 2 -> of(elements[0], elements[1]);
default -> new SimpleOrderedMap<>(List.of(elements));
};
}

}

0 comments on commit e1ab4a7

Please sign in to comment.