Example usage for org.apache.commons.lang ArrayUtils indexOf

List of usage examples for org.apache.commons.lang ArrayUtils indexOf

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils indexOf.

Prototype

public static int indexOf(boolean[] array, boolean valueToFind) 

Source Link

Document

Finds the index of the given value in the array.

Usage

From source file:org.kiji.schema.layout.impl.hbase.IdentityColumnNameTranslator.java

/** {@inheritDoc}*/
@Override/*from   w w  w .j  av a2s.  c o  m*/
public KijiColumnName toKijiColumnName(HBaseColumnName hbaseColumnName) throws NoSuchColumnException {
    LOG.debug("Translating HBase column name {} to Kiji column name.", hbaseColumnName);

    final String localityGroupName = Bytes.toString(hbaseColumnName.getFamily());

    final LocalityGroupLayout localityGroup = mLayout.getLocalityGroupMap().get(localityGroupName);
    if (localityGroup == null) {
        throw new NoSuchColumnException(
                String.format("No locality group %s in table %s.", localityGroupName, mLayout.getName()));
    }

    // Parse the HBase qualifier as a byte[] in order to save a String instantiation
    final byte[] hbaseQualifier = hbaseColumnName.getQualifier();
    final int index = ArrayUtils.indexOf(hbaseQualifier, SEPARATOR);
    if (index == -1) {
        throw new NoSuchColumnException(
                String.format("Missing separator in HBase column %s.", hbaseColumnName));
    }
    final String familyName = Bytes.toString(hbaseQualifier, 0, index);
    final String qualifierName = Bytes.toString(hbaseQualifier, index + 1, hbaseQualifier.length - index - 1);

    final FamilyLayout family = mLayout.getFamilyMap().get(familyName);
    if (family == null) {
        throw new NoSuchColumnException(String.format("No family %s in locality group %s of table %s.",
                familyName, localityGroupName, mLayout.getName()));
    }

    if (family.isGroupType()) {
        // Group type family.
        if (!family.getColumnMap().containsKey(qualifierName)) {
            throw new NoSuchColumnException(String.format("No qualifier %s in family %s of table %s.",
                    qualifierName, familyName, mLayout.getName()));
        }
        final KijiColumnName kijiColumnName = new KijiColumnName(familyName, qualifierName);
        LOG.debug("Translated to Kiji group type column {}.", kijiColumnName);
        return kijiColumnName;
    } else {
        // Map type family.
        assert family.isMapType();
        final KijiColumnName kijiColumnName = new KijiColumnName(familyName, qualifierName);
        LOG.debug("Translated to Kiji map type column '{}'.", kijiColumnName);
        return kijiColumnName;
    }
}

From source file:org.kiji.schema.layout.impl.hbase.ShortColumnNameTranslator.java

/** {@inheritDoc} */
@Override/*from w ww .j  a  v a2 s . co  m*/
public KijiColumnName toKijiColumnName(HBaseColumnName hbaseColumnName) throws NoSuchColumnException {
    LOG.debug("Translating HBase column name '{}' to Kiji column name...", hbaseColumnName);
    final ColumnId localityGroupID = ColumnId.fromByteArray(hbaseColumnName.getFamily());
    final LocalityGroupLayout localityGroup = mLayout.getLocalityGroupMap()
            .get(mLayout.getLocalityGroupIdNameMap().get(localityGroupID));
    if (localityGroup == null) {
        throw new NoSuchColumnException(String.format("No locality group with ID %s in table %s.",
                localityGroupID.getId(), mLayout.getName()));
    }

    // Parse the HBase qualifier as a byte[] in order to save a String instantiation
    final byte[] hbaseQualifier = hbaseColumnName.getQualifier();
    final int index = ArrayUtils.indexOf(hbaseQualifier, SEPARATOR);
    if (index == -1) {
        throw new NoSuchColumnException(
                String.format("Missing separator in HBase column %s.", hbaseColumnName));
    }
    final ColumnId familyID = ColumnId.fromString(Bytes.toString(hbaseQualifier, 0, index));
    final String rawQualifier = Bytes.toString(hbaseQualifier, index + 1, hbaseQualifier.length - index - 1);

    final FamilyLayout family = localityGroup.getFamilyMap()
            .get(localityGroup.getFamilyIdNameMap().get(familyID));
    if (family == null) {
        throw new NoSuchColumnException(String.format("No family with ID %s in locality group %s of table %s.",
                familyID.getId(), localityGroup.getName(), mLayout.getName()));
    }

    if (family.isGroupType()) {
        // Group type family.
        final ColumnId qualifierID = ColumnId.fromString(rawQualifier);
        final ColumnLayout qualifier = family.getColumnMap().get(family.getColumnIdNameMap().get(qualifierID));
        if (qualifier == null) {
            throw new NoSuchColumnException(String.format("No column with ID %s in family %s of table %s.",
                    qualifierID.getId(), family.getName(), mLayout.getName()));
        }
        final KijiColumnName kijiColumnName = new KijiColumnName(family.getName(), qualifier.getName());
        LOG.debug("Translated to Kiji group column {}.", kijiColumnName);
        return kijiColumnName;
    } else {
        // Map type family.
        assert family.isMapType();
        final KijiColumnName kijiColumnName = new KijiColumnName(family.getName(), rawQualifier);
        LOG.debug("Translated to Kiji map column '{}'.", kijiColumnName);
        return kijiColumnName;
    }
}

From source file:org.lexevs.dao.database.prefix.CyclingCharDbPrefixGenerator.java

/**
 * Find next char./*  w w w. j a  v  a  2  s . c o m*/
 * 
 * @param charToFind the char to find
 * 
 * @return the char
 */
protected char findNextChar(char charToFind) {
    int alphabetIndex = ArrayUtils.indexOf(ALPHABET, charToFind);
    return ALPHABET[alphabetIndex + 1];
}

From source file:org.olat.course.condition.AttributeEasyRowAdderController.java

/**
 * Internal method to add a new row at the given position
 * /* ww w  . j av a 2s  .co m*/
 * @param i
 */
