33import java .util .ArrayList ;
44import java .util .Collections ;
55import java .util .Comparator ;
6- import java .util .Map ;
76import java .util .HashMap ;
87import java .util .List ;
8+ import java .util .Map ;
99
1010/**
1111 * The InkList is the underlying type that's used to store an instance of a list
@@ -47,7 +47,7 @@ public InkList(String singleOriginListName, Story originStory) throws Exception
4747 ListDefinition def = originStory .getListDefinitions ().getListDefinition (singleOriginListName );
4848
4949 if (def != null ) {
50- origins = new ArrayList <ListDefinition >();
50+ origins = new ArrayList <>();
5151 origins .add (def );
5252 } else
5353 throw new Exception (
@@ -60,6 +60,22 @@ public InkList(String singleOriginListName, Story originStory) throws Exception
6060 public InkList (InkList otherList ) {
6161 super (otherList );
6262 this .originNames = otherList .originNames ;
63+
64+ if (otherList .origins != null ) {
65+ origins = new ArrayList <>(otherList .origins );
66+ }
67+ }
68+
69+ /**
70+ * Converts a string to an ink list and returns for use in the story.
71+ */
72+ public static InkList FromString (String myListItem , Story originStory ) throws Exception {
73+ ListValue listValue = originStory .getListDefinitions ().findSingleItemListWithName (myListItem );
74+ if (listValue != null )
75+ return new InkList (listValue .value );
76+ else
77+ throw new Exception ("Could not find the InkListItem from the string '" + myListItem
78+ + "' to create an InkList because it doesn't exist in the original list definition in ink." );
6379 }
6480
6581 ListDefinition getOriginOfMaxItem () {
@@ -86,7 +102,7 @@ public List<ListDefinition> getOrigins() {
86102 public List <String > getOriginNames () {
87103 if (this .size () > 0 ) {
88104 if (originNames == null && this .size () > 0 )
89- originNames = new ArrayList <String >();
105+ originNames = new ArrayList <>();
90106 else
91107 originNames .clear ();
92108
@@ -98,15 +114,15 @@ public List<String> getOriginNames() {
98114 }
99115
100116 void setInitialOriginName (String initialOriginName ) {
101- originNames = new ArrayList <String >();
117+ originNames = new ArrayList <>();
102118 originNames .add (initialOriginName );
103119 }
104120
105121 void setInitialOriginNames (List <String > initialOriginNames ) {
106122 if (initialOriginNames == null )
107123 originNames = null ;
108124 else {
109- originNames = new ArrayList <String >();
125+ originNames = new ArrayList <>();
110126 originNames .addAll (initialOriginNames );
111127 }
112128 }
@@ -128,8 +144,7 @@ public InkList union(InkList otherList) {
128144 * items removed that are in the passed in list. Equivalent to calling (list1 -
129145 * list2) in ink.
130146 *
131- * @param listToRemove
132- * List to remove.
147+ * @param listToRemove List to remove.
133148 */
134149
135150 public InkList without (InkList listToRemove ) {
@@ -191,8 +206,7 @@ public Map.Entry<InkListItem, Integer> getMinItem() {
191206 * Returns true if the current list contains all the items that are in the list
192207 * that is passed in. Equivalent to calling (list1 ? list2) in ink.
193208 *
194- * @param otherList
195- * Other list.
209+ * @param otherList Other list.
196210 */
197211 public boolean contains (InkList otherList ) {
198212 for (Map .Entry <InkListItem , Integer > kv : otherList .entrySet ()) {
@@ -505,7 +519,7 @@ public int hashCode() {
505519 }
506520
507521 List <Entry <InkListItem , Integer >> getOrderedItems () {
508- List <Entry <InkListItem , Integer >> ordered = new ArrayList <Entry < InkListItem , Integer > >(entrySet ());
522+ List <Entry <InkListItem , Integer >> ordered = new ArrayList <>(entrySet ());
509523
510524 Collections .sort (ordered , new Comparator <Entry <InkListItem , Integer >>() {
511525 @ Override
0 commit comments