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 double[] add(double[] array, int index, double element) 

Source Link

Document

Inserts the specified element at the specified position in the array.

Usage

From source file:com.thoughtworks.go.util.ArrayUtil.java

@SuppressWarnings("unchecked")
public static <T> T[] pushToArray(T firstOne, T[] array) {
    return (T[]) ArrayUtils.add(array, 0, firstOne);
}

From source file:com.opengamma.analytics.financial.model.volatility.smile.fitting.sabr.StandardSmileSurfaceDataBundle.java

public StandardSmileSurfaceDataBundle(final double spot, final double[] forwards, final double[] expiries,
        final double[][] strikes, final double[][] impliedVols, final Interpolator1D forwardCurveInterpolator) {
    ArgumentChecker.notNull(forwards, "forwards");
    ArgumentChecker.notNull(expiries, "expiries");
    ArgumentChecker.notNull(strikes, "strikes");
    ArgumentChecker.notNull(impliedVols, "implied volatilities");
    ArgumentChecker.notNull(forwardCurveInterpolator, "forward curve interpolator");
    _nExpiries = expiries.length;/*from ww  w .  j  a  v  a2 s .c  o m*/
    ArgumentChecker.isTrue(_nExpiries == forwards.length, "forwards wrong length; have {}, need {}",
            forwards.length, _nExpiries);
    ArgumentChecker.isTrue(_nExpiries == strikes.length, "strikes wrong length; have {}, need {}",
            strikes.length, _nExpiries);
    ArgumentChecker.isTrue(_nExpiries == impliedVols.length,
            "implied volatilities wrong length; have {}, need {}", impliedVols.length, _nExpiries);
    for (int i = 0; i < strikes.length; i++) {
        ArgumentChecker.isTrue(strikes[i].length == impliedVols[i].length,
                "implied volatilities for expiry {} not the same length as strikes; have {}, need {}",
                strikes[i].length, impliedVols[i].length);
    }
    // checkVolatilities(expiries, strikes, impliedVols); // Put this check in place, if desired, after construction.
    _expiries = expiries;
    _forwards = forwards;

    final double[] t = ArrayUtils.add(expiries, 0, 0.0);
    final double[] f = ArrayUtils.add(forwards, 0, spot);
    _forwardCurve = new ForwardCurve(InterpolatedDoublesCurve.from(t, f, forwardCurveInterpolator));
    _strikes = strikes;
    _impliedVols = impliedVols;
}

From source file:com.eryansky.web.base.OrganAction.java

/**
 * combogrid//from ww w  .  j a va2  s  .  c o  m
 * @return
 * @throws Exception
 */
public String combogrid() throws Exception {
    try {
        Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue());
        Criterion[] criterions = new Criterion[0];
        criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion);
        Criterion criterion = null;
        if (!Collections3.isEmpty(ids)) {
            //in?
            Criterion inCriterion = Restrictions.in("id", ids);

            if (StringUtils.isNotBlank(nameOrCode)) {
                Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE);
                Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE);
                Criterion criterion1 = Restrictions.or(nameCriterion, codeCriterion);
                criterion = Restrictions.or(inCriterion, criterion1);
            } else {
                criterion = inCriterion;
            }
            //??
            criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
        } else {
            if (StringUtils.isNotBlank(nameOrCode)) {
                Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE);
                Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE);
                criterion = Restrictions.or(nameCriterion, codeCriterion);
                //??
                criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
            }
        }

        //
        Page<Organ> p = new Page<Organ>(rows);//
        p = organManager.findByCriteria(p, criterions);
        Datagrid<Organ> dg = new Datagrid<Organ>(p.getTotalCount(), p.getResult());
        Struts2Utils.renderJson(dg);
    } catch (Exception e) {
        throw e;
    }
    return null;
}

From source file:info.archinnov.achilles.statement.prepared.CQLPreparedStatementBinder.java

public BoundStatementWrapper bindForSimpleCounterIncrementDecrement(PreparedStatement ps, EntityMeta entityMeta,
        PropertyMeta pm, Object primaryKey, Long increment) {
    Object[] boundValues = ArrayUtils.add(extractValuesForSimpleCounterBinding(entityMeta, pm, primaryKey), 0,
            increment);//from  ww  w  .  ja  v a 2s .  com

    BoundStatement bs = ps.bind(boundValues);

    return new BoundStatementWrapper(bs, boundValues);

}

From source file:info.archinnov.achilles.internal.statement.prepared.PreparedStatementBinder.java

