Java Code Examples for org.apache.commons.lang3.ArrayUtils.indexOf()
The following are Jave code examples for showing how to use
indexOf() of the
org.apache.commons.lang3.ArrayUtils
class.
You can vote up the examples you like. Your votes will be used in our system to get
more good examples.
+ Save this method
Example 1
Project: BaseClient File: Property.java View Source Code | 6 votes |
public boolean setPropertyValue(String propVal) { if (propVal == null) { this.value = this.defaultValue; return false; } else { this.value = ArrayUtils.indexOf(this.propertyValues, propVal); if (this.value >= 0 && this.value < this.propertyValues.length) { return true; } else { this.value = this.defaultValue; return false; } } }
Example 2
Project: Backmemed File: Property.java View Source Code | 6 votes |
public boolean setPropertyValue(String propVal) { if (propVal == null) { this.value = this.defaultValue; return false; } else { this.value = ArrayUtils.indexOf(this.propertyValues, propVal); if (this.value >= 0 && this.value < this.propertyValues.length) { return true; } else { this.value = this.defaultValue; return false; } } }
Example 3
Project: alexa-utterance-generator File: WeightedSegmentsFormatter.java View Source Code | 6 votes |
public WeightedSegmentsFormatter(final String[] args) { if (args != null) { prependPriority = ArrayUtils.contains(args, "-pp") || ArrayUtils.contains(args, "-prependPriority"); int index1 = ArrayUtils.indexOf(args, "-weight"); if (index1 < args.length - 1) { final String weightString = args[index1 + 1]; Validate.isTrue(NumberUtils.isParsable(weightString), "Please provide a numeric value for weight."); this.weight = Integer.parseInt(weightString); } int index2 = ArrayUtils.indexOf(args, "-separator"); if (index2 < args.length - 1) { valueSeparator = args[index2 + 1]; } } }
Example 4
Project: alexa-utterance-generator File: UtteranceGenerator.java View Source Code | 5 votes |
private static Optional<String> getUtteranceFileKey(final String[] args) { if (args != null) { int index = ArrayUtils.indexOf(args, "-f"); if (index < args.length - 1) { return Optional.of(args[index + 1]); } } return Optional.empty(); }
Example 5
Project: ClientAPI File: MultiType.java View Source Code | 5 votes |
/** * Sets value to the last one in the set */ public final void last() { int index = ArrayUtils.indexOf(values, getValue()); if (--index < 0) index = values.length - 1; this.setValue(values[index]); }
Example 6
Project: ClientAPI File: EnumType.java View Source Code | 5 votes |
/** * Sets value to the next one in the set */ public final void next() { int index = ArrayUtils.indexOf(values, getValue()); if (++index >= values.length) index = 0; this.setValue(values[index]); }
Example 7
Project: ClientAPI File: EnumType.java View Source Code | 5 votes |
/** * Sets value to the last one in the set */ public final void last() { int index = ArrayUtils.indexOf(values, getValue()); if (--index < 0) index = values.length - 1; this.setValue(values[index]); }
Example 8
Project: ClientAPI File: ClientAPIUtils.java View Source Code | 5 votes |
/** * Returns the specified Object from the Array if the object is present in * the array. If not, the first object present in the array will be * returned if the size of the array is greater than 1, if not, the * specified Object will be returned. * * @param object The value trying to be set * @param array The array that may/may not contain the value * @return The value found from the array */ public static <T> T objectFrom(T object, T[] array) { int index = ArrayUtils.indexOf(array, object); if (index != -1) { return array[index]; } else { if (array.length > 0) { return array[0]; } else { return object; } } }
Example 9
Project: hygene File: EdgeOptimizer.java View Source Code | 5 votes |
/** * Finds the position of parent node of the current node in the previous layer, if it exists. * * @param node the node for which the parent needs to be found * @param layer the layer in which the parent needs to be found * @return the position of parent node of the current node in the previous layer, if it exists, otherwise {@code -1} */ private int parentPositionInPreviousLayer(final LayoutableNode node, final LayoutableNode[] layer) { final Optional<Edge> possibleParent = node.getIncomingEdges().stream().findFirst(); if (!possibleParent.isPresent()) { return -1; } final LayoutableNode parent = possibleParent.get().getFrom(); return ArrayUtils.indexOf(layer, parent); }
Example 10
Project: PTEAssistant File: AppointmentParser.java View Source Code | 5 votes |
public static List<Calendar> parseAvailableAppointmentTimes(String html) { int i = html.indexOf("<div id=\"divList\">"); if(i == -1) return null; int j = html.indexOf("</div>", i); String divListHtml = html.substring(i, j + "</div>".length()); List<Calendar> calendars = new ArrayList<Calendar>(); Document doc = JsoupDocumentUtils.parseUTF8HTMLDocument(divListHtml); Elements as = doc.getElementsByTag("a"); String[] monthSimpleNameArray = new String[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; String[] weekSimpleNameArray = new String[]{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; for(Iterator<Element> iter = as.iterator(); iter.hasNext(); ) { String timeStr = iter.next().text(); if(timeStr.matches("\\w{3} \\d{1,2} \\w{3} at \\d{1,2}:\\d{1,2}.*")) { String[] parts = timeStr.split(" "); Calendar cal = Calendar.getInstance(); cal.clear(); int month = ArrayUtils.indexOf(monthSimpleNameArray, parts[2]); int dayOfWeek = ArrayUtils.indexOf(weekSimpleNameArray, parts[0]); if(month != -1 && dayOfWeek != -1) { cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(parts[1])); cal.set(Calendar.DAY_OF_WEEK, dayOfWeek); if(parts.length > 5) { switch(parts[5]){ case "AM": cal.set(Calendar.AM_PM, Calendar.AM);break; case "PM": cal.set(Calendar.AM_PM, Calendar.PM); break; } } String[] hms = parts[4].split(":"); int hour = Integer.parseInt(hms[0]); cal.set(Calendar.HOUR, hour == 12 ? 0 : hour);//12小时制,值为0-11 cal.set(Calendar.MINUTE, Integer.parseInt(hms[1])); calendars.add(cal); } } } return calendars; }
Example 11
Project: advent-of-code-2017 File: Day06.java View Source Code | 5 votes |
private static List<Bank> loopOverBanks(String[] args) { Integer[] input = ArrayConverters.asIntegerArray(args); List<Bank> banks = new ArrayList<>(); int size = input.length; boolean noCycle = true; Bank bank; do { bank = new Bank(input); // it also works as init int indexOf = banks.indexOf(bank); if (indexOf != -1) { // it's the second time we see this bank, we found the loop's entry point noCycle = false; // stop this bank.hits = 2; banks.set(indexOf, bank); } else { bank.hits = 1; // it's the first time we see this bank banks.add(bank); } input = input.clone(); // cloned in order to avoid side effect on previous input int max = Arrays.stream(input).max(Integer::compareTo).get(); // bank's max value... int index = ArrayUtils.indexOf(input, max); // ... and its index input[index] = 0; // apply puzzle specs for (; max > 0; max--) { ++input[++index % size]; // circular array } } while (noCycle); return banks; }
Example 12
Project: Minecord File: MessageUtils.java View Source Code | 5 votes |
/** * Parses boolean arguments. * @param search The string array to search through. * @param include A string that also means true. * @return The first index of the boolean argument. Returns -1 if not found. */ public static int parseBoolean(String[] search, String include) { String[] words = new String[]{"true", "yes", "allow", include}; for (String word : words) { int index = ArrayUtils.indexOf(search, word); if (index > -1) { return index; } } return -1; }
Example 13
Project: froog File: CrossEntropyLoss.java View Source Code | 5 votes |
/** * * cost = -1 * ln(ak) * * @param Ycalc * @param Yobs * @return */ @Override public double cost(SimpleMatrix Ycalc, SimpleMatrix Yobs) { //averiguamos q salida correspondia para calcular el ajuste //(el resto se hace cero ya que -1 * {y = k} * ln(ak), en las // otras salidas {y != k} => 0 int Yk = ArrayUtils.indexOf(Yobs.getMatrix().getData(), 1); //obtenemso la salida double aCalc = Ycalc.get(Yk); //realizamos los calculos return -1 * Math.log(aCalc); }
Example 14
Project: alexa-utterance-generator File: SMAPIFormatter.java View Source Code | 5 votes |
public SMAPIFormatter(final String[] args) { if (args != null) { int index = ArrayUtils.indexOf(args, "-in"); if (index < args.length - 1) { final String invocationName = args[index + 1]; Validate.notBlank(invocationName, "Please provide an invocation name."); Validate.isTrue(!invocationName.startsWith("-"), "Please provide a valid invocation name."); this.model = new SMAPIModel(invocationName); } } }
Example 15
Project: alexa-utterance-generator File: SkillBuilderFormatter.java View Source Code | 5 votes |
public SkillBuilderFormatter(final String[] args) { if (args != null) { int index = ArrayUtils.indexOf(args, "-in"); if (index < args.length - 1) { final String invocationName = args[index + 1]; Validate.notBlank(invocationName, "Please provide an invocation name."); Validate.isTrue(!invocationName.startsWith("-"), "Please provide a valid invocation name."); this.model = new SkillBuilderModel(invocationName); } } }
Example 16
Project: pnc-repressurized File: SyncedField.java View Source Code | 4 votes |
@Override protected Byte retrieveValue(Field field, Object te) throws Exception { Object[] enumTypes = field.getType().getEnumConstants(); return (byte) ArrayUtils.indexOf(enumTypes, field.get(te)); }
Example 17
Project: ForgeHax File: CompassMod.java View Source Code | 4 votes |
private double getPosOnCompass(String s) { double yaw = Math.toRadians(MathHelper.wrapDegrees(Helper.getLocalPlayer().rotationYaw - 90)); // player yaw int index = ArrayUtils.indexOf(DIRECTIONS, s)+1; // directions index in the list return yaw + index * HALF_PI; }
Example 18
Project: Minecord File: Config.java View Source Code | 4 votes |
public static void read(File file) { //Look for client token String[] args = Bot.args; if (args.length > 1 && ArrayUtils.contains(args, "-t")) { int index = ArrayUtils.indexOf(args, "-t"); if (index + 1 < args.length) { args = ArrayUtils.remove(args, index); String token = args[index]; if (token.matches("{32,}")) { System.out.println("Found custom client token: " + token); clientToken = token; args = ArrayUtils.remove(args, index); } Bot.args = args; } } try { //Parse config JSON JSONObject config = new JSONObject(FileUtils.readFileToString(file, "UTF-8")); if (clientToken == null) { clientToken = config.getString("clientToken"); } shardCount = config.getInt("shardCount"); if (shardCount < 1) shardCount = 1; owner = config.getString("owner"); devMode = config.getBoolean("devMode"); debugMode = config.getBoolean("debugMode"); logJDA = config.getBoolean("logJDA"); logChannel = config.getString("logChannel"); sendServerCount = config.getBoolean("sendServerCount"); pwToken = config.getString("pwToken"); netToken = config.getString("netToken"); orgToken = config.getString("orgToken"); game = config.getString("game"); name = config.getString("name"); prefix = config.getString("prefix"); respondToMentions = config.getBoolean("respondToMentions"); notificationTime = config.getInt("notificationTime"); deleteCommands = config.getBoolean("deleteCommands"); sendTyping = config.getBoolean("sendTyping"); invite = config.getString("invite"); showMemory = config.getBoolean("showMemory"); elevatedSkipCooldown = config.getBoolean("elevatedSkipCooldown"); JSONArray eu = config.getJSONArray("elevatedUsers"); for (int i = 0; i < eu.length(); i++) { elevatedUsers.add(eu.getString(i)); } } catch (JSONException | IOException e) { e.printStackTrace(); } }
Example 19
Project: filter-sort-jooq-api File: KeyParsers.java View Source Code | 4 votes |
private static void checkDuplicateKeys(final String... keys) { for (int i = 0; i < keys.length - 1; i++) { if (ArrayUtils.indexOf(keys, keys[i], i + 1) != -1) throw new IllegalArgumentException("List of keys has duplicate values"); } }
Example 20
Project: froog File: ConfusionMatrix.java View Source Code | 2 votes |
/** * * Esta función indica el índice de la clase, es decir:<br> * si a = [0,0,0,1], devuelve index = 3<br> * si no es encontrado devuelve -1<br> * * @param a * @return */ private int getIndex(SimpleMatrix a) { return ArrayUtils.indexOf(a.getMatrix().getData(), 1); }