List of usage examples for org.apache.commons.lang ArrayUtils indexOf
public static int indexOf(boolean[] array, boolean valueToFind)
Finds the index of the given value in the array.
From source file:org.ebayopensource.turmeric.eclipse.utils.io.PropertiesFileUtil.java
@SuppressWarnings("unchecked") private static void accessProperty(InputStream input, OutputStream output, String[] keys, PropertyOperation operation, boolean autoclose) throws IOException { List<String> lines = new ArrayList<String>(); List<String> result = new ArrayList<String>(); try {/* w w w .ja va2 s . c o m*/ lines = IOUtils.readLines(input); } finally { if (autoclose) { IOUtils.closeQuietly(input); } } try { for (String line : lines) { int offset = line.indexOf("="); if (line.trim().length() > 0 && offset > -1) { String originalKey = line.substring(0, offset).trim(); String originalValue = line.substring(++offset); int index = ArrayUtils.indexOf(keys, originalKey); if (index > -1) { String outputLine = operation.process(line, originalKey, originalValue); if (outputLine != null) { result.add(outputLine); } } else { result.add(line); } } else { result.add(line); } } if (output != null) { IOUtils.writeLines(result, null, output); } } finally { if (autoclose) { IOUtils.closeQuietly(output); } } }
From source file:org.eclipse.jubula.client.core.propertytester.AbstractBooleanPropertyTester.java
/** {@inheritDoc} */ public final boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (receiver != null) { if (getType().isAssignableFrom(receiver.getClass())) { if (ArrayUtils.indexOf(getProperties(), property) >= 0) { boolean expectedBoolean = expectedValue instanceof Boolean ? ((Boolean) expectedValue).booleanValue() : true;/*from www . j a v a 2 s .c o m*/ return testImpl(receiver, property, args) == expectedBoolean; } LOG.warn(NLS.bind(Messages.PropertyTesterPropertyNotSupported, property)); return false; } } String receiverClass = receiver != null ? receiver.getClass().getName() : "null"; //$NON-NLS-1$ LOG.warn(NLS.bind(Messages.PropertyTesterTypeNotSupported, receiverClass)); return false; }
From source file:org.eclipse.jubula.client.ui.rcp.constants.InputCodeHelper.java
/** * gives you the index of a modifier code * @param modifier/* w w w .ja v a 2 s . co m*/ * int * @return * int */ public int getIndexOfModifier(int modifier) { return ArrayUtils.indexOf(m_modifier, modifier); }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.parser.DisplayOptionsParser.java
/** * Returns the first found parameter index of the options. */// ww w .ja v a2 s . c om private int getIntParameter(String[] options, int currentValue, String parameter, String parameterName, String deviceAddress) { int idx = ArrayUtils.indexOf(options, parameter); if (idx != -1) { if (currentValue == 0) { logger.debug("{} option '{}' found at index {} for remote control '{}'", parameterName, parameter, idx + 1, deviceAddress); return idx + 1; } else { logger.warn("{} option already set for remote control '{}', ignoring '{}'!", parameterName, deviceAddress, parameter); return currentValue; } } else { return currentValue; } }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.parser.DisplayOptionsParser.java
/** * Returns all possible options from the given datapoint. *///from w ww . ja v a 2s . c o m private String[] getAvailableOptions(HmChannel channel, String datapointName) { HmDatapointInfo dpInfo = HmDatapointInfo.createValuesInfo(channel, datapointName); HmDatapoint dp = channel.getDatapoint(dpInfo); if (dp != null) { String[] options = (String[]) ArrayUtils.remove(dp.getOptions(), 0); for (String onOffString : onOff) { int onIdx = ArrayUtils.indexOf(options, onOffString); if (onIdx != -1) { options[onIdx] = datapointName + "_" + onOffString; } } return options; } return new String[0]; }
From source file:org.eclipse.wb.internal.core.databinding.ui.editor.contentproviders.ChooseClassUiContentProvider.java
/** * This method calculate state and sets or clear error message. Subclasses maybe override this * method for observe special states./*w w w . ja va2 s .c o m*/ */ protected void calculateFinish() { String className = getClassName(); // route events if (m_router != null) { m_router.handle(); } // check state if (className.length() == 0) { // empty class setErrorMessage(m_configuration.getEmptyClassErrorMessage()); } else { // check clear of default value (maybe not class) if (m_configuration.isDefaultString(className) || className.equals(m_configuration.getClearValue()) || ArrayUtils.indexOf(m_configuration.getDefaultValues(), className) != -1) { setErrorMessage(null); return; } // check load class Class<?>[][] constructorsParameters = m_configuration.getConstructorsParameters(); String errorMessagePrefix = m_configuration.getErrorMessagePrefix(); // boolean noConstructor = false; try { Class<?> testClass = loadClass(className); // check permissions int modifiers = testClass.getModifiers(); if (!Modifier.isPublic(modifiers)) { setErrorMessage(errorMessagePrefix + Messages.ChooseClassUiContentProvider_validateNotPublic); return; } if (!m_configuration.isChooseInterfaces() && Modifier.isAbstract(modifiers)) { setErrorMessage(errorMessagePrefix + Messages.ChooseClassUiContentProvider_validateAbstract); return; } // check constructor if (m_checkClasses) { m_checkClasses = false; if (constructorsParameters != null) { for (int i = 0; i < constructorsParameters.length; i++) { Class<?>[] constructorParameters = constructorsParameters[i]; for (int j = 0; j < constructorParameters.length; j++) { Class<?> constructorParameterClass = constructorParameters[j]; if (constructorParameterClass.isArray()) { String parameterClassName = constructorParameterClass.getComponentType() .getName(); if (parameterClassName.startsWith("org.eclipse")) { constructorParameters[j] = Array .newInstance(loadClass(parameterClassName), new int[1]).getClass(); } } else { String parameterClassName = constructorParameterClass.getName(); if (parameterClassName.startsWith("org.eclipse")) { constructorParameters[j] = loadClass(parameterClassName); } } } } } } if (constructorsParameters != null) { noConstructor = true; for (int i = 0; i < constructorsParameters.length; i++) { try { testClass.getConstructor(constructorsParameters[i]); noConstructor = false; break; } catch (SecurityException e) { } catch (NoSuchMethodException e) { } } } } catch (ClassNotFoundException e) { setErrorMessage(errorMessagePrefix + Messages.ChooseClassUiContentProvider_validateNotExist); return; } // prepare error message for constructor if (noConstructor) { StringBuffer parameters = new StringBuffer(errorMessagePrefix); parameters.append(Messages.ChooseClassUiContentProvider_validatePublicConstructor); for (int i = 0; i < constructorsParameters.length; i++) { Class<?>[] constructorParameters = constructorsParameters[i]; if (i > 0) { parameters.append(" "); } parameters.append(ClassUtils.getShortClassName(className)); parameters.append("("); for (int j = 0; j < constructorParameters.length; j++) { if (j > 0) { parameters.append(", "); } parameters.append(ClassUtils.getShortClassName(constructorParameters[j])); } parameters.append(")"); } parameters.append("."); setErrorMessage(parameters.toString()); } else { setErrorMessage(null); } } }
From source file:org.eclipse.wb.internal.core.databinding.ui.editor.contentproviders.ChooseClassUiContentProvider.java
/** * Sets current chosen class name./*from ww w.j av a 2s .co m*/ */ public final void setClassName(String className) { // prepare class name className = m_configuration.getRetargetClassName(className); // check clear or default value (don't add to classes scope) if (m_configuration.isDefaultString(className)) { int index = m_dialogField.getListItems().indexOf(className); if (index == -1) { m_dialogField.setDialogFieldListener(null); m_dialogField.addItem(className); m_dialogField.setDialogFieldListener(m_fieldChangeListener); m_dialogField.selectItem(className); } else { m_dialogField.selectItem(index); } return; } if (className.equals(m_configuration.getClearValue()) || ArrayUtils.indexOf(m_configuration.getDefaultValues(), className) != -1) { m_dialogField.selectItem(className); return; } // select or add class name to combo and classes scope int index = m_dialogField.getListItems().indexOf(className); if (index == -1) { m_classes.add(className); m_dialogField.setDialogFieldListener(null); m_dialogField.addItem(className); m_dialogField.setDialogFieldListener(m_fieldChangeListener); m_dialogField.selectItem(className); } else { m_dialogField.selectItem(index); } }
From source file:org.eclipse.wb.internal.core.databinding.ui.EditSelection.java
/** * @return the path for given object in elements tree. *///from ww w . jav a2 s . co m private static int[] objectToPath(ITreeContentProvider provider, Object[] input, Object object) { if (object == null) { return ArrayUtils.EMPTY_INT_ARRAY; } ArrayIntList pathList = new ArrayIntList(); while (true) { Object parent = provider.getParent(object); if (parent == null) { pathList.add(ArrayUtils.indexOf(input, object)); break; } pathList.add(ArrayUtils.indexOf(provider.getChildren(parent), object)); object = parent; } int[] path = pathList.toArray(); ArrayUtils.reverse(path); return path; }
From source file:org.eclipse.wb.internal.core.databinding.wizards.autobindings.AutomaticDatabindingFirstPage.java
@Override protected void createLocalControls(Composite parent, int columns) { // prepare super classes final String[] superClasses = m_databindingProvider.getSuperClasses(); int current = ArrayUtils.indexOf(superClasses, m_databindingProvider.getInitialSuperClass()); // create dialog field final SelectionButtonDialogFieldGroup fieldsGroup = new SelectionButtonDialogFieldGroup(SWT.RADIO, superClasses, 1);//from w ww . j a v a 2 s .c o m fieldsGroup.setLabelText(Messages.AutomaticDatabindingFirstPage_superClassLabel); fieldsGroup.setSelection(current, true); fieldsGroup.doFillIntoGrid(parent, columns); // handle change super class fieldsGroup.setDialogFieldListener(new IDialogFieldListener() { public void dialogFieldChanged(DialogField field) { int[] selection = fieldsGroup.getSelection(); if (selection.length == 1) { String superClass = superClasses[selection[0]]; // handle initial wizard selection if (m_initialBeanClassName != null) { if (getTypeName().equals(getInitialTypeNameWithSuperClass())) { setTypeName(m_initialBeanClassName + ClassUtils.getShortClassName(superClass), true); } } // setSuperClass(superClass, false); } } }); }
From source file:org.eclipse.wb.internal.core.editor.ObjectPathHelper.java
/** * @return the path for given object in components tree. *///from w w w . j ava 2 s . c o m private int[] getObjectPath(Object object) { ArrayIntList path = new ArrayIntList(); while (true) { Object parent = m_componentsProvider.getParent(object); if (parent == null) { break; } // add index int index = ArrayUtils.indexOf(m_componentsProvider.getChildren(parent), object); path.add(index); // go to parent object = parent; } // convert to array int[] finalPath = path.toArray(); ArrayUtils.reverse(finalPath); return finalPath; }