Example usage for java.util Vector get

List of usage examples for java.util Vector get

Introduction

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

Prototype

public synchronized E get(int index) 

Source Link

Document

Returns the element at the specified position in this Vector.

Usage

From source file:edu.ku.brc.specify.tasks.services.PickListUtils.java

/**
 * @param pl/* w  w w .j  av  a2 s  .  c  om*/
 * @param bpl
 * @return
 */
private static boolean pickListsEqual(final PickList pl, final BldrPickList bpl) {
    if (!StringUtils.equals(pl.getName(), bpl.getName()))
        return false;
    if (!StringUtils.equals(pl.getTableName(), bpl.getTableName()))
        return false;
    if (!StringUtils.equals(pl.getFieldName(), bpl.getFieldName()))
        return false;
    if (!StringUtils.equals(pl.getFormatter(), bpl.getFormatter()))
        return false;

    if (!equals(pl.getType(), bpl.getType()))
        return false;
    if (!equals(pl.getReadOnly(), bpl.getReadOnly()))
        return false;
    if (!equals(pl.getSizeLimit(), bpl.getSizeLimit()))
        return false;
    if (!equals(pl.getIsSystem(), bpl.getIsSystem()))
        return false;
    if (!equals(pl.getSortType(), bpl.getSortType()))
        return false;

    Vector<PickListItem> plis = new Vector<PickListItem>(pl.getPickListItems());
    Vector<BldrPickListItem> bplis = bpl.getItems();

    if ((plis.size() == 0) && (bplis == null || bplis.size() == 0))
        return true;

    if (plis.size() != bplis.size())
        return false;

    if (pl.getSortType() == PickListIFace.PL_ORDINAL_SORT) {
        Collections.sort(plis, pliComparatorOrd);
        Collections.sort(bplis);
    } else {
        Collections.sort(plis, pliComparatorTitle);
        Collections.sort(bplis, bldrPliComparatorTitle);
    }

    for (int i = 0; i < plis.size(); i++) {
        PickListItem pli = plis.get(i);
        BldrPickListItem bpli = bplis.get(i);
        //System.out.println("["+pli.getOrdinal()+"]["+bpli.getOrdinal()+"]["+pli.getTitle()+"]["+bpli.getTitle()+"]["+pli.getValue()+"]["+bpli.getValue()+"]");
        if (!StringUtils.equals(pli.getTitle(), bpli.getTitle()))
            return false;
        if (!StringUtils.equals(pli.getValue(), bpli.getValue()))
            return false;
    }

    return true;
}

From source file:org.esupportail.papercut.domain.UserPapercutInfos.java

public UserPapercutInfos(String uid, Vector<String> propertyValues) {
    this.uid = uid;
    this.fullName = propertyValues.get(0);
    this.balance = fixRoundPapercutError(propertyValues.get(1));
    this.email = propertyValues.get(2);
    this.department = propertyValues.get(3);
    this.office = propertyValues.get(4);
    this.cardNumber = propertyValues.get(5);
    this.printJobs = propertyValues.get(6);
    this.printPages = propertyValues.get(7);
    this.printDisabled = "true".equals(propertyValues.get(8));
    this.restricted = "true".equals(propertyValues.get(9));
    this.notes = propertyValues.get(10);
}

From source file:de.betterform.connector.xmlrpc.XMLRPCURIResolver.java

/**
 * Decodes the <code>xmlrpc</code> URI, runs the indicated function
 * and returns the result as a DOM document.
 *
 * @return a DOM node parsed from the <code>xmlrpc</code> URI.
 * @throws XFormsException if any error occurred.
 *///ww  w.  j  av  a 2 s .co m
public Object resolve() throws XFormsException {
    try {

        URI uri = new URI(getURI());
        log.info("Getting URI: '" + uri + "'");

        Vector v = parseURI(uri);
        String rpcURL = (String) v.get(0);
        String function = (String) v.get(1);
        Hashtable params = (Hashtable) v.get(2);

        de.betterform.connector.xmlrpc.RPCClient rpc = new de.betterform.connector.xmlrpc.RPCClient(rpcURL);

        Document document = rpc.getDocument(function, params);

        if (uri.getFragment() != null) {
            return document.getElementById(uri.getFragment());
        }

        return document;
    } catch (Exception e) {
        throw new XFormsException(e);
    }
}

From source file:info.novatec.testit.livingdoc.util.CollectionUtilTest.java

