Example usage for java.util Vector toArray

List of usage examples for java.util Vector toArray

Introduction

In this page you can find the example usage for java.util Vector toArray.

Prototype

@SuppressWarnings("unchecked")
public synchronized <T> T[] toArray(T[] a) 

Source Link

Document

Returns an array containing all of the elements in this Vector in the correct order; the runtime type of the returned array is that of the specified array.

Usage

From source file:org.n52.oxf.sos.adapter.SOSCapabilitiesMapper_200.java

private ServiceIdentification mapServiceIdentification(CapabilitiesType capabilities) {

    if (!capabilities.isSetServiceIdentification()) {
        return null;
    }// w ww .j  a v a  2 s  .  c o m

    net.opengis.ows.x11.ServiceIdentificationDocument.ServiceIdentification serviceIdentification = capabilities
            .getServiceIdentification();

    String oc_title = serviceIdentification.getTitleArray(0).getStringValue();
    String oc_serviceType = serviceIdentification.getServiceType().getStringValue();
    String[] oc_serviceTypeVersions = serviceIdentification.getServiceTypeVersionArray();

    String oc_fees = serviceIdentification.getFees();
    String[] oc_accessConstraints = serviceIdentification.getAccessConstraintsArray();
    String oc_abstract = null;
    if (oc_accessConstraints.length != 0) {
        oc_abstract = serviceIdentification.getAbstractArray(0).getStringValue();
    }
    String[] oc_keywords = null;

    Vector<String> oc_keywordsVec = new Vector<String>();
    for (int i = 0; i < serviceIdentification.getKeywordsArray().length; i++) {
        LanguageStringType[] xb_keywords = serviceIdentification.getKeywordsArray(i).getKeywordArray();
        for (LanguageStringType xb_keyword : xb_keywords) {
            oc_keywordsVec.add(xb_keyword.getStringValue());
        }
    }
    oc_keywords = new String[oc_keywordsVec.size()];
    oc_keywordsVec.toArray(oc_keywords);

    return new ServiceIdentification(oc_title, oc_serviceType, oc_serviceTypeVersions, oc_fees,
            oc_accessConstraints, oc_abstract, oc_keywords);
}

From source file:de.juwimm.cms.components.remote.ComponentsServiceSpringImpl.java

/**
 * @see de.juwimm.cms.components.remote.ComponentsServiceSpring#getUnits4Name(java.lang.String)
 *///  w  ww .j  ava2  s  .co m
@Override
protected UnitValue[] handleGetUnits4Name(String name) throws Exception {
    try {
        Vector<UnitValue> vec = new Vector<UnitValue>();
        UserHbm user = getUserHbmDao().load(AuthenticationHelper.getUserName());
        Iterator it = getUnitHbmDao().findByName(user.getActiveSite().getSiteId(), name).iterator();
        while (it.hasNext()) {
            UnitHbm unit = (UnitHbm) it.next();
            vec.addElement(getUnitHbmDao().getDao(unit));
        }
        return vec.toArray(new UnitValue[0]);
    } catch (Exception e) {
        throw new UserException(e.getMessage());
    }
}

From source file:kenh.xscript.elements.Method.java

/**
 * Process method of {@code Method} element.
 * /*from w  ww.j  a  va2  s . c  o m*/
 * @param name
 * @param parameter
 * @throws UnsupportedScriptException
 */
