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

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

Introduction

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

Prototype

public static double[] addAll(double[] array1, double[] array2) 

Source Link

Document

Adds all the elements of the given arrays into a new array.

Usage

From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.message.BinRpcMessage.java

/**
 * Decodes a BIN-RPC message from the given InputStream.
 *//*  w w w . j  ava2  s  .co m*/
public BinRpcMessage(InputStream is, boolean methodHeader, String encoding) throws IOException {
    this.encoding = encoding;
    byte sig[] = new byte[8];
    int length = is.read(sig, 0, 4);
    if (length != 4) {
        throw new EOFException("Only " + length + " bytes received reading signature");
    }
    validateBinXSignature(sig);
    length = is.read(sig, 4, 4);
    if (length != 4) {
        throw new EOFException("Only " + length + " bytes received reading message length");
    }
    int datasize = (new BigInteger(ArrayUtils.subarray(sig, 4, 8))).intValue();
    byte payload[] = new byte[datasize];
    int offset = 0;
    int currentLength;

    while (offset < datasize && (currentLength = is.read(payload, offset, datasize - offset)) != -1) {
        offset += currentLength;
    }
    if (offset != datasize) {
        throw new EOFException("Only " + offset + " bytes received while reading message payload, expected "
                + datasize + " bytes");
    }
    byte[] message = ArrayUtils.addAll(sig, payload);
    decodeMessage(message, methodHeader);
}

From source file:org.eclipse.smarthome.core.net.HttpServiceUtilTest.java

@Before
public void setup() throws InvalidSyntaxException {
    initMocks(this);

    ServiceReference<?>[] httpServiceReferences = getHttpServiceReferences();
    ServiceReference<?>[] secureHttpServiceReferences = getSecureHttpServiceReferences();

    when(bundleContext.getAllServiceReferences(ORG_OSGI_SERVICE_HTTP_SERVICE, null)).thenReturn(
            (ServiceReference<?>[]) ArrayUtils.addAll(httpServiceReferences, secureHttpServiceReferences));
}

From source file:org.eclipse.virgo.ide.runtime.internal.ui.providers.FlattenedArtefactsContentProvider.java

@Override
public Object[] getElements(Object inputElement) {

    /*/*  ww w .ja  v  a2s .  co m*/
     * while (items.hasNext()) { Object next = items.next(); if (next instanceof IServer) { servers.add((IServer)
     * next); } if (next instanceof LibrariesNode) { servers.add(((LibrariesNode) next).getServer()); } if (next
     * instanceof IServerProjectContainer || next instanceof ArtefactSet) { containers.add(next); } if (next
     * instanceof IArtefact || next instanceof IServerProjectArtefact) { artifacts.add(next); } }
     */

    if (inputElement instanceof IServer) {
        IServer server = (IServer) inputElement;
        ServerProject project = ServerProjectManager.getInstance().getProject(server);
        if (project != null) {
            IServerProjectContainer[] containers = project.getContainers()
                    .toArray(new IServerProjectContainer[0]);
            Object[] members = new Object[0];
            for (IServerProjectContainer container : containers) {
                Object[] roots = container.getMembers();
                members = ArrayUtils.addAll(members, roots);
            }
            return members;
        }
    }
    return super.getElements(inputElement);
}

From source file:org.eclipse.virgo.ide.runtime.internal.ui.providers.FlattenedPropertiesFileContentProvider.java

@Override
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof IServer) {
        Object[] elements = super.getElements(inputElement);
        Object[] returned = new Object[0];
        for (Object object : elements) {
            Object[] fileSelection = super.getElements(object);
            returned = ArrayUtils.addAll(returned, fileSelection);
        }/*from   w w w.  j a  va2s  .c  o m*/
        return returned;
    }
    return super.getElements(inputElement);
}

From source file:org.eclipse.virgo.ide.runtime.internal.ui.providers.GenericTreeProvider.java

