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:ch.systemsx.cisd.openbis.generic.shared.util.WebClientFilesUpdater.java

private final static void checkTechnologies(final String[] allTechnologies, final String[] technologies) {
    for (final String technology : technologies) {
        if (ArrayUtils.indexOf(allTechnologies, technology) < 0) {
            throw new IllegalArgumentException(String.format("Technology '%s' must be one of '%s'.", technology,
                    Arrays.toString(allTechnologies)));
        }//from   w  w  w .  j  ava  2 s.  c om
    }
}

From source file:com.bstek.dorado.view.registry.AssembledComponentTypeRegister.java

@Override
protected ComponentTypeRegisterInfo getRegisterInfo() throws Exception {
    AssembledComponentTypeRegisterInfo registerInfo = (AssembledComponentTypeRegisterInfo) super.getRegisterInfo();

    Class<? extends Component> cl = registerInfo.getClassType();
    if (cl != null && !AssembledComponent.class.isAssignableFrom(cl)) {
        throw new IllegalArgumentException(cl + " should implements " + AssembledComponent.class + ".");
    }/*from www  .j a  v a 2s  .  co m*/

    registerInfo.setSrc(src);

    String category = null;
    Widget widget = null;
    if (cl != null) {
        widget = cl.getAnnotation(Widget.class);
        if (widget != null && ArrayUtils.indexOf(cl.getDeclaredAnnotations(), widget) >= 0) {
            category = widget.category();
        }
    }
    registerInfo.setCategory((StringUtils.isEmpty(category)) ? "Others" : category);

    Map<String, VirtualPropertyDescriptor> propertieDescriptors = new HashMap<String, VirtualPropertyDescriptor>();
    if (virtualProperties != null) {
        for (Map.Entry<String, Properties> entry : virtualProperties.entrySet()) {
            String propertyName = entry.getKey();
            Properties properties = entry.getValue();
            VirtualPropertyDescriptor propertyDescriptor = new VirtualPropertyDescriptor();
            propertyDescriptor.setName(propertyName);

            String type = properties.getProperty("type");
            if (StringUtils.isNotEmpty(type)) {
                propertyDescriptor.setType(ClassUtils.forName(type));
            }

            String avialableAt = properties.getProperty("avialableAt");
            if (StringUtils.isNotEmpty(avialableAt)) {
                propertyDescriptor.setAvialableAt(VirtualPropertyAvialableAt.valueOf(avialableAt));
            }

            propertyDescriptor.setDefaultValue(properties.getProperty("defaultValue"));
            propertyDescriptor.setReferenceComponentType(properties.getProperty("referenceComponentType"));
            propertieDescriptors.put(propertyName, propertyDescriptor);
        }
    }
    registerInfo.setVirtualProperties(propertieDescriptors);

    Map<String, VirtualEventDescriptor> eventDescriptors = new HashMap<String, VirtualEventDescriptor>();
    if (virtualEvents != null) {
        for (Map.Entry<String, Properties> entry : virtualEvents.entrySet()) {
            String eventName = entry.getKey();
            VirtualEventDescriptor eventDescriptor = new VirtualEventDescriptor();
            eventDescriptor.setName(eventName);
            eventDescriptors.put(eventName, eventDescriptor);
        }
    }
    registerInfo.setVirtualEvents(eventDescriptors);
    return registerInfo;
}

From source file:com.syncnapsis.security.accesscontrol.BaseAccessRule.java

/**
 * Check whether a given entity is owned by the given authorities.
 * /*www .j av a2 s .c  o  m*/
 * @param entity - the entity to check the owner for
 * @param authorities - the authorities to check against
 * @return true or false
 */
public boolean isOwner(Object entity, Object... authorities) {
    if (entity instanceof Ownable<?>) {
        List<?> owners = ((Ownable<?>) entity).getOwners();
        if (owners != null && authorities != null) {
            for (Object owner : owners) {
                if (ArrayUtils.indexOf(authorities, owner) != -1)
                    return true;
                if (isOwner(owner, authorities))
                    return true;
            }
        }
    }
    return false;
}

