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

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

Introduction

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

Prototype

public static boolean contains(boolean[] array, boolean valueToFind) 

Source Link

Document

Checks if the value is in the given array.

Usage

From source file:de.alpharogroup.random.RandomExtensionsTest.java

/**
 * Test method for {@link RandomExtensions#getRandomEnum(String)} .
 *//*from www .ja  v a2 s .  c om*/
@Test
public void testGetRandomEnumString() {
    final String enumClassName = "de.alpharogroup.test.objects.Gender";
    final Gender randomEnumEntry = RandomExtensions.getRandomEnum(enumClassName);

    final Gender[] genders = Gender.values();
    AssertJUnit.assertTrue("Enum value should contain the random value.",
            ArrayUtils.contains(genders, randomEnumEntry));
}

From source file:com.adobe.cq.wcm.core.components.models.impl.v1.SocialMediaHelperImpl.java

@PostConstruct
private void initModel() throws Exception {
    ValueMap pageProperties = currentPage.getProperties();
    String[] socialMedia = pageProperties.get(PN_SOCIAL_MEDIA, String[].class);
    facebookEnabled = ArrayUtils.contains(socialMedia, PV_FACEBOOK);
    pinterestEnabled = ArrayUtils.contains(socialMedia, PV_PINTEREST);
    socialMediaEnabled = facebookEnabled || pinterestEnabled;
    variantPath = pageProperties.get(PN_VARIANT_PATH, String.class);
}

From source file:com.qccr.livtrip.web.template.BaseDirective.java

/**
 * ??//from   ww w  .j a v a2  s . co m
 * 
 * @param params
 *            ?
 * @param ignoreProperties
 *            
 * @return ?
 */
protected List<Order> getOrders(Map<String, TemplateModel> params, String... ignoreProperties)
        throws TemplateModelException {
    String orderBy = StringUtils
            .trim(FreeMarkerUtils.getParameter(ORDER_BY_PARAMETER_NAME, String.class, params));
    List<Order> orders = new ArrayList<Order>();
    if (StringUtils.isNotEmpty(orderBy)) {
        String[] orderByItems = orderBy.split(ORDER_BY_ITEM_SEPARATOR);
        for (String orderByItem : orderByItems) {
            if (StringUtils.isNotEmpty(orderByItem)) {
                String property = null;
                Order.Direction direction = null;
                String[] orderBys = orderByItem.split(ORDER_BY_FIELD_SEPARATOR);
                if (orderBys.length == 1) {
                    property = orderBys[0];
                } else if (orderBys.length >= 2) {
                    property = orderBys[0];
                    try {
                        direction = Order.Direction.valueOf(orderBys[1]);
                    } catch (IllegalArgumentException e) {
                        continue;
                    }
                } else {
                    continue;
                }
                if (!ArrayUtils.contains(ignoreProperties, property)) {
                    orders.add(new Order(property, direction));
                }
            }
        }
    }
    return orders;
}

From source file:com.adobe.people.jedelson.cq.urlfilter.impl.UrlFilter.java

boolean check(String value, String allowedArrayPropertyName, String allowedPatternPropertyName,
        ValueMap properties) {// www.ja  va 2 s  .  com
    if (value == null) {
        // no value is always allowed
        return true;
    }
    String[] allowedValues = properties.get(allowedArrayPropertyName, String[].class);
    if (allowedValues != null) {
        if (allowedValues.length == 0) {
            logger.debug("{} was empty, therefore not allowing any value.", allowedArrayPropertyName);
            return false;
        } else if (!ArrayUtils.contains(allowedValues, value)) {
            logger.debug("{} did not contain our string {}. checking the pattern.", allowedArrayPropertyName,
                    value);
            String allowedPattern = properties.get(allowedPatternPropertyName, String.class);
            if (allowedPattern == null || !Pattern.matches(allowedPattern, value)) {
                logger.debug("allowedPattern ({}) did not match our string {}", allowedPattern, value);
                return false;
            } else {
                logger.debug("allowedPattern ({}) did match our string {}", allowedPattern, value);
                return true;
            }
        } else {
            return true;
        }
    } else {
        String allowedPattern = properties.get(allowedPatternPropertyName, String.class);
        if (allowedPattern != null && !Pattern.matches(allowedPattern, value)) {
            logger.debug("allowedPattern ({}) did not match our string {}", allowedPattern, value);
            return false;
        } else {
            return true;
        }
    }
}

From source file:com.haulmont.cuba.core.app.serialization.EntitySerialization.java

