List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException(int index)
From source file:de.codesourcery.jasm16.compiler.CompilationUnit.java
@Override public Line getLineByNumber(int lineNumber) throws IndexOutOfBoundsException { final Line result = lines.get(lineNumber); if (result == null) { throw new IndexOutOfBoundsException("No line with number " + lineNumber); }/*from w w w. j a va 2s. co m*/ return result; }
From source file:com.link_intersystems.lang.reflect.Member2.java
/** * @param index//from ww w. j a v a2 s . c om * @return * @since 1.0.0.0 */ protected Parameter getParameter(int index) { List<Parameter> parametersInternal = getParameters(); if (index < parametersInternal.size()) { return parametersInternal.get(index); } else if (isVarArgs() && parametersInternal.size() > 0) { Parameter parameterInfoImpl = parametersInternal.get(parametersInternal.size() - 1); return parameterInfoImpl; } else { throw new IndexOutOfBoundsException("unable to get parameter info for index " + index + ". Paramter length is " + parametersInternal.size()); } }
From source file:com.netflix.config.ConcurrentCompositeConfiguration.java
private void checkIndex(int newIndex) { if (newIndex < 0 || newIndex > configList.size()) { throw new IndexOutOfBoundsException( newIndex + " is out of bounds of the size of configuration list " + configList.size()); }/*w w w. j a v a2 s . c om*/ }
From source file:com.slytechs.utils.region.FlexRegion.java
private final int getSegmentIndex(final long position) { /*//from www .jav a 2 s. c o m * Optimize for 1 single segment list, no need to initiate an Iterator * object */ if ((this.segments.size() == 1) && this.segments.getFirst().checkBoundsGlobal(position)) { return 0; } int i = 0; for (final RegionSegment<T> ds : this.segments) { if (ds.checkBoundsGlobal(position)) { return i; } i++; } throw new IndexOutOfBoundsException("Position out of bounds [" + position + "]"); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.localworkspace.IgnoreFile.java
/** * Similar to .NET's String.Compare(String, Int32, String, Int32, Int32, * StringComparison), but always does a locale-invariant case-insensitive * comparison instead of honoring a StringComparison arg. * <p>/*from w w w . j a va 2 s. c o m*/ * This method is here and not in {@link LocaleInvariantStringHelpers} * because it does bounds checking in the .NET way, which differs from * Java's {@link String#regionMatches(boolean, int, String, int, int)} * enough to keep it separate. But the match algorithm at the bottom could * be useful in a new method there. */ private int compareCaseInsensitive(final String strA, final int offsetA, final String strB, final int offsetB, final int length) { if (strA == null && strB != null) { return -1; } else if (strA != null && strB == null) { return 1; } // .NET is documented to throw when length > 0 and one is not null else if ((strA == null || strB == null) && length > 0) { throw new IndexOutOfBoundsException("length cannot be > 0 with null string arguments"); //$NON-NLS-1$ } // End values exclusive final int endA = offsetA + length; final int endB = offsetB + length; if (endA > strA.length()) { throw new IndexOutOfBoundsException("offsetA + length is past the end of strA"); //$NON-NLS-1$ } if (endB > strB.length()) { throw new IndexOutOfBoundsException("offsetB + length is past the end of strB"); //$NON-NLS-1$ } /* * We checked that we won't walk off the end of either string, so we can * use just one of the end indices (endA) to limit our loop. */ for (int iA = offsetA, iB = offsetB; iA < endA; iA++, iB++) { char a = strA.charAt(iA); char b = strB.charAt(iB); if (a != b) { // Try both as upper case a = Character.toUpperCase(a); b = Character.toUpperCase(b); if (a != b) { // Try both as lower case a = Character.toLowerCase(a); b = Character.toLowerCase(b); if (a != b) { // Unicode difference works return a - b; } } } } // Got to end of both segments without a difference return 0; }
From source file:tw.com.sti.store.api.android.AndroidApiService.java
public List<NameValuePair> createRequestParams(String[] paramNames, String[] paramValues, boolean withToken, Integer appfilter, String userId, String pwd) { List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("store", storeId)); nvps.add(new BasicNameValuePair("aver", sdkVer)); nvps.add(new BasicNameValuePair("arel", sdkRel)); nvps.add(new BasicNameValuePair("cver", clientVer)); nvps.add(new BasicNameValuePair("lang", Locale.getDefault().toString())); TimeZone tz = TimeZone.getDefault(); nvps.add(new BasicNameValuePair("tzid", tz.getID())); nvps.add(new BasicNameValuePair("tzrawoffset", "" + tz.getRawOffset())); String time = "" + System.currentTimeMillis(); nvps.add(new BasicNameValuePair("time", time)); String vstring = storeId + "|" + time; if (userId != null && pwd != null) { vstring = storeId + "|" + time + "|" + userId + "|" + pwd; } else if (withToken && this.credential.getToken() != null && this.credential.getToken().length() > 0) { vstring = storeId + "|" + time + "|" + this.credential.getToken(); } else if (deviceId != null && subscriberId != null && simSerialNumber != null) { vstring = storeId + "|" + time + "|" + deviceId + "|" + subscriberId + "|" + simSerialNumber; }//from w ww .jav a 2 s . com L.d("vstring=" + vstring); String vsign = ""; try { vsign = Dsa.sign(vstring, this.config.getApiPrivkey()); } catch (Exception e) { } nvps.add(new BasicNameValuePair("vsign", vsign)); nvps.add(new BasicNameValuePair("imei", deviceId)); nvps.add(new BasicNameValuePair("mac", macAddress)); nvps.add(new BasicNameValuePair("imsi", subscriberId)); nvps.add(new BasicNameValuePair("iccid", simSerialNumber)); nvps.add(new BasicNameValuePair("dvc", Build.MODEL)); nvps.add(new BasicNameValuePair("wpx", wpx)); nvps.add(new BasicNameValuePair("hpx", hpx)); if (appfilter == null) { //?appFilter() nvps.add(new BasicNameValuePair("appfilter", "" + appFilter)); } else { //?appfilter nvps.add(new BasicNameValuePair("appfilter", "" + appfilter)); } //??? if (this.config.getSnum() != null && this.config.getSnum().length() > 0) { nvps.add(new BasicNameValuePair("snum", this.config.getSnum())); } if (withToken && this.credential.getToken() != null && this.credential.getToken().length() > 0) { nvps.add(new BasicNameValuePair("token", this.credential.getToken())); } if (paramNames == null || paramValues == null) { return nvps; } if (paramNames.length != paramValues.length) { throw new IndexOutOfBoundsException("paramNames.length != paramValues.length"); } int count = paramNames.length; for (int i = 0; i < count; i++) { nvps.add(new BasicNameValuePair(paramNames[i], paramValues[i])); } return nvps; }
From source file:hivemall.utils.math.MatrixUtils.java
@Nonnull public static RealMatrix[] unflatten(@Nonnull final double[] data, final int rows, final int cols, final int len) { final RealMatrix[] grid = new RealMatrix[len]; int offset = 0; for (int k = 0; k < len; k++) { RealMatrix cell = new BlockRealMatrix(rows, cols); grid[k] = cell;/*from ww w .ja v a2 s .co m*/ for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (offset >= data.length) { throw new IndexOutOfBoundsException( "Offset " + offset + " exceeded data.length " + data.length); } double value = data[offset]; cell.setEntry(i, j, value); offset++; } } } if (offset != data.length) { throw new IllegalArgumentException("Invalid data for unflatten"); } return grid; }
From source file:com.alkacon.opencms.documentcenter.CmsDocumentList.java
/** * Check if the given index is in range. If not, throw an appropriate * runtime exception. This method does *not* check if the index is * negative: It is always used immediately prior to an array access, * which throws an ArrayIndexOutOfBoundsException if index is negative. * // w w w . ja v a2 s. co m * @param index the index to check */ private void rangeCheck(int index) { if ((index > m_size) || (index < 0)) { throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + m_size); } }
From source file:net.grinder.util.Preconditions.java
/** * Ensures that {@code index} specifies a valid <i>element</i> in an array, list or string of * size {@code size}. An element index may range from zero, inclusive, to {@code size}, * exclusive./*from w ww . j a v a2 s. c o m*/ * * @param index * a user-supplied index identifying an element of an array, list or string * @param size * the size of that array, list or string * @param desc * the text to use to describe this index in an error message * @return the value of {@code index} */ public static int checkElementIndex(int index, int size, @Nullable String desc) { // Carefully optimized for execution by hotspot (explanatory comment // above) if (index < 0 || index >= size) { throw new IndexOutOfBoundsException(badElementIndex(index, size, desc)); } return index; }
From source file:Main.java
/** * <p>Removes the element at the specified position from the specified array. * All subsequent elements are shifted to the left (subtracts one from * their indices).</p>//w w w .j av a2 s . com * * <p>This method returns a new array with the same elements of the input * array except the element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p> * * <p>If the input array is {@code null}, an IndexOutOfBoundsException * will be thrown, because in that case no valid index can be specified.</p> * * @param array the array to remove the element from, may not be {@code null} * @param index the position of the element to be removed * @return A new array containing the existing elements except the element * at the specified position. * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index >= array.length), or if the array is {@code null}. * @since 2.1 */ private static Object remove(final Object array, final int index) { final int length = getLength(array); if (index < 0 || index >= length) { throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length); } final Object result = Array.newInstance(array.getClass().getComponentType(), length - 1); System.arraycopy(array, 0, result, 0, index); if (index < length - 1) { System.arraycopy(array, index + 1, result, index, length - index - 1); } return result; }