ArrayUtils.java :  » Database-DBMS » JODB » com » mobixess » jodb » util » Java Open Source

Java Open Source » Database DBMS » JODB 
JODB » com » mobixess » jodb » util » ArrayUtils.java
/*
Copyright (C) 2007  Mobixess Inc. http://www.java-objects-database.com

This file is part of the JODB (Java Objects Database) open source project.

JODB is free software; you can redistribute it and/or modify it under
the terms of version 2 of the GNU General Public License as published
by the Free Software Foundation.

JODB is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
*/
package com.mobixess.jodb.util;


public class ArrayUtils {
    public static int indexOf(int[] array, int value){
        for (int i = 0; i < array.length; i++) {
            if(array[i]==value){
                return i;
            }
        }
        return -1;
    }
    
    public static int indexOf(Object[] array, Object value){
        for (int i = 0; i < array.length; i++) {
            if(array[i]==value){
                return i;
            }
            if(value!=null && array[i]!=null && value.equals(array[i]) ){
                return i;
            }
        }
        return -1;
    }
    
    public static int identityIndexOf(Object[] array, Object value){
        for (int i = 0; i < array.length; i++) {
            if(array[i]==value){
                return i;
            }
        }
        return -1;
    }
    
    public static void clear(Object[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = null;
        }
    }
    
    public static String toString(int[] array){
        StringBuffer result = new StringBuffer();
        result.append('{');
        for (int i = 0; i < array.length; i++) {
            result.append(""+array[i]+",");
        }
        result.append('}');
        return result.toString();
    }
    
    

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.