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

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

Introduction

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

Prototype

public static short[] add(short[] array, short element) 

Source Link

Document

Copies the given array and adds the given element at the end of the new array.

Usage

From source file:gda.device.detector.EpicsMCACounterTimer.java

/**
 * @param channel/*from w w w.jav  a2  s.c  om*/
 * @param epicsMcaName
 */
public void setEpicsMcaName(int channel, String epicsMcaName) {
    if (channel >= 0 && channel < epicsMcaNameList.size()) {
        this.extraNames = (String[]) ArrayUtils.add(this.extraNames, epicsMcaName);
    }
}

From source file:gda.device.scannable.CoupledScannable.java

/**
 * @param newScannableName//from   w  w  w.j a  v a  2  s . c om
 *            The Scannable name to add.
 */
public void addScannableName(String newScannableName) {
    if (!ArrayUtils.contains(scannableNames, newScannableName)) {
        scannableNames = (String[]) ArrayUtils.add(scannableNames, newScannableName);
    }
}

From source file:de.ingrid.admin.command.PlugdescriptionCommandObject.java

public void addDatatypesOfIndex(String indexId, String type) {
    String[] indexDatatypes = getDatatypesOfIndex(indexId);
    if (!StringUtils.isEmptyOrWhiteSpace(type)
            && (indexDatatypes == null || !existsInArray(indexDatatypes, type))) {
        setDatatypesOfIndex(indexId, (String[]) ArrayUtils.add(indexDatatypes, type));
    }/*from  www.j a  v a  2  s.c om*/
}

From source file:info.archinnov.achilles.internal.context.DaoContext.java

public void pushUpdateStatement(PersistenceContext context, List<PropertyMeta> pms) {
    log.debug("Push insert statement for PersistenceContext '{}' and properties '{}'", context, pms);
    EntityMeta entityMeta = context.getEntityMeta();
    Optional<Integer> ttlO = context.getTtt();
    Optional<Long> timestampO = context.getTimestamp();
    ConsistencyLevel writeLevel = overrider.getWriteLevel(context, entityMeta);
    if (timestampO.isPresent()) {
        final Pair<Update.Where, Object[]> pair = statementGenerator.generateUpdateFields(context.getEntity(),
                entityMeta, pms);//from   w  w w  . ja v a  2  s. c o m

        final Update.Where where = pair.left;
        Object[] boundValues = pair.right;
        Update.Options updateOptions = where.using(timestamp(timestampO.get()));
        boundValues = ArrayUtils.add(boundValues, timestampO.get());

        if (ttlO.isPresent()) {
            updateOptions = updateOptions.and(ttl(ttlO.get()));
            boundValues = ArrayUtils.add(boundValues, ttlO.get());
        }
        context.pushStatement(new RegularStatementWrapper(updateOptions, boundValues, getCQLLevel(writeLevel)));
    } else {
        PreparedStatement ps = cacheManager.getCacheForFieldsUpdate(session, dynamicPSCache, context, pms);
        BoundStatementWrapper bsWrapper = binder.bindForUpdate(ps, entityMeta, pms, context.getEntity(),
                writeLevel, ttlO);
        context.pushStatement(bsWrapper);
    }
}

From source file:info.magnolia.jaas.sp.AbstractLoginModule.java

@Override
public boolean login() throws LoginException {
    if (this.getSkip()) {
        return true;
    }//from w  ww.j a v a2s.  c  o  m

    if (this.callbackHandler == null) {
        throw new LoginException("Error: no CallbackHandler available");
    }

    Callback[] callbacks = new Callback[2];
    callbacks[0] = new NameCallback("name");
    callbacks[1] = new PasswordCallback("pswd", false);

    // if the realm is not defined in the jaas configuration
    // we ask use a callback to get the value
    if (this.useRealmCallback) {
        callbacks = (Callback[]) ArrayUtils.add(callbacks, new RealmCallback());
    }

    this.success = false;
    try {
        this.callbackHandler.handle(callbacks);
        this.name = ((NameCallback) callbacks[0]).getName();
        this.pswd = ((PasswordCallback) callbacks[1]).getPassword();
        if (this.useRealmCallback) {
            String aRealm = ((RealmCallback) callbacks[2]).getRealm();
            this.realm = StringUtils.isBlank(aRealm) ? this.realm : Realm.Factory.newRealm(aRealm);
        }

        this.validateUser();
    } catch (IOException ioe) {
        log.debug("Exception caught", ioe);
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException ce) {
        log.debug(ce.getMessage(), ce);
        throw new LoginException(ce.getCallback().toString() + " not available");
    }

    // TODO: should not we set success BEFORE calling validateUser to give it chance to decide whether to throw an exception or reset the value to false?
    this.success = true;
    this.setSharedStatus(STATUS_SUCCEEDED);
    return this.success;
}