public BoundStatementWrapper bindForSimpleCounterIncrementDecrement(PreparedStatement ps, EntityMeta entityMeta,
        PropertyMeta pm, Object primaryKey, Long increment, ConsistencyLevel consistencyLevel) {
    log.trace("Bind prepared statement {} for simple counter increment of {} using primary key {} and value {}",
            ps.getQueryString(), pm, primaryKey, increment);
    Object[] boundValues = ArrayUtils.add(extractValuesForSimpleCounterBinding(entityMeta, pm, primaryKey), 0,
            increment);/*w w  w  .  j av  a2  s.c o m*/

    BoundStatement bs = ps.bind(boundValues);
    return new BoundStatementWrapper(bs, boundValues, getCQLLevel(consistencyLevel));
}

From source file:com.eryansky.web.base.UserAction.java

/**
 * combogrid//from w  ww.j a v a2 s.  c om
 * @return
 * @throws Exception
 */
public String combogrid() throws Exception {
    try {
        Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue());
        Criterion[] criterions = new Criterion[0];
        criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion);
        Criterion criterion = null;
        if (!Collections3.isEmpty(ids)) {
            //in?
            Criterion inCriterion = Restrictions.in("id", ids);

            if (StringUtils.isNotBlank(loginNameOrName)) {
                Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName,
                        MatchMode.ANYWHERE);
                Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
                Criterion criterion1 = Restrictions.or(loginNameCriterion, nameCriterion);
                criterion = Restrictions.or(inCriterion, criterion1);
            } else {
                criterion = inCriterion;
            }
            //??
            criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
        } else {
            if (StringUtils.isNotBlank(loginNameOrName)) {
                Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName,
                        MatchMode.ANYWHERE);
                Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
                criterion = Restrictions.or(loginNameCriterion, nameCriterion);
                //??
                criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
            }
        }

        //
        Page<User> p = new Page<User>(rows);//
        p = userManager.findByCriteria(p, criterions);
        Datagrid<User> dg = new Datagrid<User>(p.getTotalCount(), p.getResult());
        Struts2Utils.renderJson(dg);
    } catch (Exception e) {
        throw e;
    }
    return null;
}

From source file:info.archinnov.achilles.statement.prepared.CQLPreparedStatementBinder.java

public BoundStatementWrapper bindForClusteredCounterIncrementDecrement(PreparedStatement ps,
        EntityMeta entityMeta, PropertyMeta pm, Object primaryKey, Long increment) {
    List<Object> primarykeys = bindPrimaryKey(primaryKey, entityMeta.getIdMeta());
    Object[] keys = ArrayUtils.add(primarykeys.toArray(new Object[primarykeys.size()]), 0, increment);

    BoundStatement bs = ps.bind(keys);/*from  w w  w  .jav a2  s. c om*/

    return new BoundStatementWrapper(bs, keys);
}

From source file:gda.scan.MultiScanRunner.java

@Override
public ScanInformation getScanInformation() {
    ScanInformation info = first.getScanInformation();

    int[] dimensions = info.getDimensions();
    dimensions = ArrayUtils.add(dimensions, 0, scans.size());
    info.setDimensions(dimensions);/*w  ww  . j  ava2s . c  o m*/

    int points = 0;
    for (MultiScanItem scan : scans) {
        points += scan.scan.getScanInformation().getNumberOfPoints();
    }
    info.setNumberOfPoints(points);

    return info;
}

From source file:info.archinnov.achilles.internal.statement.prepared.PreparedStatementBinder.java

public BoundStatementWrapper bindForClusteredCounterIncrementDecrement(PreparedStatement ps,
        EntityMeta entityMeta, Object primaryKey, Long increment, ConsistencyLevel consistencyLevel) {
    log.trace(/*w ww . j  ava 2s  . co  m*/
            "Bind prepared statement {} for clustered counter increment/decrement for {} using primary key {} and value {}",
            ps.getQueryString(), entityMeta, primaryKey, increment);

    List<Object> primaryKeys = bindPrimaryKey(primaryKey, entityMeta.getIdMeta());
    Object[] keys = ArrayUtils.add(primaryKeys.toArray(new Object[primaryKeys.size()]), 0, increment);

    BoundStatement bs = ps.bind(keys);

    return new BoundStatementWrapper(bs, keys, getCQLLevel(consistencyLevel));
}

From source file:fr.inria.atlanmod.neoemf.map.datastore.estores.impl.DirectWriteMapResourceEStoreImpl.java

protected void add(PersistentEObject object, EAttribute eAttribute, int index, Object value) {
    Object[] array = (Object[]) getFromMap(object, eAttribute);
    if (array == null) {
        array = new Object[] {};
    }/*  www  .  j  av a  2s .  c  o  m*/
    array = ArrayUtils.add(array, index, serializeToMapValue(eAttribute, value));
    map.put(Fun.t2(object.id(), eAttribute.getName()), array);
}