All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.flink.runtime.state.ArrayListSerializer Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.flink.runtime.state; import org.apache.flink.api.common.typeutils.TypeSerializer; import org.apache.flink.core.memory.DataInputView; import org.apache.flink.core.memory.DataOutputView; import java.io.IOException; import java.util.ArrayList; @SuppressWarnings("ForLoopReplaceableByForEach") final public class ArrayListSerializer extends TypeSerializer> { private static final long serialVersionUID = 1119562170939152304L; private final TypeSerializer elementSerializer; public ArrayListSerializer(TypeSerializer elementSerializer) { this.elementSerializer = elementSerializer; } @Override public boolean isImmutableType() { return false; } @Override public TypeSerializer> duplicate() { TypeSerializer duplicateElement = elementSerializer.duplicate(); return duplicateElement == elementSerializer ? this : new ArrayListSerializer(duplicateElement); } @Override public ArrayList createInstance() { return new ArrayList<>(); } @Override public ArrayList copy(ArrayList from) { ArrayList newList = new ArrayList<>(from.size()); for (int i = 0; i < from.size(); i++) { newList.add(elementSerializer.copy(from.get(i))); } return newList; } @Override public ArrayList copy(ArrayList from, ArrayList reuse) { return copy(from); } @Override public int getLength() { return -1; // var length } @Override public void serialize(ArrayList list, DataOutputView target) throws IOException { final int size = list.size(); target.writeInt(size); for (int i = 0; i < size; i++) { elementSerializer.serialize(list.get(i), target); } } @Override public ArrayList deserialize(DataInputView source) throws IOException { final int size = source.readInt(); final ArrayList list = new ArrayList<>(size); for (int i = 0; i < size; i++) { list.add(elementSerializer.deserialize(source)); } return list; } @Override public ArrayList deserialize(ArrayList reuse, DataInputView source) throws IOException { return deserialize(source); } @Override public void copy(DataInputView source, DataOutputView target) throws IOException { // copy number of elements final int num = source.readInt(); target.writeInt(num); for (int i = 0; i < num; i++) { elementSerializer.copy(source, target); } } // -------------------------------------------------------------------- @Override public boolean equals(Object obj) { return obj == this || (obj != null && obj.getClass() == getClass() && elementSerializer.equals(((ArrayListSerializer) obj).elementSerializer)); } @Override public boolean canEqual(Object obj) { return true; } @Override public int hashCode() { return elementSerializer.hashCode(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy