11package org .dbsp .simulator .collections ;
22
33import org .dbsp .simulator .AggregateDescription ;
4+ import org .dbsp .simulator .types .Weight ;
45import org .dbsp .simulator .types .WeightType ;
56import org .dbsp .simulator .util .IIndentStream ;
67import org .dbsp .simulator .util .ToIndentableString ;
1112import java .util .function .Function ;
1213import java .util .function .Predicate ;
1314
14- public class ZSet <Data , Weight > extends BaseCollection < Weight > implements ToIndentableString {
15+ public class ZSet <Data > extends BaseCollection implements ToIndentableString {
1516 /** Maps values to weights. Invariant: weights are never zero */
1617 final Map <Data , Weight > data ;
17- final WeightType <Weight > weightType ;
1818
1919 /** Create a Z-set by cloning the data from the specified map. */
20- public ZSet (Map <Data , Weight > data , WeightType <Weight > weightType ) {
20+ public ZSet (Map <Data , Weight > data , WeightType weightType ) {
21+ super (weightType );
2122 this .data = new HashMap <>();
22- this .weightType = weightType ;
2323 for (Map .Entry <Data , Weight > datum : data .entrySet ()) {
2424 if (!this .weightType .isZero (datum .getValue ()))
2525 this .data .put (datum .getKey (), datum .getValue ());
@@ -37,28 +37,28 @@ public int entryCount() {
3737 }
3838
3939 /** Create an empty Z-set */
40- public ZSet (WeightType <Weight > weightType ) {
40+ public ZSet (WeightType weightType ) {
41+ super (weightType );
4142 this .data = new HashMap <>();
42- this .weightType = weightType ;
4343 }
4444
45- public ZSet (Collection <Data > data , WeightType <Weight > weightType ) {
45+ public ZSet (Collection <Data > data , WeightType weightType ) {
46+ super (weightType );
4647 this .data = new HashMap <>();
47- this .weightType = weightType ;
4848 for (Data datum : data ) {
4949 this .data .merge (datum , this .weightType .one (), this ::merger );
5050 }
5151 }
5252
53- public ZSet <Data , Weight > negate () {
53+ public ZSet <Data > negate () {
5454 Map <Data , Weight > result = new HashMap <>();
5555 for (Map .Entry <Data , Weight > entry : this .data .entrySet ()) {
5656 result .put (entry .getKey (), this .weightType .negate (entry .getValue ()));
5757 }
5858 return new ZSet <>(result , this .weightType );
5959 }
6060
61- public static <Data , Weight > ZSet <Data , Weight > zero (WeightType < Weight > weightType ) {
61+ public static <Data , Weight > ZSet <Data > zero (WeightType weightType ) {
6262 return new ZSet <>(weightType );
6363 }
6464
@@ -70,18 +70,18 @@ Weight merger(Weight oldWeight, Weight newWeight) {
7070 return w ;
7171 }
7272
73- public ZSet <Data , Weight > add (ZSet <Data , Weight > other ) {
73+ public ZSet <Data > add (ZSet <Data > other ) {
7474 Map <Data , Weight > result = new HashMap <>(this .data );
7575 for (Map .Entry <Data , Weight > entry : other .data .entrySet ()) {
7676 result .merge (entry .getKey (), entry .getValue (), this ::merger );
7777 }
7878 return new ZSet <>(result , this .weightType );
7979 }
8080
81- public <OtherData , Result > ZSet <Result , Weight > multiply (
82- ZSet <OtherData , Weight > other ,
81+ public <OtherData , Result > ZSet <Result > multiply (
82+ ZSet <OtherData > other ,
8383 BiFunction <Data , OtherData , Result > combiner ) {
84- ZSet <Result , Weight > result = new ZSet <>(this .weightType );
84+ ZSet <Result > result = new ZSet <>(this .weightType );
8585 for (Map .Entry <Data , Weight > entry : this .data .entrySet ()) {
8686 for (Map .Entry <OtherData , Weight > otherEntry : other .data .entrySet ()) {
8787 Result data = combiner .apply (entry .getKey (), otherEntry .getKey ());
@@ -92,36 +92,36 @@ public <OtherData, Result> ZSet<Result, Weight> multiply(
9292 return result ;
9393 }
9494
95- public ZSet <Data , Weight > subtract (ZSet <Data , Weight > other ) {
95+ public ZSet <Data > subtract (ZSet <Data > other ) {
9696 Map <Data , Weight > result = new HashMap <>(this .data );
9797 for (Map .Entry <Data , Weight > entry : other .data .entrySet ()) {
9898 result .merge (entry .getKey (), this .weightType .negate (entry .getValue ()), this ::merger );
9999 }
100100 return new ZSet <>(result , this .weightType );
101101 }
102102
103- public ZSet <Data , Weight > append (Data data , Weight weight ) {
103+ public ZSet <Data > append (Data data , Weight weight ) {
104104 this .data .merge (data , weight , this ::merger );
105105 return this ;
106106 }
107107
108- public boolean equals (ZSet <Data , Weight > other ) {
108+ public boolean equals (ZSet <Data > other ) {
109109 return this .subtract (other ).isEmpty ();
110110 }
111111
112- public ZSet <Data , Weight > append (Data data ) {
112+ public ZSet <Data > append (Data data ) {
113113 this .append (data , this .weightType .one ());
114114 return this ;
115115 }
116116
117- public ZSet <Data , Weight > append (ZSet <Data , Weight > other ) {
117+ public ZSet <Data > append (ZSet <Data > other ) {
118118 for (Map .Entry <Data , Weight > entry : other .data .entrySet ()) {
119119 this .data .merge (entry .getKey (), entry .getValue (), this ::merger );
120120 }
121121 return this ;
122122 }
123123
124- public ZSet <Data , Weight > positive (boolean set ) {
124+ public ZSet <Data > positive (boolean set ) {
125125 Map <Data , Weight > result = new HashMap <>();
126126 for (Map .Entry <Data , Weight > entry : this .data .entrySet ()) {
127127 Weight weight = entry .getValue ();
@@ -134,11 +134,11 @@ public ZSet<Data, Weight> positive(boolean set) {
134134 return new ZSet <>(result , this .weightType );
135135 }
136136
137- public ZSet <Data , Weight > distinct () {
137+ public ZSet <Data > distinct () {
138138 return this .positive (true );
139139 }
140140
141- public <OData > ZSet <OData , Weight > map (Function <Data , OData > tupleTransform ) {
141+ public <OData > ZSet <OData > map (Function <Data , OData > tupleTransform ) {
142142 Map <OData , Weight > result = new HashMap <>();
143143 for (Map .Entry <Data , Weight > entry : this .data .entrySet ()) {
144144 Weight weight = entry .getValue ();
@@ -148,7 +148,7 @@ public <OData> ZSet<OData, Weight> map(Function<Data, OData> tupleTransform) {
148148 return new ZSet <>(result , this .weightType );
149149 }
150150
151- public ZSet <Data , Weight > filter (Predicate <Data > keep ) {
151+ public ZSet <Data > filter (Predicate <Data > keep ) {
152152 Map <Data , Weight > result = new HashMap <>();
153153 for (Map .Entry <Data , Weight > entry : this .data .entrySet ()) {
154154 Weight weight = entry .getValue ();
@@ -158,8 +158,8 @@ public ZSet<Data, Weight> filter(Predicate<Data> keep) {
158158 return new ZSet <>(result , this .weightType );
159159 }
160160
161- public <Key > IndexedZSet <Key , Data , Weight > index (Function <Data , Key > key ) {
162- IndexedZSet <Key , Data , Weight > result = new IndexedZSet <>(this .weightType );
161+ public <Key > IndexedZSet <Key , Data > index (Function <Data , Key > key ) {
162+ IndexedZSet <Key , Data > result = new IndexedZSet <>(this .weightType );
163163 for (Map .Entry <Data , Weight > entry : this .data .entrySet ()) {
164164 Weight weight = entry .getValue ();
165165 Key keyValue = key .apply (entry .getKey ());
@@ -186,20 +186,20 @@ public Collection<Data> toCollection() {
186186 return result ;
187187 }
188188
189- public ZSet <Data , Weight > union (ZSet <Data , Weight > other ) {
189+ public ZSet <Data > union (ZSet <Data > other ) {
190190 return this .add (other ).distinct ();
191191 }
192192
193- public ZSet <Data , Weight > union_all (ZSet <Data , Weight > other ) {
193+ public ZSet <Data > union_all (ZSet <Data > other ) {
194194 return this .add (other );
195195 }
196196
197- public ZSet <Data , Weight > except (ZSet <Data , Weight > other ) {
197+ public ZSet <Data > except (ZSet <Data > other ) {
198198 return this .distinct ().subtract (other .distinct ()).distinct ();
199199 }
200200
201201 public <Result , IntermediateResult > Result aggregate (
202- AggregateDescription <Result , IntermediateResult , Data , Weight > aggregate ) {
202+ AggregateDescription <Result , IntermediateResult , Data > aggregate ) {
203203 IntermediateResult result = aggregate .initialValue ;
204204 for (Map .Entry <Data , Weight > entry : this .data .entrySet ()) {
205205 Weight weight = entry .getValue ();
0 commit comments