Java List Starts with startsWith(List left, List right, boolean equals)

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

Description

starts With

License

Open Source License

Declaration

public static boolean startsWith(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:// w w w  .j a  va2s  . c  o  m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.List;

public class Main {
    public static boolean startsWith(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(i), right.get(i)))
                return false;
        return true;
    }

    public static boolean startsWith(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[i], right[i]))
                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. startsWith(List left, List right, boolean equals)
  2. startsWith(List list0, List list1)
  3. startsWith(List string, List prefix)
  4. startsWithAny(String s, List prefixes)
  5. startsWithWord(String aTarget, List aExpectWordList)