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:com.facebook.presto.accumulo.index.Indexer.java

/**
 * Gets the column family of the index table based on the given column family and qualifier.
 *
 * @param columnFamily Presto column family
 * @param columnQualifier Presto column qualifier
 * @return ByteBuffer of the given index column family
 *//* www .j  a  va  2  s .  c  o  m*/
public static ByteBuffer getIndexColumnFamily(byte[] columnFamily, byte[] columnQualifier) {
    return wrap(ArrayUtils.addAll(ArrayUtils.add(columnFamily, UNDERSCORE), columnQualifier));
}

From source file:net.jolm.JolmLdapTemplate.java

/**
 * Adds objectClass attribute to attributes list that need to be returned, it has to be
 * returned.//from ww w.  ja v a  2s .co m
 */
private String[] addObjectClassIfMissed(String[] attributes) {
    if (!Arrays.asList(attributes).contains("objectClass")) {
        return (String[]) ArrayUtils.add(attributes, "objectClass");
    }
    return attributes;
}

From source file:gda.jython.scriptcontroller.logging.LoggingScriptController.java

private String[] getUpdateValues(ScriptControllerLoggingMessage arg) {
    String[] values = new String[0];
    for (Method getter : refreshColumnGetters.keySet()) {
        try {//from w ww. ja  v  a2s  . c o  m
            String value = getter.invoke(arg, new Object[] {}).toString();
            values = (String[]) ArrayUtils.add(values, value);
        } catch (Exception e) {
            logger.debug("Exception invoking method " + getter.getName(), e);
        }
    }
    return values;
}

From source file:gda.jython.scriptcontroller.logging.LoggingScriptController.java

private String[] getValues(ScriptControllerLoggingMessage arg) {
    String[] values = new String[0];
    for (Method getter : columnGetters.keySet()) {
        try {// w  w w.  jav a2  s.c o  m
            String value = getter.invoke(arg, new Object[] {}).toString();
            values = (String[]) ArrayUtils.add(values, value);
        } catch (Exception e) {
            logger.debug("Exception invoking method " + getter.getName(), e);
        }
    }
    return values;
}

From source file:com.haulmont.cuba.core.sys.MetadataLoader.java

protected void postProcessProperty(MetaClass metaClass, MetaProperty metaProperty) {
    // init inverse properties
    MetaProperty inverseProp = metaProperty.getInverse();
    if (inverseProp != null && inverseProp.getInverse() == null) {
        ((MetaPropertyImpl) inverseProp).setInverse(metaProperty);
    }//from  w  w w.  j  a  v a2s .  com

    if (metaProperty.getRange() == null || !metaProperty.getRange().isClass())
        return;

    AnnotatedElement annotatedElement = metaProperty.getAnnotatedElement();

    OnDelete onDelete = annotatedElement.getAnnotation(OnDelete.class);
    if (onDelete != null) {
        Map<String, Object> metaAnnotations = metaClass.getAnnotations();

        MetaProperty[] properties = (MetaProperty[]) metaAnnotations.get(OnDelete.class.getName());
        properties = (MetaProperty[]) ArrayUtils.add(properties, metaProperty);
        metaAnnotations.put(OnDelete.class.getName(), properties);
    }

    OnDeleteInverse onDeleteInverse = annotatedElement.getAnnotation(OnDeleteInverse.class);
    if (onDeleteInverse != null) {
        Map<String, Object> metaAnnotations = metaProperty.getRange().asClass().getAnnotations();

        MetaProperty[] properties = (MetaProperty[]) metaAnnotations.get(OnDeleteInverse.class.getName());
        properties = (MetaProperty[]) ArrayUtils.add(properties, metaProperty);
        metaAnnotations.put(OnDeleteInverse.class.getName(), properties);
    }
}

From source file:au.org.ala.biocache.web.ExploreController.java

/**
 * Returns the species that only have occurrences in the supplied WKT.
 * @return// w ww . ja va 2s . c o  m
 */
@RequestMapping(value = "/explore/endemic/species.csv", method = RequestMethod.GET)
public void getEndemicSpeciesCSV(SpatialSearchRequestParams requestParams, HttpServletResponse response)
        throws Exception {
    requestParams.setFacets(new String[] { SearchDAOImpl.NAMES_AND_LSID });
    requestParams.setFq((String[]) ArrayUtils.add(requestParams.getFq(), "species_guid:[* TO *]"));
    List<FieldResultDTO> list = getSpeciesOnlyInWKT(requestParams, response);
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/plain");
    java.io.PrintWriter writer = response.getWriter();
    writer.write("Family,Scientific name,Common name,Taxon rank,LSID,# Occurrences");
    for (FieldResultDTO item : list) {
        String s = item.getLabel();
        if (s.startsWith("\"") && s.endsWith("\"") && s.length() > 2)
            s = s.substring(1, s.length() - 1);
        String[] values = s.split("\\|", 6);
        if (values.length >= 5) {
            writer.write("\n" + values[4] + ",\"" + values[0] + "\",\"" + values[2] + "\",," + values[1] + ","
                    + item.getCount());
        }
    }
    writer.flush();
    writer.close();
}