@Processing
public void process(@Attribute(ATTRIBUTE_NAME) String name, @Primal @Attribute(ATTRIBUTE_PARA) String parameter)
        throws UnsupportedScriptException {
    this.name = name;

    if (StringUtils.isBlank(name)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this, "The method name is empty.");
        throw ex;
    }

    Map<String, Element> methods = this.getEnvironment().getMethods();
    if (methods.containsKey(name)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this,
                "Reduplicate method. [" + name + "]");
        throw ex;
    }

    if (StringUtils.isNotBlank(parameter)) {
        String[] paras = StringUtils.split(parameter, ",");
        Vector<String[]> allParas = new Vector();
        Vector<String> existParas = new Vector(); // exist parameters
        for (String para : paras) {
            if (StringUtils.isBlank(para)) {
                UnsupportedScriptException ex = new UnsupportedScriptException(this,
                        "Parameter format incorrect. [" + name + ", " + parameter + "]");
                throw ex;
            }

            String[] all = StringUtils.split(para, " ");
            String paraName = StringUtils.trimToEmpty(all[all.length - 1]);
            if (StringUtils.isBlank(paraName) || StringUtils.contains(paraName, "{")) {
                UnsupportedScriptException ex = new UnsupportedScriptException(this,
                        "Parameter format incorrect. [" + name + ", " + parameter + "]");
                throw ex;
            }
            if (existParas.contains(paraName)) {
                UnsupportedScriptException ex = new UnsupportedScriptException(this,
                        "Reduplicate parameter. [" + name + ", " + paraName + "]");
                throw ex;
            } else {
                existParas.add(paraName);
            }

            Vector<String> one = new Vector();
            one.add(paraName);
            for (int i = 0; i < all.length - 1; i++) {
                String s = StringUtils.trimToEmpty(all[i]);
                if (StringUtils.isBlank(s))
                    continue;
                if (s.equals(MODI_FINAL) || s.equals(MODI_REQUIRED)
                        || (s.startsWith(MODI_DEFAULT + "(") && s.endsWith(")"))) {
                    one.add(s);
                } else {
                    UnsupportedScriptException ex = new UnsupportedScriptException(this,
                            "Unsupported modifier. [" + name + ", " + paraName + ", " + s + "]");
                    throw ex;
                }
            }

            String[] one_ = one.toArray(new String[] {});
            allParas.add(one_);
        }

        parameters = allParas.toArray(new String[][] {});
    }

    // store into {methods}
    methods.put(name, this);
}

From source file:org.apache.felix.webconsole.internal.compendium.ConfigManager.java

private Object getArray(int type, Vector values) {
    int totalSize = values.size();

    // short cut for string array
    if (type == AttributeDefinition.STRING) {
        return values.toArray(new String[totalSize]);
    }//  www  .j a v a  2s  .  c  o m

    Object tempArray;
    switch (type) {
    case AttributeDefinition.FLOAT:
        tempArray = new float[totalSize];
    case AttributeDefinition.LONG:
        tempArray = new long[totalSize];
    case AttributeDefinition.INTEGER:
        tempArray = new int[totalSize];
    case AttributeDefinition.SHORT:
        tempArray = new short[totalSize];
    case AttributeDefinition.BOOLEAN:
        tempArray = new boolean[totalSize];
    case AttributeDefinition.BYTE:
        tempArray = new byte[totalSize];
    case AttributeDefinition.CHARACTER:
        tempArray = new char[totalSize];
    case AttributeDefinition.DOUBLE:
        tempArray = new double[totalSize];

    default:
        // unexpected, but assume string
        tempArray = new String[totalSize];
    }

    for (int i = 0; i < totalSize; i++) {
        Array.set(tempArray, i, values.get(i));
    }

    return tempArray;
}

From source file:org.apache.juddi.api.impl.UDDICustodyTransferImpl.java