@Test
@SuppressWarnings("unchecked")
public void testCanConvertArraysToVectors() {
    Vector<? extends Object> vec = CollectionUtil.toVector("1", null, new Date());
    assertEquals(3, vec.size());//from   w ww. j av a 2 s. c  o m
    assertTrue(vec.get(0) instanceof String);
    assertTrue(vec.get(1) == null);
    assertTrue(vec.get(2) instanceof Date);
}

From source file:nl.knmi.adaguc.services.oauth2.OAuth2Handler.java

/**
 * Returns unique user identifier from id_token (JWTPayload). The JWT token
 * is *NOT* verified. Several impact portal session attributes are set: -
 * user_identifier - emailaddress/*  w  w w .ja  v a 2  s . c o m*/
 * 
 * @param request
 * @param JWT
 * @return
 * @throws ElementNotFoundException
 */
private static UserInfo getIdentifierFromJWTPayload(String JWT) throws ElementNotFoundException {
    JSONObject id_token_json = null;
    try {
        id_token_json = (JSONObject) new JSONTokener(JWT).nextValue();
    } catch (JSONException e1) {
        Debug.errprintln("Unable to convert JWT Token to JSON");
        return null;
    }

    String email = "null";
    String userSubject = null;
    String aud = "";
    try {
        email = id_token_json.get("email").toString();
    } catch (JSONException e) {
    }
    try {
        userSubject = id_token_json.get("sub").toString();
    } catch (JSONException e) {
    }

    try {
        aud = id_token_json.get("aud").toString();
    } catch (JSONException e) {
    }

    if (aud == null) {
        Debug.errprintln("Error: aud == null");
        return null;
    }
    if (userSubject == null) {
        Debug.errprintln("Error: userSubject == null");
        return null;
    }

    // Get ID based on aud (client id)
    String clientId = null;

    Vector<String> providernames = OAuthConfigurator.getProviders();

    for (int j = 0; j < providernames.size(); j++) {
        OAuthConfigurator.Oauth2Settings settings = OAuthConfigurator.getOAuthSettings(providernames.get(j));
        if (settings.OAuthClientId.equals(aud)) {
            clientId = settings.id;
        }
    }

    if (clientId == null) {
        Debug.errprintln("Error: could not match OAuthClientId to aud");
        return null;

    }

    String user_identifier = clientId + "/" + userSubject;
    String user_openid = null;
    UserInfo userInfo = new UserInfo();
    userInfo.user_identifier = user_identifier;
    userInfo.user_openid = user_openid;
    userInfo.user_email = email;

    Debug.println("getIdentifierFromJWTPayload (id_token): Found unique ID " + user_identifier);

    return userInfo;

}

From source file:nl.knmi.adaguc.services.oauth2.OAuth2Handler.java

/**
 * Makes a JSON object and sends it to response with information needed for
 * building the OAuth2 login form./*from   www .  ja v a2s  .co  m*/
 * 
 * @param request
 * @param response
 * @throws ElementNotFoundException
 */
private static void makeForm(HttpServletRequest request, HttpServletResponse response)
        throws ElementNotFoundException {
    JSONResponse jsonResponse = new JSONResponse(request);

    JSONObject form = new JSONObject();
    try {

        JSONArray providers = new JSONArray();
        form.put("providers", providers);
        Vector<String> providernames = OAuthConfigurator.getProviders();

        for (int j = 0; j < providernames.size(); j++) {
            OAuthConfigurator.Oauth2Settings settings = OAuthConfigurator
                    .getOAuthSettings(providernames.get(j));
            JSONObject provider = new JSONObject();
            provider.put("id", providernames.get(j));
            provider.put("description", settings.description);
            provider.put("logo", settings.logo);
            provider.put("registerlink", settings.registerlink);
            providers.put(provider);

        }
    } catch (JSONException e) {
    }
    jsonResponse.setMessage(form);

    try {
        jsonResponse.print(response);
    } catch (Exception e1) {

    }

}

From source file:de.betterform.connector.xmlrpc.XMLRPCSubmissionHandler.java

/**
 * Serializes and submits the given instance data to an xmlrpc function protocol.
 *
 * @param submission the submission issuing the request.
 * @param instance   the instance data to be serialized and submitted.
 * @return <code>null</code>.
 * @throws XFormsException if any error occurred during submission.
 */// www. ja va  2  s . co m