From source file:au.org.ala.biocache.dao.SearchDAOImpl.java

/**
 * Writes the values for the first supplied facet to output stream
 * /*from   w  w w.  j  a va  2  s.  co m*/
 * @param includeCount true when the count should be included in the download
 * @param lookupName true when a name lsid should be looked up in the bie
 * 
 */
public void writeFacetToStream(SpatialSearchRequestParams searchParams, boolean includeCount,
        boolean lookupName, boolean includeSynonyms, OutputStream out, DownloadDetailsDTO dd) throws Exception {
    //set to unlimited facets
    searchParams.setFlimit(-1);
    formatSearchQuery(searchParams);
    //add the context information
    updateQueryContext(searchParams);
    String queryString = buildSpatialQueryString(searchParams);
    SolrQuery solrQuery = initSolrQuery(searchParams, false, null);
    solrQuery.setQuery(queryString);

    //don't want any results returned
    solrQuery.setRows(0);
    solrQuery.setFacetLimit(FACET_PAGE_SIZE);
    int offset = 0;
    boolean shouldLookup = lookupName
            && (searchParams.getFacets()[0].contains("_guid") || searchParams.getFacets()[0].contains("_lsid"));

    QueryResponse qr = runSolrQuery(solrQuery, searchParams);
    logger.debug("Retrieved facet results from server...");
    if (!qr.getResults().isEmpty()) {
        FacetField ff = qr.getFacetField(searchParams.getFacets()[0]);

        //write the header line
        if (ff != null) {
            String[] header = new String[] { ff.getName() };
            // out.write(ff.getName().getBytes());
            if (shouldLookup) {
                header = speciesLookupService.getHeaderDetails(ff.getName(), includeCount, includeSynonyms);
            } else if (includeCount) {
                //out.write(",Count".getBytes());
                header = (String[]) ArrayUtils.add(header, "count");
            }
            CSVRecordWriter writer = new CSVRecordWriter(out, header);
            //out.write("\n".getBytes());
            //PAGE through the facets until we reach the end.
            while (ff.getValueCount() > 0) {
                if (ff.getValueCount() > 0) {
                    //process the "species_guid_ facet by looking up the list of guids
                    if (shouldLookup) {

                        List<String> guids = new ArrayList<String>();
                        List<Long> counts = new ArrayList<Long>();
                        logger.debug("Downloading " + ff.getValueCount() + " species guids");
                        for (FacetField.Count value : ff.getValues()) {
                            guids.add(value.getName());
                            if (includeCount) {
                                counts.add(value.getCount());
                            }

                            //Only want to send a sub set of the list so that the URI is not too long for BIE
                            if (guids.size() == 30) {
                                //now get the list of species from the web service TODO may need to move this code
                                //handle null values being returned from the service...
                                writeTaxonDetailsToStream(guids, counts, includeCount, includeSynonyms, writer);
                                guids.clear();
                                counts.clear();
                            }
                        }
                        //now write any guids that remain at the end of the looping
                        writeTaxonDetailsToStream(guids, counts, includeCount, includeSynonyms, writer);
                    } else {
                        //default processing of facets
                        for (FacetField.Count value : ff.getValues()) {
                            String[] row = includeCount
                                    ? new String[] { value.getName(), Long.toString(value.getCount()) }
                                    : new String[] { value.getName() };
                            writer.write(row);
                        }
                    }
                    offset += FACET_PAGE_SIZE;
                    if (dd != null) {
                        dd.updateCounts(FACET_PAGE_SIZE);
                    }
                    //get the next values
                    solrQuery.remove("facet.offset");
                    solrQuery.add("facet.offset", Integer.toString(offset));
                    qr = runSolrQuery(solrQuery, searchParams);
                    ff = qr.getFacetField(searchParams.getFacets()[0]);
                }
                writer.finalise();
            }
        }
    }
}

From source file:net.navasoft.madcoin.backend.model.entities.impl.ServiceProviders.java

/**
 * Gets the conditions.//  w  w  w  .j  a v a  2  s.  c o m
 * 
 * @return the conditions
 * @since 7/09/2014, 06:51:59 PM
 */
@Override
@Transient
public Object[] getConditions() {
    Object[] result = (Object[]) Array.newInstance(Object.class, 0);
    for (WorkRequestsXServiceProviders scheduled : workRequestsXServiceProvidersCollection) {
        if (scheduled.getWorkRequests().getEstimatedClosing() != null) {
            result = ArrayUtils.add(result, scheduled.getWorkRequests().getEstimatedArrival());
            result = ArrayUtils.add(result, scheduled.getWorkRequests().getEstimatedClosing());
        }
    }
    result = ArrayUtils.add(result, getProviderRole().getProviderScope());
    // TODO obtener token de logueo
    result = ArrayUtils.add(result, "df75a122 60b499a0 ae60c94f 4040330d 2e10a37d ba657451 c4df2120 fca8ad25");
    return result;
}

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