@SuppressWarnings("unchecked")
public void discardTransferToken(DiscardTransferToken body) throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {//w  w  w. j av a2  s .co m
        tx.begin();

        UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());

        new ValidateCustodyTransfer(publisher).validateDiscardTransferToken(em, body);

        org.uddi.custody_v3.TransferToken apiTransferToken = body.getTransferToken();
        if (apiTransferToken != null) {
            String transferTokenId = new String(apiTransferToken.getOpaqueToken());
            org.apache.juddi.model.TransferToken modelTransferToken = em
                    .find(org.apache.juddi.model.TransferToken.class, transferTokenId);
            if (modelTransferToken != null)
                em.remove(modelTransferToken);
        }

        KeyBag keyBag = body.getKeyBag();
        if (keyBag != null) {
            List<String> keyList = keyBag.getKey();
            Vector<DynamicQuery.Parameter> params = new Vector<DynamicQuery.Parameter>(0);
            for (String key : keyList) {
                // Creating parameters for key-checking query
                DynamicQuery.Parameter param = new DynamicQuery.Parameter("UPPER(ttk.entityKey)",
                        key.toUpperCase(), DynamicQuery.PREDICATE_EQUALS);

                params.add(param);
            }

            // Find the associated transfer tokens and remove them.
            DynamicQuery getTokensQry = new DynamicQuery();
            getTokensQry.append("select distinct ttk.transferToken from TransferTokenKey ttk").pad();
            getTokensQry.WHERE().pad().appendGroupedOr(params.toArray(new DynamicQuery.Parameter[0]));

            Query qry = getTokensQry.buildJPAQuery(em);
            List<org.apache.juddi.model.TransferToken> tokensToDelete = qry.getResultList();
            if (tokensToDelete != null && tokensToDelete.size() > 0) {
                for (org.apache.juddi.model.TransferToken tt : tokensToDelete)
                    em.remove(tt);
            }
        }

        tx.commit();
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(CustodyTransferQuery.DISCARD_TRANSFERTOKEN, QueryStatus.SUCCESS, procTime);

    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

From source file:com.w20e.socrates.model.ExpressionCompiler.java

/**
 * Only implemented to return true/false functions.
 * /*from  ww  w  .  j ava 2 s  .co  m*/
 * @param arg0
 *            numeric argument specifying function
 * @param arg1
 *            dunno
 * @return new XBoolean
 */
@Override
public Object function(final int arg0, final Object[] arg1) {

    //System.out.print(arg0);

    if (arg0 == ExpressionCompiler.TRUE) {
        return new XBoolean(true);
    } else if (arg0 == ExpressionCompiler.RND) {
        Round rnd = new Round();
        Vector<Expression> v = new Vector<Expression>();
        if (arg1 != null) {
            for (Object arg : arg1) {
                v.add((Expression) arg);
            }
        }
        rnd.setOperands(v.toArray(new Expression[v.size()]));
        return rnd;
    } else if (arg0 == ExpressionCompiler.FLOOR) {
        Floor floor = new Floor();
        floor.setLeftOperand((Expression) arg1[0]);
        return floor;
    } else if (arg0 == ExpressionCompiler.NOT) {
        Not not = new Not();
        not.setLeftOperand((Expression) arg1[0]);
        return not;
    } else if (arg0 == ExpressionCompiler.SUM) {
        return this.sum(0, arg1);
    } else if (arg0 == Compiler.FUNCTION_STRING) {
        // only with mandatory parameter is implemented!
        return new XVar(arg1[0].toString()); // throws exception if args1
        // == null
    } else {
        return new XBoolean(false);
    }
}

From source file:nz.co.fortytwo.freeboard.installer.InstalManager.java

public InstalManager(String name) {
    super(name);/*w  w w .j  a  va 2  s  .co  m*/

    String[] devices = new String[] { "ArduIMU v3", "Arduino Mega 1280", "Arduino Mega 2560" };
    deviceMap.put(devices[0], "atmega328p");
    deviceMap.put(devices[1], "atmega1280");
    deviceMap.put(devices[2], "atmega2560");
    deviceComboBox = new JComboBox<String>(devices);

    //toolsDir = new File("./src/main/resources/tools");
    //if (!toolsDir.exists()) {
    //   System.out.println("Cannot locate avrdude");
    //}
    @SuppressWarnings("unchecked")
    Enumeration<CommPortIdentifier> commPorts = CommPortIdentifier.getPortIdentifiers();
    Vector<String> commModel = new Vector<String>();
    while (commPorts.hasMoreElements()) {
        CommPortIdentifier commPort = commPorts.nextElement();
        if (commPort.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            //?if(SystemUtils.IS_LINUX())
            if (commPort.getName().startsWith("tty")) {
                // linux
                commModel.add("/dev/" + commPort.getName());
            } else {
                // windoze
                commModel.add(commPort.getName());
            }
        }
    }
    portComboBox = new JComboBox<String>(commModel.toArray(new String[0]));
    portComboBox1 = new JComboBox<String>(commModel.toArray(new String[0]));

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.addWidgets();
    this.pack();
    this.setVisible(true);
    JOptionPane.showMessageDialog(this,
            "This utility is quite experimental, specifically I develop on Linux, and I dont have MS Windows \nto test on, so dont be surprised by errors!\n"
                    + "If you have problems, copy the output from the right side panel, along with a clear description \nof what you were doing, and email me at robert@42.co.nz"
                    + " so I can recreate and fix the error."
                    + "\n\nCopyright 2013 R T Huitema. Licenced under GNU GPL v3");
}

