Java List Reverse compareVersions(List version1, List version2)

Here you can find the source of compareVersions(List version1, List version2)

Description

compare Versions

License

Apache License

Declaration

static int compareVersions(List<Integer> version1, List<Integer> version2) 

Method Source Code

//package com.java2s;
/*/*from  w ww  .  j  a v  a  2s. c om*/
 * 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.
 */

import java.util.Iterator;
import java.util.List;

public class Main {
    static int compareVersions(List<Integer> version1, List<Integer> version2) {
        for (Iterator<Integer> it1 = version1.iterator(), it2 = version2.iterator();;) {
            if (!it1.hasNext()) {
                return it2.hasNext() ? -1 : 0;
            }
            if (!it2.hasNext()) {
                return it1.hasNext() ? 1 : 0;
            }

            Integer num1 = it1.next();
            Integer num2 = it2.next();

            int rel = num1.compareTo(num2);
            if (rel != 0) {
                return rel;
            }
        }
    }
}

Related

  1. addReverse(List list, List append)
  2. compareVersions(List list1, List list2)
  3. compareVersions(String version1, String version2)
  4. createReversedList(List inputList)
  5. firstElementOf(List list, int reverseIndexPosition)
  6. formatToIp(final List shortList, final boolean reverseOrder)