public Map submit(Submission submission, Node instance) throws XFormsException {

    if (!submission.getReplace().equals("none")) {
        throw new XFormsException("submission mode '" + submission.getReplace() + "' not supported");
    }

    try {
        SerializerRequestWrapper wrapper = new SerializerRequestWrapper(new ByteArrayOutputStream());
        serialize(submission, instance, wrapper);
        ByteArrayOutputStream stream = (ByteArrayOutputStream) wrapper.getBodyStream();

        URI uri = new URI(getURI());
        log.info("Getting URI: '" + uri + "'");

        Vector v = parseURI(uri);
        String rpcURL = (String) v.get(0);
        String function = (String) v.get(1);
        Hashtable params = (Hashtable) v.get(2);

        params.put("doc", stream.toByteArray());

        de.betterform.connector.xmlrpc.RPCClient rpc = new de.betterform.connector.xmlrpc.RPCClient(rpcURL);

        Hashtable result = rpc.runFunc(function, params);

        if (((String) result.get("status")).equals("error")) {
            throw new XFormsException((String) result.get("error"));
        }
    } catch (Exception e) {
        throw new XFormsException(e);
    }
    return null;
}

From source file:edu.stanford.cfuller.imageanalysistools.clustering.ObjectClustering.java

/**
 * Sets up a set of ClusterObjects and a set of Clusters from an Image mask with each object labeled with a unique greylevel.
 *
 * @param im                The Image mask with each cluster object labeled with a unique greylevel.  These must start at 1 and be consecutive.
 * @param clusterObjects    A Vector of ClusterObjects that will contain the initialized ClusterObjects on return; this may be empty, and any contents will be erased.
 * @param clusters          A Vector of Clusters that will contain the initialized Clusters on return; this may be empty, and any contents will be erased.
 * @param k                 The number of Clusters to generate.
 * @return                  The number of ClusterObjects in the Image.
 *//*from www  .ja v a 2 s.  c o m*/
public static int initializeObjectsAndClustersFromImage(Image im, Vector<ClusterObject> clusterObjects,
        Vector<Cluster> clusters, int k) {

    int n = 0;

    clusters.clear();

    for (int j = 0; j < k; j++) {

        clusters.add(new Cluster());
        clusters.get(j).setID(j + 1);

    }

    Histogram h = new Histogram(im);

    n = h.getMaxValue();

    clusterObjects.clear();

    for (int j = 0; j < n; j++) {

        clusterObjects.add(new ClusterObject());

        clusterObjects.get(j).setCentroidComponents(0, 0, 0);

        clusterObjects.get(j).setnPixels(0);

    }

    for (ImageCoordinate i : im) {

        if (im.getValue(i) > 0) {

            ClusterObject current = clusterObjects.get((int) im.getValue(i) - 1);

            current.incrementnPixels();

            current.setCentroid(current.getCentroid().add(new Vector3D(i.get(ImageCoordinate.X),
                    i.get(ImageCoordinate.Y), i.get(ImageCoordinate.Z))));

        }

    }

    for (int j = 0; j < n; j++) {
        ClusterObject current = clusterObjects.get(j);
        current.setCentroid(current.getCentroid().scalarMultiply(1.0 / current.getnPixels()));
    }

    //initialize clusters using kmeans++ strategy

    double[] probs = new double[n];
    double[] cumulativeProbs = new double[n];

    java.util.Arrays.fill(probs, 0);
    java.util.Arrays.fill(cumulativeProbs, 0);

    //choose the initial cluster

    int initialClusterObject = (int) Math.floor(n * RandomGenerator.rand());

    clusters.get(0).setCentroid(clusterObjects.get(initialClusterObject).getCentroid());

    clusters.get(0).getObjectSet().add(clusterObjects.get(initialClusterObject));

    for (int j = 0; j < n; j++) {

        clusterObjects.get(j).setCurrentCluster(clusters.get(0));
    }

    //assign the remainder of the clusters

    for (int j = 1; j < k; j++) {

        double probSum = 0;

        for (int m = 0; m < n; m++) {
            double minDist = Double.MAX_VALUE;

            Cluster bestCluster = null;

            for (int p = 0; p < j; p++) {

                double tempDist = clusterObjects.get(m).distanceTo(clusters.get(p));

                if (tempDist < minDist) {
                    minDist = tempDist;

                    bestCluster = clusters.get(p);
                }

            }

            probs[m] = minDist;
            probSum += minDist;

            clusterObjects.get(m).setCurrentCluster(bestCluster);
        }

        for (int m = 0; m < n; m++) {
            probs[m] = probs[m] / probSum;
            if (m == 0) {
                cumulativeProbs[m] = probs[m];
            } else {
                cumulativeProbs[m] = cumulativeProbs[m - 1] + probs[m];
            }
        }
        double randNum = RandomGenerator.rand();
        int nextCenter = 0;

        for (int m = 0; m < n; m++) {
            if (randNum < cumulativeProbs[m]) {
                nextCenter = m;
                break;
            }
        }

        clusters.get(j).setCentroid(clusterObjects.get(nextCenter).getCentroid());

    }

    for (int m = 0; m < n; m++) {

        double minDist = Double.MAX_VALUE;

        Cluster bestCluster = null;

        for (int p = 0; p < k; p++) {

            double tempDist = clusterObjects.get(m).distanceTo(clusters.get(p));

            if (tempDist < minDist) {

                minDist = tempDist;
                bestCluster = clusters.get(p);
            }
        }

        clusterObjects.get(m).setCurrentCluster(bestCluster);
        bestCluster.getObjectSet().add(clusterObjects.get(m));

    }

    return n;
}

