Java List Ends with endsWith(List left, List right, boolean equals)

Here you can find the source of endsWith(List left, List right, boolean equals)

Description

ends With

License

Open Source License

Declaration

public static boolean endsWith(List left, List right, boolean equals) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from   ww  w .j a  v a2s  .c  o m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.List;

public class Main {
    public static boolean endsWith(List left, List right, boolean equals) {
        if (left == null || right == null)
            return false;
        int l = left.size();
        int r = right.size();
        if (r > l || !equals && r == l)
            return false;

        for (int i = 0; i < r; i++)
            if (!equals(left.get(l - i - 1), right.get(r - i - 1)))
                return false;
        return true;
    }

    public static boolean endsWith(Object[] left, Object[] right,
            boolean equals) {
        if (left == null || right == null)
            return false;
        int l = left.length;
        int r = right.length;
        if (r > l || !equals && r == l)
            return false;
        for (int i = 0; i < r; i++)
            if (!equals(left[l - i - 1], right[r - i - 1]))
                return false;
        return true;
    }

    public static boolean equals(boolean left, boolean right) {
        return left == right;
    }

    public static boolean equals(int left, int right) {
        return left == right;
    }

    public static boolean equals(Object left, Object right) {
        return left == null ? right == null : left.equals(right);
    }
}

Related

  1. endsWith(List left, List right, boolean equals)
  2. endsWith(List source, List prefix)
  3. endsWith(List hierarchy, String... items)
  4. endsWith(List lst, List suffix)
  5. endsWith(List string, List suffix)