Java List Sort getOverlapCount(List list1, List list2, boolean sorted)

Here you can find the source of getOverlapCount(List list1, List list2, boolean sorted)

Description

get Overlap Count

License

Apache License

Declaration

public static <T extends Comparable<T>> int getOverlapCount(List<T> list1, List<T> list2, boolean sorted) 

Method Source Code

//package com.java2s;
/**/*from   w  w w  .  j  a  v a2s. com*/
 * Copyright 2015, Emory University
 * 
 * Licensed 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.Collections;

import java.util.List;

public class Main {
    public static <T extends Comparable<T>> int getOverlapCount(List<T> list1, List<T> list2, boolean sorted) {
        if (!sorted) {
            Collections.sort(list1);
            Collections.sort(list2);
        }

        if (list1.size() > list2.size()) {
            List<T> temp = list1;
            list1 = list2;
            list2 = temp;
        }

        T l1_ele, l2_ele;
        int i = 0, j = 0, comp, count = 0, size1 = list1.size(), size2 = list2.size();

        for (; i < size1; i++) {
            l1_ele = list1.get(i);

            for (; j < size2; j++) {
                l2_ele = list2.get(j);

                comp = l1_ele.compareTo(l2_ele);
                if (comp > 0)
                    continue;
                else if (comp == 0) {
                    j++;
                    count++;
                }
                break;
            }
        }

        return count;
    }
}

Related

  1. equalUnsorted(List list1, List list2)
  2. extractRankedProducts( List unsortedProducts)
  3. formatAsSortUniqCSVString(List s)
  4. getIndexForSortedInsert(final List listSorted, final String item)
  5. getNumberListSorted(String pagesStr)
  6. getSortedFilesList(String filesList)
  7. getSortedKetList(HashMap numKnownGenesHashMap)
  8. getSortedList(Collection collection)
  9. getSortedList(Set items)