protected Gson createGsonForSerialization(@Nullable View view, EntitySerializationOption... options) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    if (ArrayUtils.contains(options, EntitySerializationOption.PRETTY_PRINT)) {
        gsonBuilder.setPrettyPrinting();
    }/*from w  ww . ja va 2  s .  co  m*/
    gsonBuilder.registerTypeHierarchyAdapter(Entity.class, new EntitySerializer(view, options))
            .registerTypeHierarchyAdapter(Date.class, new DateSerializer()).create();
    if (ArrayUtils.contains(options, EntitySerializationOption.SERIALIZE_NULLS)) {
        gsonBuilder.serializeNulls();
    }
    return gsonBuilder.create();
}

From source file:com.googlesource.gerrit.plugins.its.jira.restapi.JiraRestApi.java

/**
 * Checks if the connection returned one of the provides pass or fail Codes. If not, an
 * IOException exception is thrown. If it was part of the list, then the actual response code is
 * returned. returns true if valid response is returned, otherwise false
 *///from  ww  w. ja v a 2  s .c o m
private boolean validateResponse(HttpURLConnection conn, int passCode, int[] failCodes) throws IOException {
    responseCode = conn.getResponseCode();
    if (responseCode == passCode) {
        return true;
    }
    if ((failCodes == null) || (!ArrayUtils.contains(failCodes, responseCode))) {
        throw new IOException("Request failed: " + conn.getURL() + " - " + conn.getResponseCode() + " - "
                + conn.getResponseMessage());
    }
    return false;
}

From source file:gov.nih.nci.cabig.caaers.web.fields.AbstractInputField.java

public boolean isRequired() {
    return ArrayUtils.contains(validators, FieldValidator.NOT_NULL_VALIDATOR);
}

From source file:com.codebutler.farebot.activities.AddKeyActivity.java

@Override
protected void onNewIntent(Intent intent) {
    Tag tag = (Tag) intent.getParcelableExtra("android.nfc.extra.TAG");
    mTagId = Utils.getHexString(tag.getId(), "");

    if (ArrayUtils.contains(tag.getTechList(), "android.nfc.tech.MifareClassic")) {
        mCardType = "MifareClassic";
        ((TextView) findViewById(R.id.card_type)).setText("MIFARE Classic");
        ((TextView) findViewById(R.id.card_id)).setText(mTagId);
        ((TextView) findViewById(R.id.key_data)).setText(Utils.getHexString(mKeyData, "").toUpperCase());

        findViewById(R.id.directions).setVisibility(View.GONE);
        findViewById(R.id.info).setVisibility(View.VISIBLE);
        findViewById(R.id.add).setVisibility(View.VISIBLE);

    } else {//from  ww  w . j av a 2  s  .  c o m
        new AlertDialog.Builder(this).setMessage(R.string.card_keys_not_supported)
                .setPositiveButton(android.R.string.ok, null).show();
    }
}

From source file:com.digitalpebble.storm.crawler.indexing.AbstractIndexerBolt.java

/**
 * Determine whether a document should be indexed based on the presence of a
 * given key/value or the RobotsTags.ROBOTS_NO_INDEX directive.
 * // ww  w  .j ava2s.c  o m
 * @return true if the document should be kept.
 **/
protected boolean filterDocument(Metadata meta) {
    String noindexVal = meta.getFirstValue(RobotsTags.ROBOTS_NO_INDEX);
    if ("true".equalsIgnoreCase(noindexVal))
        return false;

    if (filterKeyValue == null)
        return true;
    String[] values = meta.getValues(filterKeyValue[0]);
    // key not found
    if (values == null)
        return false;
    return ArrayUtils.contains(values, filterKeyValue[1]);
}

From source file:de.unisb.cs.st.javalanche.mutation.util.AddMutations.java

private static int[] getReplaceOperators(int operator) {
    if (ArrayUtils.contains(integerOpcodes, operator)) {
        return integerOpcodes;
    }/*  w  w w.jav a  2 s.c o  m*/
    if (ArrayUtils.contains(longOpcodes, operator)) {
        return longOpcodes;
    }
    if (ArrayUtils.contains(longShiftOpcodes, operator)) {
        return longShiftOpcodes;
    }

    if (ArrayUtils.contains(floatOpcodes, operator)) {
        return floatOpcodes;
    }
    if (ArrayUtils.contains(doubleOpcodes, operator)) {
        return doubleOpcodes;
    }
    return new int[0];
}