/**
 * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
 *///w w  w. j  ava 2s.  c  o m
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof Collection) {
        Collection<?> collection = (Collection<?>) inputElement;
        Object[] elements = new Object[] {};
        for (Object object : collection) {
            elements = ArrayUtils.addAll(elements, getElements(object));
        }
        return elements;
    }
    return new Object[0];
}

From source file:org.eclipse.wb.tests.designer.rcp.model.layout.form.gef.FormLayoutAlignmentTest.java

private static String[] getLines_twoButtons_typical(String[] constraints_1, String[] constraints_2) {
    constraints_1 = (String[]) ArrayUtils.clone(constraints_1);
    constraints_2 = (String[]) ArrayUtils.clone(constraints_2);
    for (int i = 0; i < constraints_1.length; i++) {
        constraints_1[i] = "        data_1." + constraints_1[i];
    }/*w  w  w  .ja  v  a 2s  . c o  m*/
    for (int i = 0; i < constraints_2.length; i++) {
        constraints_2[i] = "        data_2." + constraints_2[i];
    }
    String[] lines = new String[] { "public class Test extends Shell {", "  private Button button_1;",
            "  private Button button_2;", "  public Test() {", "    setLayout(new FormLayout());", "    {",
            "      button_1 = new Button(this, SWT.NONE);", "      {",
            "        FormData data_1 = new FormData();" };
    lines = (String[]) ArrayUtils.addAll(lines, constraints_1);
    lines = (String[]) ArrayUtils.addAll(lines,
            new String[] { "        button_1.setLayoutData(data_1);", "      }", "    }", "    {",
                    "      button_2 = new Button(this, SWT.NONE);", "      {",
                    "        FormData data_2 = new FormData();" });
    lines = (String[]) ArrayUtils.addAll(lines, constraints_2);
    lines = (String[]) ArrayUtils.addAll(lines,
            new String[] { "        button_2.setLayoutData(data_2);", "      }", "    }", "  }", "}" });
    return lines;
}

From source file:org.ednovo.gooru.application.util.SerializerUtil.java

/**
 * @param model/* w ww.j ava 2 s  .c  om*/
 * @param type
 * @param excludes
 * @param includes
 * @return
 */
public static String serialize(Object model, final String type, String[] excludes, boolean deepSerialize,
        final boolean useBaseExcludes, final boolean excludeNullObject, String... includes) {
    if (model == null) {
        return "";
    }
    String serializedData = null;
    JSONSerializer serializer = new JSONSerializer();
    boolean handlingAssessmentQuestion = willSerializeAssessmentQuestion(model);

    if (type == null || type.equals(JSON)) {

        if (includes != null) {
            includes = (String[]) ArrayUtils.add(includes, "*.contentPermissions");
            serializer.include(includes);
        } else {
            serializer.include("*.contentPermissions");
        }
        serializer.include(includes);

        if (useBaseExcludes) {
            if (excludes != null) {
                excludes = (String[]) ArrayUtils.addAll(excludes, EXCLUDES);
            } else {
                excludes = EXCLUDES;
            }
        }

        if (model instanceof User) {
            deepSerialize = true;
        }
        if (model != null) {
            serializer = appendTransformers(serializer, excludeNullObject);
        }
        if (handlingAssessmentQuestion) {
            serializer = handleAssessmentQuestionTransformers(serializer);
        }

        if (excludes != null) {
            serializer.exclude(excludes);
        }

        try {
            model = protocolSwitch(model);
            serializedData = deepSerialize ? serializer.deepSerialize(model) : serializer.serialize(model);
            log(model, serializedData);

        } catch (Exception ex) {
            LOGGER.error("serialize: happened to throw exception", ex);
            if (model instanceof Resource) {
                LOGGER.error("Serialization failed for resource : " + ((Resource) model).getContentId());
            } else if (model instanceof List) {
                List list = (List<?>) model;
                if (list != null && list.size() > 0 && list.get(0) instanceof Resource) {
                    LOGGER.error("Serialization failed for list resources of size : " + list.size()
                            + " resource : " + ((Resource) list.get(0)).getContentId());
                }
            } else {
                LOGGER.error("Serialization failed" + ex);
            }
            throw new MethodFailureException(ex.getMessage());
        }

    } else {
        serializedData = new XStream().toXML(model);
    }
    return serializedData;
}