From source file:com.exoplatform.social.activity.storage.cache.CachedActivityStorage.java

private String[] add(String[] mentionerIds, String mentionStr, List<String> addedOrRemovedIds) {
    if (ArrayUtils.toString(mentionerIds).indexOf(mentionStr) == -1) { // the first mention
        addedOrRemovedIds.add(mentionStr.replace(MENTION_CHAR, ""));
        return (String[]) ArrayUtils.add(mentionerIds, mentionStr + 1);
    }/*from w w  w . j  a  v a2  s. c  o  m*/

    String storedId = null;
    for (String mentionerId : mentionerIds) {
        if (mentionerId.indexOf(mentionStr) != -1) {
            mentionerIds = (String[]) ArrayUtils.removeElement(mentionerIds, mentionerId);
            storedId = mentionStr + (Integer.parseInt(mentionerId.split(MENTION_CHAR)[1]) + 1);
            break;
        }
    }

    addedOrRemovedIds.add(mentionStr.replace(MENTION_CHAR, ""));
    mentionerIds = (String[]) ArrayUtils.add(mentionerIds, storedId);
    return mentionerIds;
}

From source file:net.navasoft.madcoin.backend.services.vo.request.SuccessRequestVOWrapper.java

/**
 * Gets the processing values.//from  ww w .j  a  v  a 2  s.com
 * 
 * @param service
 *            the service
 * @since 27/07/2014, 06:49:08 PM
 */
@Override
public void processValues(IService service) {
    if (isValidService(service)) {
        for (ProcessedField annotatedField : getTarget(service)) {
            for (Method accessor : filterMethods()) {
                Annotation annot = accessor.getAnnotation(ProcessingField.class);
                if (annot != null) {
                    ProcessingField expectedReal = ((ProcessingField) annot);
                    if (!ArrayUtils.contains(alreadyProcessed, expectedReal.expectedVariable())) {
                        try {
                            if (validateProcessAnnotations(annotatedField, expectedReal)) {
                                Object requestValue = null;
                                switch (expectedReal.precedence()) {
                                case BASIC_OPTIONAL:
                                    requestValue = accessor.invoke(hidden, ArrayUtils.EMPTY_OBJECT_ARRAY);
                                    processed.put(expectedReal.expectedVariable(), requestValue);
                                    alreadyProcessed = (String[]) ArrayUtils.add(alreadyProcessed,
                                            expectedReal.expectedVariable());
                                    break;
                                case BASIC_REQUIRED:
                                    requestValue = accessor.invoke(this.hidden, ArrayUtils.EMPTY_OBJECT_ARRAY);
                                    processed.put(expectedReal.expectedVariable(), requestValue);
                                    alreadyProcessed = (String[]) ArrayUtils.add(alreadyProcessed,
                                            expectedReal.expectedVariable());
                                    break;
                                case COMPLEX_OPTIONAL:
                                    requestValue = expectedReal.helperClass().newInstance();
                                    processed.put(expectedReal.expectedVariable(),
                                            expectedReal.helperClass()
                                                    .getMethod(expectedReal.converterMethod(),
                                                            ArrayUtils.EMPTY_CLASS_ARRAY)
                                                    .invoke(requestValue, ArrayUtils.EMPTY_OBJECT_ARRAY));
                                    alreadyProcessed = (String[]) ArrayUtils.add(alreadyProcessed,
                                            expectedReal.expectedVariable());
                                    break;
                                case COMPLEX_REQUIRED:
                                    requestValue = expectedReal.helperClass().newInstance();
                                    processed.put(expectedReal.expectedVariable(),
                                            expectedReal.helperClass()
                                                    .getMethod(expectedReal.converterMethod(),
                                                            ArrayUtils.EMPTY_CLASS_ARRAY)
                                                    .invoke(requestValue, ArrayUtils.EMPTY_OBJECT_ARRAY));
                                    alreadyProcessed = (String[]) ArrayUtils.add(alreadyProcessed,
                                            expectedReal.expectedVariable());
                                    break;
                                default:
                                    break;
                                }
                            }
                        } catch (IllegalAccessException e1) {
                        } catch (IllegalArgumentException e1) {
                        } catch (InvocationTargetException e1) {
                        } catch (NoSuchMethodException e) {
                        } catch (SecurityException e) {
                        } catch (InstantiationException e) {
                        }
                    }
                }
            }
        }
    }
}

From source file:com.blockwithme.hacktors.Mobile.java