From source file:net.bible.android.view.activity.settings.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // change theme according to light sensor
    UiUtils.applyTheme(this);

    super.onCreate(savedInstanceState);

    // allow partial integration with And Bible framework - without this TTS stops
    // putting this before the below ensures any error dialog will be displayed in front of the settings screen and not the previous screen
    // see onStop for paired iAmNoLongerCurrent method call
    CurrentActivityHolder.getInstance().setCurrentActivity(this);

    try {//from  www.  ja v a  2 s . c  o  m
        addPreferencesFromResource(R.xml.settings);

        //If no light sensor exists switch to old boolean check box
        // see here for method: http://stackoverflow.com/questions/4081533/how-to-remove-android-preferences-from-the-screen
        Preference unusedNightModePreference = getPreferenceScreen()
                .findPreference(ScreenSettings.getUnusedNightModePreferenceKey());
        getPreferenceScreen().removePreference(unusedNightModePreference);

        // if no tilt sensor then remove tilt-to-scroll setting
        if (!PageTiltScrollControl.isTiltSensingPossible()) {
            Preference tiltToScrollPreference = getPreferenceScreen()
                    .findPreference(PageTiltScrollControl.TILT_TO_SCROLL_PREFERENCE_KEY);
            getPreferenceScreen().removePreference(tiltToScrollPreference);
        }

        // only JellyBean supports Malayalam so remove ml for older versions of Android
        if (!CommonUtils.isJellyBeanPlus()) {
            ListPreference localePref = (ListPreference) getPreferenceScreen().findPreference(LOCALE_PREF);
            CharSequence[] entries = localePref.getEntries();
            CharSequence[] entryValues = localePref.getEntryValues();
            int mlIndex = ArrayUtils.indexOf(entryValues, "ml");
            if (mlIndex != -1) {
                Log.d(TAG, "removing Malayalam from preference list");
                localePref.setEntries(ArrayUtils.remove(entries, mlIndex));
                localePref.setEntryValues(ArrayUtils.remove(entryValues, mlIndex));
            }
        }

        addScreenTimeoutSettings();

    } catch (Exception e) {
        Log.e(TAG, "Error preparing preference screen", e);
        Dialogs.getInstance().showErrorMsg(R.string.error_occurred);
    }
}

From source file:com.opengamma.analytics.math.curve.DoublesCurveInterpolatedAnchor.java

/**
 * Constructor./*from   w w  w .jav a 2 s  .  c  o  m*/
 * @param xData The x data without the anchor.
 * @param yData The y data.
 * @param anchor The anchor point. Should not be in xData.
 * @param anchorValue The anchor point value.
 * @param interpolator The interpolator.
 * @param name The curve name.
 * @return The curve.
 */
public static DoublesCurveInterpolatedAnchor from(double[] xData, double[] yData, double anchor,
        double anchorValue, Interpolator1D interpolator, String name) {
    ArgumentChecker.notNull(xData, "X data");
    int xLength = xData.length;
    ArgumentChecker.notNull(yData, "Y data");
    ArgumentChecker.isTrue(xLength == yData.length, "Data of incorrect length.");
    double[] xExtended = new double[xLength + 1];
    double[] yExtended = new double[xLength + 1];
    System.arraycopy(xData, 0, xExtended, 0, xLength);
    xExtended[xLength] = anchor;
    System.arraycopy(yData, 0, yExtended, 0, xLength);
    yExtended[xLength] = anchorValue;
    ParallelArrayBinarySort.parallelBinarySort(xExtended, yExtended);
    int anchorIndex = ArrayUtils.indexOf(xExtended, anchor);
    return new DoublesCurveInterpolatedAnchor(xExtended, yExtended, anchorIndex, interpolator, name);
}

From source file:net.mumie.coursecreator.graph.cells.MainComponentConstants.java

/**
 * returns if a category belongs to a Problem
 * @param cat/*from  w  w  w  .  ja va2  s  .  c o m*/
 * @return true category is a problemCategory
 * false category is no problemCategory
 */