private void addRowAt(final int rowPos) {
    // 1) Make room for the new row if the row is inserted between existing
    // rows. Increment the row id in the user object of the form elements and
    // move them in the form element arrays
    final Map formComponents = flc.getFormComponents();
    for (int move = rowPos + 1; move <= columnAttribute.size(); move++) {
        FormItem oldPos = (FormItem) formComponents.get(columnAttribute.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = (FormItem) formComponents.get(columnOperator.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = (FormItem) formComponents.get(columnValueText.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = (FormItem) formComponents.get(columnValueSelection.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = (FormItem) formComponents.get(columnAddRow.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = (FormItem) formComponents.get(columnRemoveRow.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
    }
    // 2) create the new row

    // get gui translated shib attributes - fallback is to use the key also as value
    final String[] guiTranslatedAttKeys = new String[attrKeys.length];
    for (int j = 0; j < attrKeys.length; j++) {
        final String key = attrKeys[j];
        // OLAT-5089: use translate(String key, String[] args, boolean fallBackToDefaultLocale) version
        // of Translator because that's the only one not
        String translated = getTranslator().translate(key, null, Level.OFF);
        if (translated.indexOf(Translator.NO_TRANSLATION_ERROR_PREFIX) == 0) {
            final Translator translator = UserManager.getInstance()
                    .getPropertyHandlerTranslator(getTranslator());
            final String prefix = "form.name.";
            // OLAT-5089: use translate(String key, String[] args, boolean fallBackToDefaultLocale) version
            // of Translator because that's the only one not
            translated = translator.translate(prefix + key, null, Level.OFF);
            if (translated.indexOf(Translator.NO_TRANSLATION_ERROR_PREFIX) == 0) {
                // could not translate this key, use key for non-translated values
                guiTranslatedAttKeys[j] = key;
            } else {
                guiTranslatedAttKeys[j] = translated;
            }
        } else {
            guiTranslatedAttKeys[j] = translated;
        }
    }
    // sort after the values
    ArrayHelper.sort(attrKeys, guiTranslatedAttKeys, false, true, true);
    // use this sorted keys-values
    final SingleSelection attribute = uifactory.addDropdownSingleselect(PRE_ATTRIBUTE + rowCreationCounter,
            null, flc, attrKeys, guiTranslatedAttKeys, null);
    attribute.setUserObject(Integer.valueOf(rowPos));
    attribute.addActionListener(this, FormEvent.ONCHANGE);
    columnAttribute.add(rowPos, attribute.getName());

    // 2b) Operator selector
    final String[] values = OperatorManager.getRegisteredAndAlreadyTranslatedOperatorLabels(getLocale(),
            operatorKeys);
    final FormItem operator = uifactory.addDropdownSingleselect(PRE_OPERATOR + rowCreationCounter, null, flc,
            operatorKeys, values, null);
    operator.setUserObject(Integer.valueOf(rowPos));
    columnOperator.add(rowPos, operator.getName());

    // 2c) Attribute value - can be either a text input field or a selection
    // drop down box - create both and hide the selection box
    //
    final TextElement valuetxt = uifactory.addTextElement(PRE_VALUE_TEXT + rowCreationCounter, null, -1, null,
            flc);
    valuetxt.setDisplaySize(25);
    valuetxt.setNotEmptyCheck("form.easy.error.attribute");
    valuetxt.setUserObject(Integer.valueOf(rowPos));
    columnValueText.add(rowPos, valuetxt.getName());
    // now the selection box
    final FormItem iselect = uifactory.addDropdownSingleselect(PRE_VALUE_SELECTION + rowCreationCounter, null,
            flc, new String[0], new String[0], null);
    iselect.setUserObject(Integer.valueOf(rowPos));
    iselect.setVisible(false);
    columnValueSelection.add(rowPos, iselect.getName());
    // 3) Init values for this row, assume selection of attribute at position 0
    if (ArrayUtils.contains(attrKeys, preselectedAttribute)) {
        attribute.select(preselectedAttribute, true);
        updateValueElementForAttribute(attribute.getKey(ArrayUtils.indexOf(attrKeys, preselectedAttribute)),
                rowPos, preselectedAttributeValue);
    } else {
        updateValueElementForAttribute(attribute.getKey(0), rowPos, null);
    }
    // 4) Add the 'add' and 'remove' buttons
    final FormLinkImpl addL = new FormLinkImpl("add_" + rowCreationCounter, "add." + rowPos, "+",
            Link.BUTTON_SMALL + Link.NONTRANSLATED);
    addL.setUserObject(Integer.valueOf(rowPos));
    flc.add(addL);
    columnAddRow.add(rowPos, addL.getName());
    //
    final FormLinkImpl removeL = new FormLinkImpl("remove_" + rowCreationCounter, "remove." + rowPos, "-",
            Link.BUTTON_SMALL + Link.NONTRANSLATED);
    removeL.setUserObject(Integer.valueOf(rowPos));
    flc.add(removeL);
    columnRemoveRow.add(rowPos, removeL.getName());

    // new row created, increment counter for unique form element id's
    rowCreationCounter++;
}

From source file:org.openengsb.core.test.ServiceList.java

@Override
public int indexOf(Object o) {
    return ArrayUtils.indexOf(tracker.getServices(), o);
}

From source file:org.openhab.binding.homematic.internal.communicator.RemoteControlOptionParser.java

/**
 * Returns the first found parameter index of the valueList.
 *//*from   www .  j  a v  a  2  s .  c  o m*/
private int getIntParameter(String[] valueList, int currentValue, String parameter, String parameterName) {
    int idx = ArrayUtils.indexOf(valueList, parameter);
    if (idx != -1) {
        if (currentValue == 0) {
            logger.debug("{} Parameter {} found at index {} for remote control {}", parameterName, parameter,
                    idx + 1, remoteControlAddress);
            return idx + 1;
        } else {
            logger.warn("{} Parameter already set for remote control {}, ignoring {}!", parameterName,
                    remoteControlAddress, parameter);
            return currentValue;
        }
    } else {
        return currentValue;
    }
}

From source file:org.openhab.binding.homematic.internal.communicator.RemoteControlOptionParser.java

/**
 * Returns all possible value items from the remote control.
 *///from w  ww . j  a va2  s  .  c o  m
private String[] getValueItems(String parameterName) {
    DatapointConfig dpConfig = new DatapointConfig(remoteControlAddress, "18", parameterName);
    HmValueItem hmValueItem = context.getStateHolder().getState(dpConfig);
    if (hmValueItem != null) {
        String[] valueList = (String[]) ArrayUtils.remove(hmValueItem.getValueList(), 0);
        int onIdx = ArrayUtils.indexOf(valueList, "ON");
        if (onIdx != -1) {
            valueList[onIdx] = parameterName + "_ON";
        }
        return valueList;
    }
    return new String[0];
}

From source file:org.openhab.binding.neeo.internal.NeeoRoomProtocol.java

/**
 * Processes a change to the scenario (whether it's been launched or not)
 *
 * @param scenarioKey a non-null, non-empty scenario key
 * @param launch true if the scenario was launched, false otherwise
 *//*w  ww . j  a  va 2s . c o  m*/
private void processScenarioChange(String scenarioKey, boolean launch) {
    NeeoUtil.requireNotEmpty(scenarioKey, "scenarioKey cannot be empty");

    final String[] activeScenarios = this.activeScenarios.get();
    final int idx = ArrayUtils.indexOf(activeScenarios, scenarioKey);

    // already set that way
    if ((idx < 0 && !launch) || (idx >= 0 && launch)) {
        return;
    }

    final String[] newScenarios = idx >= 0 ? (String[]) ArrayUtils.remove(activeScenarios, idx)
            : (String[]) ArrayUtils.add(activeScenarios, scenarioKey);

    this.activeScenarios.set(newScenarios);

    refreshScenarioStatus(scenarioKey);
}

From source file:org.openhab.binding.yamahareceiver.internal.protocol.xml.InputWithPresetControlXML.java

private int convertToPresetNumber(String presetValue) {
    if (StringUtils.isNotEmpty(presetValue)) {
        if (StringUtils.isNumeric(presetValue)) {
            return Integer.parseInt(presetValue);
        } else {/* ww w .java2s  .  co m*/
            // special handling for RX-V3900, where 'A1' becomes 101 and 'B2' becomes 202 preset
            if (presetValue.length() >= 2) {
                Character presetAlpha = presetValue.charAt(0);
                if (Character.isLetter(presetAlpha) && Character.isUpperCase(presetAlpha)) {
                    int presetNumber = Integer.parseInt(presetValue.substring(1));
                    return (ArrayUtils.indexOf(LETTERS, presetAlpha) + 1) * 100 + presetNumber;
                }
            }
        }
    }
    return -1;
}

From source file:org.openlegacy.ide.eclipse.actions.GenerateViewDialog.java

@Override
protected Control createDialogArea(Composite parent) {

    parent = new Composite(parent, SWT.NONE);

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;//from   w w w .  ja va 2 s . co m
    GridData gd = new GridData();
    gd.widthHint = 400;
    parent.setLayoutData(gd);
    parent.setLayout(gridLayout);

    parent.getShell().setText(PluginConstants.TITLE);

    Label label = new Label(parent, SWT.NULL);
    label.setText(Messages.getString("label_project_name"));

    Composite composite = new Composite(parent, SWT.NONE);

    gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    gd = new GridData(GridData.FILL_HORIZONTAL, GridData.FILL_VERTICAL, true, true);
    gd.horizontalSpan = 3;
    composite.setLayoutData(gd);
    composite.setLayout(gridLayout);

    projectName = new Combo(composite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
    String[] projectNames = EclipseUtil.getProjectNames();
    projectName.setItems(projectNames);
    projectName.select(ArrayUtils.indexOf(projectNames, getProject().getName()));

    generateHelpBtn = new Button(composite, SWT.CHECK);
    generateHelpBtn.setText(Messages.getString("label_generate_help"));
    generateHelpBtn.setSelection(true);

    loadPrefrences();

    return parent;
}