/**
 * Converts a position object to an array of doubles. It position is an Angle quantity it is converted to degrees,
 * if a linear quantity it is converted to mm, else it is just treated as a number.
 * // w  ww  .  j a v  a  2  s .c o m
 * @param position
 * @return array of doubles
 */
public static Double[] objectToArray(Object position) {

    Double[] posArray = new Double[0];
    if (position instanceof Double[]) {
        return (Double[]) position;

    }
    if (position instanceof Number[]) {
        int length = ArrayUtils.getLength(position);
        posArray = new Double[length];
        for (int i = 0; i < length; i++) {
            posArray[i] = ((Number[]) position)[i].doubleValue();
        }
        return posArray;
    } else if (position instanceof Object[]) {
        int length = ((Object[]) position).length;
        posArray = new Double[length];
        for (int i = 0; i < length; i++) {
            Object obj = ((Object[]) position)[i];
            Double val = null;
            if (obj instanceof String) {
                val = Double.parseDouble((String) obj);
            } else if (obj instanceof Number) {
                val = ((Number) obj).doubleValue();
            } else if (obj instanceof PyObject) {
                val = (Double) ((PyObject) obj).__tojava__(Double.class);
            }
            posArray[i] = val;
        }
        return posArray;
    }
    // if its a Java array
    else if (position.getClass().isArray()) {
        int length = ArrayUtils.getLength(position);
        for (int i = 0; i < length; i++) {
            posArray = (Double[]) ArrayUtils.add(posArray, Array.getDouble(position, i));
        }
        return posArray;
    }
    // if its a Jython array
    else if (position instanceof PySequence) {
        int length = ((PySequence) position).__len__();
        for (int i = 0; i < length; i++) {
            posArray = (Double[]) ArrayUtils.add(posArray, getDouble(position, i));
        }
    }
    // if its a Jython array
    else if (position instanceof List) {
        @SuppressWarnings("rawtypes")
        int length = ((List) position).size();
        for (int i = 0; i < length; i++) {
            posArray = (Double[]) ArrayUtils.add(posArray, getDouble(position, i));
        }
    }
    // if its a Quantity
    else if (position instanceof Quantity) {
        posArray = (Double[]) ArrayUtils.add(posArray, ((Quantity) position).getAmount());
    }
    // if its a String, then try to convert to a double
    else if (position instanceof String) {
        Quantity posAsQ = QuantityFactory.createFromString((String) position);
        Double posAsDouble = posAsQ != null ? posAsQ.getAmount() : Double.parseDouble((String) position);
        posArray = (Double[]) ArrayUtils.add(posArray, posAsDouble);
    }
    // else assume its some object whose toString() method returns a String which can be converted
    else {
        posArray = (Double[]) ArrayUtils.add(posArray, Double.parseDouble(position.toString()));
    }
    return posArray;
}

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

/**
 * Converts a Jython PyObject into its Java equivalent if that is possible. This only works on the sorts of objects
 * dealt with in the Jython environment i.e. Strings, integers, floats (doubles) and arrays of these.
 * <P>//from   w w  w . j a v a 2s. c om
 * If this fails or cannot work for any reason then null is returned.
 * 
 * @param object
 * @return Java equivalent object
 */
public static Object convertToJava(PyObject object) {

    Object output = null;
    if (object instanceof PyFloat) {
        output = object.__tojava__(Double.class);
    } else if (object instanceof PyInteger) {
        output = object.__tojava__(Integer.class);
    } else if (object instanceof PyString) {
        output = object.__tojava__(String.class);
    } else if (object instanceof PySequence || object instanceof PyList) {
        // create a Java array of PyObjects
        // ArrayList<PyObject> theList = (ArrayList<PyObject>)
        // object.__tojava__(ArrayList.class);

        // loop through and convert each item into its Java equivilent
        output = new Object[0];
        int length;

        if (object instanceof PySequence) {
            length = ((PySequence) object).__len__();
        } else {
            length = ((PyList) object).__len__();
        }
        for (int i = 0; i < length; i++) {

            PyObject item = null;

            if (object instanceof PySequence) {
                item = ((PySequence) object).__finditem__(i);
            } else {
                item = ((PyList) object).__finditem__(i);
            }

            if (item instanceof PyFloat) {
                Double thisItem = (Double) item.__tojava__(Double.class);
                output = ArrayUtils.add((Object[]) output, thisItem);
            } else if (item instanceof PyInteger) {
                Integer thisItem = (Integer) item.__tojava__(Integer.class);
                output = ArrayUtils.add((Object[]) output, thisItem);
            } else if (item instanceof PyString) {
                String thisItem = (String) item.__tojava__(String.class);
                output = ArrayUtils.add((Object[]) output, thisItem);
            }
        }
    }

    if (output == org.python.core.Py.NoConversion) {
        output = null;
    }

    return output;
}