Skip to content

Commit

Permalink
use java.util.Map to implement Multiset
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuyi Chen committed Sep 16, 2017
1 parent 138e78d commit d58071e
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 386 deletions.
7 changes: 0 additions & 7 deletions flink-core/pom.xml
Expand Up @@ -80,13 +80,6 @@ under the License.
<!-- managed version -->
</dependency>

<!-- For multiset -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>

<!-- Avro is needed for the interoperability with Avro types for serialization -->
<dependency>
<groupId>org.apache.avro</groupId>
Expand Down

This file was deleted.

Expand Up @@ -18,12 +18,11 @@

package org.apache.flink.api.java.typeutils;

import org.apache.commons.collections4.multiset.AbstractMultiSet;
import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.api.common.typeutils.base.MultisetSerializer;

import java.util.Map;

import static org.apache.flink.util.Preconditions.checkNotNull;

Expand All @@ -33,19 +32,17 @@
* @param <T> The type of the elements in the Multiset.
*/
@PublicEvolving
public final class MultisetTypeInfo<T> extends TypeInformation<AbstractMultiSet<T>> {
public final class MultisetTypeInfo<T> extends MapTypeInfo<T, Integer> {

private static final long serialVersionUID = 1L;

private final TypeInformation<T> elementTypeInfo;


public MultisetTypeInfo(Class<T> elementTypeClass) {
this.elementTypeInfo = of(checkNotNull(elementTypeClass, "elementTypeClass"));
super(elementTypeClass, Integer.class);
}

public MultisetTypeInfo(TypeInformation<T> elementTypeInfo) {
this.elementTypeInfo = checkNotNull(elementTypeInfo, "elementTypeInfo");
super(elementTypeInfo, BasicTypeInfo.INT_TYPE_INFO);
}

// ------------------------------------------------------------------------
Expand All @@ -56,7 +53,7 @@ public MultisetTypeInfo(TypeInformation<T> elementTypeInfo) {
* Gets the type information for the elements contained in the Multiset
*/
public TypeInformation<T> getElementTypeInfo() {
return elementTypeInfo;
return getKeyTypeInfo();
}

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -87,26 +84,20 @@ public int getTotalFields() {

@SuppressWarnings("unchecked")
@Override
public Class<AbstractMultiSet<T>> getTypeClass() {
return (Class<AbstractMultiSet<T>>)(Class<?>)AbstractMultiSet.class;
public Class<Map<T, Integer>> getTypeClass() {
return (Class<Map<T, Integer>>)(Class<?>)Map.class;
}

@Override
public boolean isKeyType() {
return false;
}

@Override
public TypeSerializer<AbstractMultiSet<T>> createSerializer(ExecutionConfig config) {
TypeSerializer<T> elementTypeSerializer = elementTypeInfo.createSerializer(config);
return new MultisetSerializer<>(elementTypeSerializer);
}

// ------------------------------------------------------------------------

@Override
public String toString() {
return "Multiset<" + elementTypeInfo + '>';
return "Multiset<" + getKeyTypeInfo() + '>';
}

@Override
Expand All @@ -116,15 +107,15 @@ public boolean equals(Object obj) {
}
else if (obj instanceof MultisetTypeInfo) {
final MultisetTypeInfo<?> other = (MultisetTypeInfo<?>) obj;
return other.canEqual(this) && elementTypeInfo.equals(other.elementTypeInfo);
return other.canEqual(this) && getKeyTypeInfo().equals(other.getKeyTypeInfo());
} else {
return false;
}
}

@Override
public int hashCode() {
return 31 * elementTypeInfo.hashCode() + 1;
return 31 * getKeyTypeInfo().hashCode() + 1;
}

@Override
Expand Down

This file was deleted.

0 comments on commit d58071e

Please sign in to comment.