Bill commented on a change in pull request #5273: URL: https://github.com/apache/geode/pull/5273#discussion_r446470963
########## File path: geode-serialization/src/main/java/org/apache/geode/internal/serialization/VersionOrdinalImpl.java ########## @@ -0,0 +1,132 @@ +/* + * 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.geode.internal.serialization; + +public class VersionOrdinalImpl implements VersionOrdinal { + + protected final short ordinal; + + public VersionOrdinalImpl(final short ordinal) { + this.ordinal = ordinal; + } + + @Override + public short ordinal() { + return ordinal; + } + + @Override + public int compareTo(final VersionOrdinal other) { + if (other == null) { + return 1; + } else { + return compareTo(other.ordinal()); + } + } + + /** + * TODO: eliminate this legacy method in favor of requiring callers to construct a + * VersionOrdinalImpl. Inline this logic up in compareTo(VersionOrdinal). + */ + public int compareTo(final short other) { + // short min/max can't overflow int, so use (a-b) + final int thisOrdinal = this.ordinal; + final int otherOrdinal = other; + return thisOrdinal - otherOrdinal; + } + + @Override + public boolean equals(final Object other) { + if (other == this) Review comment: I think we are ok. If `other` is `null` then it cannot be equal to `this`. if `other` is `null` the `instanceof` check will return `false` ---------------------------------------------------------------- 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]