/**
 * Tries to add some equipment to the mobile.
 * Returns false on failure.//  ww  w.  ja  va 2 s  .  c  om
 */
public boolean addItem(final Item theItem) {
    Preconditions.checkNotNull(theItem);
    if (getItems() == MAX_ITEMS) {
        // 10 is maximum items
        return false;
    }
    for (int i = 0; i < equipment.length; i++) {
        if (equipment[i] == theItem) {
            // Already in equipment ...
            return false;
        }

    }
    equipment = (Item[]) ArrayUtils.add(equipment, theItem);
    controller.itemAdded(theItem);
    return true;
}

From source file:net.firejack.platform.installation.processor.SetupSystemProcessor.java

public void setupSystemAlias() {
    String domainUrl = OpenFlameConfig.DOMAIN_URL.getValue();
    Integer port = Integer.parseInt(OpenFlameConfig.PORT.getValue());

    String[] domainUrlParts = domainUrl.split("\\.");
    ArrayUtils.reverse(domainUrlParts);/* w ww.  j  a v a  2  s  .  c  om*/
    if (domainUrlParts.length > 1 && !StringUtils.isNumeric(domainUrlParts[0])) {
        if (domainUrlParts.length == 2) {
            domainUrlParts = (String[]) ArrayUtils.add(domainUrlParts, "www");
        }

        String rootDomainLookup = domainUrlParts[0] + "." + domainUrlParts[1];

        RootDomainModel rootDomain = rootDomainStore.findByLookup(rootDomainLookup);
        if (rootDomain == null) {
            rootDomain = new RootDomainModel();
            rootDomain.setName(DiffUtils.findRootDomainName(rootDomainLookup));
            rootDomain.setLookup(rootDomainLookup);
            rootDomainStore.save(rootDomain);
        }

        RegistryNodeModel parent = rootDomain;
        if (domainUrlParts.length > 3) {
            String domainLookup = rootDomainLookup;
            for (int i = 2; i < domainUrlParts.length - 1; i++) {
                String domainName = domainUrlParts[i];
                domainLookup += "." + domainName;
                DomainModel domain = domainStore.findByLookup(domainLookup);
                if (domain == null) {
                    domain = new DomainModel();
                    domain.setName(domainName);
                    domain.setParent(parent);
                    domainStore.save(domain);
                    parent = domain;
                }
            }
        }

        String systemName = domainUrlParts[domainUrlParts.length - 1];
        String systemLookup = StringUtils.join(domainUrlParts, ".");
        SystemModel system = systemStore.findByLookup(systemLookup);
        if (system == null) {
            SystemModel mainSystem = systemStore.findByLookup(OpenFlame.SYSTEM);

            system = new SystemModel();
            system.setName(systemName);
            system.setServerName(domainUrl);
            system.setPort(port);
            system.setProtocol(EntityProtocol.HTTP);
            system.setStatus(RegistryNodeStatus.ACTIVE);
            system.setParent(parent);
            system.setMain(mainSystem);
            systemStore.save(system);
        }
    }
}

From source file:mitm.common.security.ca.handlers.comodo.ApplyCustomClientCert.java

/**
 * Requests a certificate. Returns true if a certificate was successfully requested. 
 * @return true if successful, false if an error occurs
 * @throws CustomClientCertException/*from w  w w  . j  a v a  2  s.c o  m*/
 */
public boolean apply() throws CustomClientCertException {
    reset();

    if (StringUtils.isEmpty(ap)) {
        throw new CustomClientCertException("ap must be specified.");
    }

    if (StringUtils.isEmpty(pkcs10)) {
        throw new CustomClientCertException("pkcs10 must be specified.");
    }

    PostMethod postMethod = new PostMethod(connectionSettings.getApplyCustomClientCertURL());

    NameValuePair[] data = { new NameValuePair("ap", ap), new NameValuePair("days", Integer.toString(days)),
            new NameValuePair("pkcs10", pkcs10), new NameValuePair("successURL", "none"),
            new NameValuePair("errorURL", "none") };

    if (cACertificateID != null) {
        data = (NameValuePair[]) ArrayUtils.add(data,
                new NameValuePair("caCertificateID", cACertificateID.toString()));
    }

    postMethod.setRequestBody(data);

    HTTPMethodExecutor executor = new HTTPMethodExecutor(connectionSettings.getTotalTimeout(),
            connectionSettings.getProxyInjector());

    executor.setConnectTimeout(connectionSettings.getConnectTimeout());
    executor.setReadTimeout(connectionSettings.getReadTimeout());

    try {
        executor.executeMethod(postMethod, responseHandler);
    } catch (IOException e) {
        throw new CustomClientCertException(e);
    }

    return !error;
}