Here you can find the source of arrayIndexFor(final String raw)
Parameter | Description |
---|---|
raw | DOCUMENT ME! |
protected static int arrayIndexFor(final String raw)
//package com.java2s; //License from project: LGPL public class Main { /**//from w w w. ja v a 2 s .co m * DOCUMENT ME! * * @param raw DOCUMENT ME! * * @return DOCUMENT ME! */ protected static int arrayIndexFor(final String raw) { /* * Empty? No dice. */ if (raw.isEmpty()) { return -1; } /* * Leading zeroes are not allowed in number-only refTokens for arrays. But then, 0 followed by anything else * than a number is invalid as well. So, if the string starts with '0', return 0 if the token length is 1 or -1 * otherwise. */ if (raw.charAt(0) == '0') { return (raw.length() == 1) ? 0 : -1; } /* * Otherwise, parse as an int. If we can't, -1. */ try { return Integer.parseInt(raw); } catch (NumberFormatException ignored) { return -1; } } }