public static boolean isProblemCategory(int cat) {
    return (cat == ArrayUtils.indexOf(categories, CAT_APPLET)
            || cat == ArrayUtils.indexOf(categories, CAT_MCHOICE));
}

From source file:com.agimatec.validation.model.MetaBean.java

public void putProperty(String name, MetaProperty property) {
    final MetaProperty oldProperty = getProperty(name);
    if (oldProperty == null) { // add
        if (properties.length == 0) {
            properties = new MetaProperty[1];
        } else {/*from  w w w .  j a  v  a 2 s  . co  m*/
            MetaProperty[] newproperties = new MetaProperty[properties.length + 1];
            System.arraycopy(properties, 0, newproperties, 0, properties.length);
            properties = newproperties;
        }
        properties[properties.length - 1] = property;
    } else { // replace
        int idx = ArrayUtils.indexOf(properties, oldProperty);
        properties[idx] = property;
    }
}

From source file:gov.nih.nci.cabig.caaers.accesscontrol.filter.query.QuerySecurityFilterer.java

/**
 * Will take care of applying the filter.
 * Obtain the base query, then replace the base entity and its alias with "index name" and "index alias"
 * then issue couple of joins with the entity.
 * //  w w  w  . j  av  a 2 s  .  c o m
 * @param query
 */
public void applyFilter(AbstractQuery query) {
    /*
    Note :-
    "select p from Participant p, ParticipantIndex i where p = i.participant" takes longer time
    compared to "select p from ParticipantIndex i join i.participant p".
    */

    String hql = query.getBaseQueryString();
    String[] hqlElements = StringUtils.split(hql);

    int etIndex = ArrayUtils.indexOf(hqlElements, entityName);
    if (etIndex <= 0 && hqlElements.length <= etIndex) {
        log.warn("Query [" + query.getClass().getName() + "] is incorrectly framed [" + hql + "]");
        throw new IllegalArgumentException("The query supplied for index filtering " + "["
                + query.getClass().getName() + "], do not follow the conventions");
    }

    String entityAlias = hqlElements[etIndex + 1];

    //replace the base query after replacing the entity and its alias with equivalent indexName and indexAlias
    hqlElements[etIndex] = indexName;
    hqlElements[etIndex + 1] = indexAlias;

    String newQuery = StringUtils.join(hqlElements, " ");
    query.modifyQueryString(newQuery);

    //issue joins with index and extra conditions.

    // the index alias join should be joined at the beginning
    query.joinAtTheBeginningOfList(getIndexAlias() + "." + getEntityAssociation() + " " + entityAlias);
    query.andWhere(getIndexAlias() + ".loginId = :loginId");
    query.andWhere("bitand(" + getIndexAlias() + ".role, " + getRole() + ") > 0");
    query.setParameter("loginId", getLoginId());
    query.setFiltered(true);
}

From source file:net.mumie.coursecreator.graph.cells.MainComponentConstants.java

/**
 * //ww w.  ja va2  s.c  om
 * @param cat
 * @return
 */
public static boolean isSectionCategory(int cat) {
    return (cat == ArrayUtils.indexOf(categories, CAT_SECTION));
}

From source file:com.jaspersoft.studio.book.widgets.SPEvaluationReadCombo.java

public void setData(APropertyNode pnode, Object b) {
    setRefreshing(true);//from  w w w .  java 2s.c om
    updateItems(pnode);
    if (b == null) {
        combo.select(0); //select the default item //combo.getItems().length-1
    } else if (b instanceof PartEvaluationTimeType) {
        PartEvaluationTimeType evaluation = (PartEvaluationTimeType) b;
        if (evaluation.equals(PartEvaluationTimeType.GROUP)) {
            String evaluationGroup = (String) pnode.getPropertyValue(MReportPart.PROPERTY_EVALTIME_GROUP);
            int index = ArrayUtils.indexOf(combo.getItems(), evaluationGroup);
            combo.select(index);
        } else {
            int index = ArrayUtils.indexOf(combo.getItems(), evaluation.getName());
            combo.select(index);
        }
    } else {
        setRefreshing(false);
        super.setData(pnode, b);
    }
    setRefreshing(false);
}