From source file:eionet.gdem.web.struts.hosts.HostDetailsAction.java

@Override
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse httpServletResponse) {
    ActionMessages errors = new ActionMessages();
    DynaValidatorForm hostForm = (DynaValidatorForm) actionForm;
    String hostId = (String) hostForm.get("id");

    try {//from   w ww  . ja  v a 2 s. c  o m
        if (checkPermission(request, Names.ACL_HOST_PATH, "u")) {
            Vector hosts = hostDao.getHosts(hostId);

            if (hosts != null) {
                Hashtable host = (Hashtable) hosts.get(0);
                hostForm.set("id", host.get("host_id"));
                hostForm.set("host", host.get("host_name"));
                hostForm.set("username", host.get("user_name"));
                hostForm.set("password", host.get("pwd"));
            }
        } else {
            errors.add(ActionMessages.GLOBAL_MESSAGE,
                    new ActionMessage("error.unoperm", translate(actionMapping, request, "label.hosts")));
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("label.exception.unknown"));
    }

    if (errors.size() > 0) {
        // request.getSession().setAttribute("dcm.errors", errors);
        saveErrors(request, errors);
        return actionMapping.getInputForward();
    }
    return actionMapping.findForward("success");
}

From source file:net.sf.jdmf.visualization.clustering.ChartGenerator.java

public JFreeChart generateXYChart(List<Cluster> clusters, Integer firstAttributeIndex,
        String firstAttributeName, Integer secondAttributeIndex, String secondAttributeName) {
    XYSeriesCollection dataset = new XYSeriesCollection();

    for (Cluster cluster : clusters) {
        XYSeries series = new XYSeries(cluster.getName());

        for (Vector<Double> point : cluster.getPoints()) {
            series.add(point.get(firstAttributeIndex), point.get(secondAttributeIndex));
        }//from   ww  w  .j  a v a  2 s.c o m

        dataset.addSeries(series);
    }

    XYToolTipGenerator xyToolTipGenerator = new XYToolTipGenerator() {
        public String generateToolTip(XYDataset dataset, int series, int item) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(String.format("<html><p style='color:#0000ff;'>Series: '%s'</p>",
                    dataset.getSeriesKey(series)));
            Cluster cl = clusters.get(series);
            Vector<Double> point = cl.getPoints().get(item);
            for (int i = 0; i < point.size(); i++) {
                //stringBuilder.append(String.format("Attr:'%d'<br/>", d));
                try {
                    String attr = _attrName.get(i);
                    stringBuilder.append(attr + " " + point.get(i) + "<br/>");
                } catch (Exception e) {
                    // Do nothing 
                }
            }
            stringBuilder.append("</html>");
            return stringBuilder.toString();
        }
    };

    /***
    return ChartFactory.createScatterPlot( "Cluster Analysis", 
    firstAttributeName, secondAttributeName, dataset, 
    PlotOrientation.VERTICAL, true, true, false );
    ***/
    JFreeChart jfc = ChartFactory.createScatterPlot("Cluster Analysis", firstAttributeName, secondAttributeName,
            dataset, PlotOrientation.VERTICAL, true, true, false);

    XYItemRenderer render = jfc.getXYPlot().getRenderer();
    render.setBaseToolTipGenerator(xyToolTipGenerator);
    return jfc;
}