mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
add /apis.json and (re)add .../versions.json paths
This commit is contained in:
@ -29,9 +29,60 @@ import java.util.List;
|
||||
/*******************************************************************************
|
||||
** List.of is "great", but annoying because it makes unmodifiable lists...
|
||||
** So, replace it with this, which returns ArrayLists, which "don't suck"
|
||||
**
|
||||
** Can use it 3 ways:
|
||||
** ListBuilder.of(value, value2, ...) => List (an ArrayList)
|
||||
** ListBuilder.<ElementType>of(SomeList::new).with(value).with(value2)...build() => SomeList (the type you specify)
|
||||
** new ListBuilder.<ElementType>.with(value).with(value2)...build() => List (an ArrayList - for when you have more than 10 values...)
|
||||
*******************************************************************************/
|
||||
public class ListBuilder
|
||||
public class ListBuilder<E>
|
||||
{
|
||||
private List<E> list;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Constructor
|
||||
**
|
||||
*******************************************************************************/
|
||||
public ListBuilder()
|
||||
{
|
||||
this.list = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Constructor
|
||||
**
|
||||
*******************************************************************************/
|
||||
public ListBuilder(List<E> list)
|
||||
{
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public ListBuilder<E> with(E value)
|
||||
{
|
||||
list.add(value);
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public List<E> build()
|
||||
{
|
||||
return (this.list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
|
@ -22,6 +22,8 @@
|
||||
package com.kingsrook.qqq.backend.core.utils.collections;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -69,4 +71,22 @@ class ListBuilderTest
|
||||
///////////////////////////////////////
|
||||
list.add(4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testBuilderMode()
|
||||
{
|
||||
List<String> builtList = new ListBuilder<String>().with("A").with("B").build();
|
||||
assertEquals(List.of("A", "B"), builtList);
|
||||
assertEquals(ArrayList.class, builtList.getClass());
|
||||
|
||||
List<String> builtLinkedList = new ListBuilder<String>(new LinkedList<>()).with("A").with("B").build();
|
||||
assertEquals(List.of("A", "B"), builtLinkedList);
|
||||
assertEquals(LinkedList.class, builtLinkedList.getClass());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user