From source file:org.ednovo.gooru.controllers.v1.api.DomainRestController.java

@AuthorizeOperations(operations = { GooruOperationConstants.OPERATION_DOMAIN_ADD })
@RequestMapping(method = RequestMethod.POST)
public ModelAndView createDomain(@RequestBody String data, HttpServletRequest request,
        HttpServletResponse response) {//from w  w  w .  j a v  a 2 s .  co m
    final User user = (User) request.getAttribute(Constants.USER);
    ActionResponseDTO<Domain> responseDTO = getDomainService()
            .createDomain(buildDomainFromInputParameters(data), user);
    if (responseDTO.getErrors().getErrorCount() > 0) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    } else {
        response.setStatus(HttpServletResponse.SC_CREATED);
        responseDTO.getModel().setUri(
                RequestMappingUri.DOMAIN + RequestMappingUri.SEPARATOR + responseDTO.getModel().getDomainId());
    }
    String includes[] = (String[]) ArrayUtils.addAll(CREATE_INCLUDES, ERROR_INCLUDE);
    return toModelAndViewWithIoFilter(responseDTO.getModelData(), RESPONSE_FORMAT_JSON, EXCLUDE_ALL, true,
            includes);
}

From source file:org.ednovo.gooru.controllers.v1.api.SubdomainRestController.java

@AuthorizeOperations(operations = { GooruOperationConstants.OPERATION_SUBDOMAIN_ADD })
@RequestMapping(method = RequestMethod.POST)
public ModelAndView createSubdomain(HttpServletRequest request, HttpServletResponse response,
        @RequestBody String data) {
    User user = (User) request.getAttribute(Constants.USER);
    final ActionResponseDTO<Subdomain> responseDTO = this.getSubdomainService()
            .createSubdomain(buildSubdomainFromInputParameters(data), user);
    if (responseDTO.getErrors().getErrorCount() > 0) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    } else {/*from   www  .jav  a  2  s.com*/
        response.setStatus(HttpServletResponse.SC_CREATED);
        responseDTO.getModel().setUri(RequestMappingUri.SUBDOMAIN + RequestMappingUri.SEPARATOR
                + responseDTO.getModel().getSubdomainId());
    }
    String includes[] = (String[]) ArrayUtils.addAll(CREATE_INCLUDES, ERROR_INCLUDE);
    return toModelAndViewWithIoFilter(responseDTO.getModelData(), FORMAT_JSON, EXCLUDE_ALL, true, includes);
}

From source file:org.ednovo.gooru.controllers.v1.api.SubjectRestController.java

@AuthorizeOperations(operations = { GooruOperationConstants.OPERATION_SUBJECT_ADD })
@RequestMapping(method = RequestMethod.POST)
public ModelAndView createSubject(HttpServletRequest request, HttpServletResponse response,
        @RequestBody String data) {
    User user = (User) request.getAttribute(Constants.USER);
    final ActionResponseDTO<Subject> responseDTO = this.getSubjectService()
            .createSubject(buildSubjectFromInputParameters(data), user);
    if (responseDTO.getErrors().getErrorCount() > 0) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    } else {//from   w w w.  jav  a 2  s.c o m
        response.setStatus(HttpServletResponse.SC_CREATED);
        responseDTO.getModel().setUri(RequestMappingUri.SUBJECT + RequestMappingUri.SEPARATOR
                + responseDTO.getModel().getSubjectId());
    }
    String includes[] = (String[]) ArrayUtils.addAll(CREATE_INCLUDES, ERROR_INCLUDE);
    return toModelAndViewWithIoFilter(responseDTO.getModelData(), FORMAT_JSON, EXCLUDE_ALL, true, includes);
}