1 21 22 package org.opensubsystems.core.util; 23 24 32 public final class ArrayUtils 33 { 34 37 private ArrayUtils( 38 ) 39 { 40 } 42 43 45 54 public static int[] exclude( 55 int[] arrBase, 56 int[] arrExclude 57 ) 58 { 59 int[] arrReturn = null; 60 61 if ((arrBase != null) && (arrBase.length > 0) && (arrExclude != null) 62 && (arrExclude.length > 0)) 63 { 64 int[] arrHelp; 65 int iCount1; 66 int iHelp; 67 int iLength = 0; 68 69 arrHelp = new int[arrBase.length]; 70 for (iCount1 = 0; iCount1 < arrBase.length; iCount1++) 71 { 72 iHelp = arrBase[iCount1]; 73 if (ArrayUtils.contains(arrExclude, iHelp) == -1) 74 { 75 arrHelp[iLength++] = iHelp; 78 } 79 } 80 81 arrReturn = new int[iLength]; 84 for (int iCount = 0; iCount < iLength; iCount++) 85 { 86 arrReturn[iCount] = arrHelp[iCount]; 87 } 88 } 89 else 90 { 91 arrReturn = arrBase; 92 } 93 94 return arrReturn; 95 } 96 97 105 public static int contains( 106 int[] source, 107 int iTarget 108 ) 109 { 110 int iReturn = -1; 111 112 if ((source != null) && (source.length > 0)) 113 { 114 int iIndex; 115 116 for (iIndex = 0; iIndex < source.length; iIndex++) 117 { 118 if (source[iIndex] == iTarget) 119 { 120 iReturn = iIndex; 121 break; 122 } 123 } 124 } 125 126 return iReturn; 127 } 128 129 135 public static long sum( 136 int[] source 137 ) 138 { 139 int iReturn = 0; 140 141 if ((source != null) && (source.length > 0)) 142 { 143 int iIndex; 144 145 for (iIndex = 0; iIndex < source.length; iIndex++) 146 { 147 iReturn += source[iIndex]; 148 } 149 } 150 151 return iReturn; 152 } 153 } 154 | Popular Tags |