Fokko commented on a change in pull request #13635: URL: https://github.com/apache/beam/pull/13635#discussion_r558836580
########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DequeCoder.java ########## @@ -0,0 +1,82 @@ +/* + * 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.beam.sdk.coders; + +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.List; +import org.apache.beam.sdk.values.TypeDescriptor; +import org.apache.beam.sdk.values.TypeParameter; + +/** + * A {@link Coder} for {@link Deque}, using the format of {@link IterableLikeCoder}. + * + * @param <T> the type of the elements of the Deques being transcoded + */ +public class DequeCoder<T> extends IterableLikeCoder<T, Deque<T>> { + + public static <T> DequeCoder<T> of(Coder<T> elemCoder) { + return new DequeCoder<>(elemCoder); + } + + ///////////////////////////////////////////////////////////////////////////// + // Internal operations below here. + + @Override + protected Deque<T> decodeToIterable(List<T> decodedElements) { + return new ArrayDeque<>(decodedElements); + } + + protected DequeCoder(Coder<T> elemCoder) { + super(elemCoder, "Deque"); + } + + @Override + public boolean consistentWithEquals() { + return getElemCoder().consistentWithEquals(); + } + + @Override + public Object structuralValue(Deque<T> values) { Review comment: I'm actually looking into this, but it isn't that trivial. This method is only tested for the `MapCoder` and `ListCoder`. My startingpoint was the tests of the `SetCoder`, where this wasn't covered. The issue with the Deque is that it do `LinkedList` extends `AbstractSequentialList` which extends `AbstractList` which does override `equals` and `hashCode` - so the implementation is not inherited from `Object`. `ArrayDeque`, on the other hand, really doesn't inherit anything other implementation as far as I can see. Its direct superclass (`AbstractCollection`) doesn't override them. So the test is failing for the Deque since the objects aren't equal (it only tests `lhs == rhs`, as this is the equals implementation of Object. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