From source file:org.kchine.rpf.PoolUtils.java

public static URL[] getURLS(String urlsStr) {
    StringTokenizer st = new StringTokenizer(urlsStr, " ");
    Vector<URL> result = new Vector<URL>();
    while (st.hasMoreElements()) {
        try {//from   w w  w  .  j a  v a2s  . c  om
            result.add(new URL((String) st.nextElement()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return (URL[]) result.toArray(new URL[0]);
}

From source file:org.accada.hal.impl.sim.SimulatorController.java

public Observation[] identify(String[] readPointNames) throws HardwareException {
    // Each read point gets its own Observation
    Observation[] observations = new Observation[readPointNames.length];

    for (int i = 0; i < readPointNames.length; i++) {

        observations[i] = new Observation();
        observations[i].setHalName(this.halName);
        observations[i].setReadPointName(readPointNames[i]);

        //Get the tag IDs on this antenna
        Vector<String> v = new Vector<String>();
        Iterator it = ((HashSet) reader.get(readPointNames[i])).iterator();
        while (it.hasNext()) {
            Tag t = (Tag) it.next();/*  w  ww  .  j av  a  2s.c  o  m*/
            v.add(t.getTagID());
        }

        int len = v.size();
        String v_arr[] = new String[len];
        v_arr = v.toArray(v_arr);
        TagDescriptor[] td_arr = new TagDescriptor[v_arr.length];
        String idTConf;
        try {
            idTConf = props.getParameter("idTypesConfig");
        } catch (Exception e) {
            idTConf = null;
        }
        for (int j = 0; j < td_arr.length; j++) {
            IDType idType = IDType.getIdType("EPC", idTConf);
            byte[] accada_sim_tid_bytes = ByteBlock.hexStringToByteArray("E2FFF000");
            EPCTransponderModel tagModel = EPCTransponderModel.getEpcTrasponderModel(accada_sim_tid_bytes,
                    epcTransponderModelsConfig);
            MemoryBankDescriptor[] memoryBankDescriptors = new MemoryBankDescriptor[4];
            memoryBankDescriptors[0] = new MemoryBankDescriptor(tagModel.getReservedSize(),
                    tagModel.getReservedReadable(), tagModel.getReservedWriteable());
            memoryBankDescriptors[1] = new MemoryBankDescriptor(tagModel.getEpcSize(),
                    tagModel.getEpcReadable(), tagModel.getEpcWriteable());
            memoryBankDescriptors[2] = new MemoryBankDescriptor(tagModel.getTidSize(),
                    tagModel.getTidReadable(), tagModel.getTidWriteable());
            memoryBankDescriptors[3] = new MemoryBankDescriptor(tagModel.getUserSize(),
                    tagModel.getUserReadable(), tagModel.getUserWriteable());
            MemoryDescriptor memoryDescriptor = new MemoryDescriptor(memoryBankDescriptors);
            td_arr[j] = new TagDescriptor(idType, memoryDescriptor);
        }
        observations[i].setTagDescriptors(td_arr);
        observations[i].setIds(v_arr);
        observations[i].setTimestamp(System.currentTimeMillis());

        if (!readyReadPoints.contains(readPointNames[i])) {
            log.error("Read point \"" + readPointNames[i] + "\" is not ready.");
            observations[i].setIds(new String[0]);
            observations[i].setTagDescriptors(new TagDescriptor[0]);
            observations[i].successful = false;
        } else if (continuousIdentifyErrors.contains(readPointNames[i])) {
            observations[i].successful = false;
        } else if (identifyError.contains(readPointNames[i])) {
            observations[i].successful = false;
            identifyError.remove(readPointNames[i]);
        } else {
            observations[i].successful = true;
        }

        log.debug(observations[i].toString());
    }
    return observations;
}

From source file:org.fosstrak.hal.impl.sim.SimulatorController.java

public Observation[] identify(String[] readPointNames) throws HardwareException {
    // Each read point gets its own Observation
    Observation[] observations = new Observation[readPointNames.length];

    for (int i = 0; i < readPointNames.length; i++) {

        observations[i] = new Observation();
        observations[i].setHalName(this.halName);
        observations[i].setReadPointName(readPointNames[i]);

        //Get the tag IDs on this antenna
        Vector<String> v = new Vector<String>();
        Iterator it = ((HashSet) reader.get(readPointNames[i])).iterator();
        while (it.hasNext()) {
            Tag t = (Tag) it.next();//w w  w.  j a  va 2s  .com
            v.add(t.getTagID());
        }

        int len = v.size();
        String v_arr[] = new String[len];
        v_arr = v.toArray(v_arr);
        TagDescriptor[] td_arr = new TagDescriptor[v_arr.length];
        String idTConf;
        try {
            idTConf = props.getParameter("idTypesConfig");
        } catch (Exception e) {
            idTConf = null;
        }
        for (int j = 0; j < td_arr.length; j++) {
            IDType idType = IDType.getIdType("EPC", idTConf);
            byte[] fosstrak_sim_tid_bytes = ByteBlock.hexStringToByteArray("E2FFF000");
            EPCTransponderModel tagModel = EPCTransponderModel.getEpcTrasponderModel(fosstrak_sim_tid_bytes,
                    epcTransponderModelsConfig);
            MemoryBankDescriptor[] memoryBankDescriptors = new MemoryBankDescriptor[4];
            memoryBankDescriptors[0] = new MemoryBankDescriptor(tagModel.getReservedSize(),
                    tagModel.getReservedReadable(), tagModel.getReservedWriteable());
            memoryBankDescriptors[1] = new MemoryBankDescriptor(tagModel.getEpcSize(),
                    tagModel.getEpcReadable(), tagModel.getEpcWriteable());
            memoryBankDescriptors[2] = new MemoryBankDescriptor(tagModel.getTidSize(),
                    tagModel.getTidReadable(), tagModel.getTidWriteable());
            memoryBankDescriptors[3] = new MemoryBankDescriptor(tagModel.getUserSize(),
                    tagModel.getUserReadable(), tagModel.getUserWriteable());
            MemoryDescriptor memoryDescriptor = new MemoryDescriptor(memoryBankDescriptors);
            td_arr[j] = new TagDescriptor(idType, memoryDescriptor);
        }
        observations[i].setTagDescriptors(td_arr);
        observations[i].setIds(v_arr);
        observations[i].setTimestamp(System.currentTimeMillis());

        if (!readyReadPoints.contains(readPointNames[i])) {
            log.error("Read point \"" + readPointNames[i] + "\" is not ready.");
            observations[i].setIds(new String[0]);
            observations[i].setTagDescriptors(new TagDescriptor[0]);
            observations[i].successful = false;
        } else if (continuousIdentifyErrors.contains(readPointNames[i])) {
            observations[i].successful = false;
        } else if (identifyError.contains(readPointNames[i])) {
            observations[i].successful = false;
            identifyError.remove(readPointNames[i]);
        } else {
            observations[i].successful = true;
        }

        log.debug(observations[i].toString());
    }
    return observations;
}