Example usage for java.util Vector clear

List of usage examples for java.util Vector clear

Introduction

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

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this Vector.

Usage

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

/**
 * Sets up a set of ClusterObjects and a set of Clusters from two Image masks, one labeled with individual objects, and one labeled with all objects in a single cluster grouped with a single label.
 *
 * @param labeledByObject       An Image mask with all objects in the Image labeled with an unique greylevel value.  These labels must start with 1 and be consecutive.
 * @param labeledByCluster      An Image mask with all the objects in each cluster labeled with the same unique greylevel value.  These labels must start with 1 and be consecutive.
 * @param clusterObjects        A Vector of ClusterObjects that will contain the initialized ClusterObjects on return; this can be empty, and any contents will be erased.
 * @param clusters              A Vector of Clusters that will contain the initialized Clusters on return; this can be empty, and any contents will be erased.
 * @param k                     The number of clusters in the Image.  This must be the same as the number of unique nonzero greylevels in the labeledByCluster Image.
 * @return                      The number of ClusterObjects in the Image.
 *///from  w  w w. j  a  v a  2s .  c om
public static int initializeObjectsAndClustersFromClusterImage(Image labeledByObject, Image labeledByCluster,
        Vector<ClusterObject> clusterObjects, Vector<Cluster> clusters, int k) {

    clusters.clear();

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

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

    }

    Histogram h = new Histogram(labeledByObject);

    int 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 : labeledByObject) {

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

            int value = (int) (labeledByObject.getValue(i));

            clusterObjects.get(value - 1).incrementnPixels();
            clusterObjects.get(value - 1).setCentroid(
                    clusterObjects.get(value - 1).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()));
    }

    for (ImageCoordinate i : labeledByObject) {

        int clusterValue = (int) labeledByCluster.getValue(i);
        int objectValue = (int) labeledByObject.getValue(i);
        if (clusterValue == 0 || objectValue == 0) {
            continue;
        }

        clusters.get(clusterValue - 1).getObjectSet().add(clusterObjects.get(objectValue - 1));

    }

    for (Cluster c : clusters) {

        int objectCounter = 0;

        c.setCentroidComponents(0, 0, 0);

        for (ClusterObject co : c.getObjectSet()) {

            objectCounter++;
            co.setCurrentCluster(c);

            c.setCentroid(c.getCentroid().add(co.getCentroid()));

        }

        c.setCentroid(c.getCentroid().scalarMultiply(1.0 / objectCounter));

    }

    return n;

}

From source file:org.apache.axis.utils.BeanUtils.java

/**
 * Return a list of properties in the bean which should be attributes
 *///from www  .  ja  v  a2  s .  c  om
public static Vector getBeanAttributes(Class javaType, TypeDesc typeDesc) {
    Vector ret = new Vector();

    if (typeDesc == null) {
        // !!! Support old-style beanAttributeNames for now

        // See if this object defined the 'getAttributeElements' function
        // which returns a Vector of property names that are attributes
        try {
            Method getAttributeElements = javaType.getMethod("getAttributeElements", new Class[] {});
            // get string array
            String[] array = (String[]) getAttributeElements.invoke(null, noArgs);

            // convert it to a Vector
            ret = new Vector(array.length);
            for (int i = 0; i < array.length; i++) {
                ret.add(array[i]);
            }
        } catch (Exception e) {
            ret.clear();
        }
    } else {
        FieldDesc[] fields = typeDesc.getFields();
        if (fields != null) {
            for (int i = 0; i < fields.length; i++) {
                FieldDesc field = fields[i];
                if (!field.isElement()) {
                    ret.add(field.getFieldName());
                }
            }
        }
    }

    return ret;
}

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.
 */// ww  w .  j  a v a2s.  c  om
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:org.sakaiproject.content.tool.AttachmentAction.java

/**
 * Handle the eventSubmit_doRemove command to remove the selected attachment(s).
 *//*from  w w w. j a v  a 2s  . c  o  m*/
static public void doRemove(RunData data) {
    if (!"POST".equals(data.getRequest().getMethod())) {
        return;
    }

    SessionState state = ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    // modify the attachments vector
    Vector attachments = (Vector) state.getAttribute(STATE_ATTACHMENTS);

    // read the form to figure out which attachment(s) to remove.
    String[] selected = data.getParameters().getStrings("select");

    // if nothing selected, and there's just one attachment, remove it
    if (selected == null) {
        if (attachments.size() == 1) {
            attachments.clear();
        } else {
            // leave a message
            state.setAttribute(VelocityPortletPaneledAction.STATE_MESSAGE, rb.getString("alert"));
        }
    }

    else {
        // run through these 1 based indexes backwards, so we can remove each without invalidating the rest
        // ASSUME: they are in ascending order
        for (int i = selected.length - 1; i >= 0; i--) {
            try {
                int index = Integer.parseInt(selected[i]) - 1;
                attachments.removeElementAt(index);
            } catch (Exception e) {
                M_log.warn(
                        "AttachmentAction" + ".doRemove(): processing selected [" + i + "] : " + e.toString());
            }
        }
    }

    // end up in main mode
    state.setAttribute(STATE_MODE, MODE_MAIN);

}

From source file:org.openmrs.web.dwr.DWRProviderService.java

/**
 * Finds providers for the given name along with the total count of providers that matched.
 * //w  ww .  j ava 2 s.co m
 * @param name to search
 * @param includeRetired true/false whether or not to included retired providers
 * @param start starting index for the results to return
 * @param length the number of results to return
 * @return a list of matching providers
 * @throws APIException on any errors while searching providers
 * @should return the count of all providers matching the searched name along with provider list
 *         for given length
 */
public Map<String, Object> findProviderCountAndProvider(String name, boolean includeRetired, Integer start,
        Integer length) throws APIException {
    Map<String, Object> providerMap = new HashMap<String, Object>();
    Vector<Object> objectList = findProvider(name, includeRetired, start, length);
    try {
        providerMap.put("count", Context.getProviderService().getCountOfProviders(name, includeRetired));
        providerMap.put("objectList", objectList);
    } catch (Exception e) {
        log.error("Error while searching for providers", e);
        objectList.clear();
        objectList.add(
                Context.getMessageSourceService().getMessage("Provider.search.error") + " - " + e.getMessage());
        providerMap.put("count", 0);
        providerMap.put("objectList", objectList);
    }
    return providerMap;
}

From source file:com.bailen.radioOnline.recursos.REJA.java

public Cancion[] getRatings(String apiKey) throws IOException {
    HttpHeaders header = new HttpHeaders();
    header.set("Authorization", apiKey);
    HttpEntity entity = new HttpEntity(header);
    String lista = new String();
    HttpEntity<String> response;
    response = new RestTemplate().exchange("http://ceatic.ujaen.es:8075/radioapi/v2/ratings", HttpMethod.GET,
            entity, String.class, lista);

    String canc = response.getBody();
    StringTokenizer st = new StringTokenizer(canc, "[", true);
    st.nextToken();//ww w.j  a va  2s.  c o  m
    if (!st.hasMoreTokens()) {
        return null;
    }
    st.nextToken();
    canc = "[" + st.nextToken();

    try {

        ObjectMapper a = new ObjectMapper();
        ItemPuntu[] listilla = a.readValue(canc, ItemPuntu[].class);
        Vector<Integer> ids = new Vector<>();
        Vector<Cancion> punt = new Vector<>();
        //como jamendo solo devuelve 10 canciones llamamos las veces necesarias
        for (int i = 0; i < (listilla.length / 10) + 1; ++i) {
            ids.clear();
            //aunque le mandemos mas ids de la cuenta solo devolvera las 10 primeras canciones y 
            //de esta forma controlamos el desborde
            for (int j = i * 10; j < listilla.length; ++j) {
                ids.add(listilla[j].getId());
            }
            Cancion[] listilla1 = jamendo.canciones(ids);
            for (int k = 0; k < listilla1.length; ++k) {
                punt.add(listilla1[k]);
            }
        }

        for (int i = 0; i < punt.size(); ++i) {
            punt.get(i).setRating(listilla[i].getRating());
            punt.get(i).setFav(listilla[i].getFav());
        }

        return punt.toArray(new Cancion[punt.size()]);

    } catch (Exception e) {
        //return null;
        throw new IOException("no se han recibido canciones");
    }

}

From source file:net.sf.l2j.gameserver.model.entity.L2JOneoRusEvents.TvT.java

private static boolean startEventOk() {
    if (_joining || !_teleport || _started)
        return false;
    if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE")) {
        if (_teamPlayersCount.contains(0))
            return false;
    } else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE")) {
        Vector<L2PcInstance> playersShuffleTemp = new Vector<L2PcInstance>();
        int loopCount = 0;
        loopCount = _playersShuffle.size();
        for (int i = 0; i < loopCount; i++) {
            if (_playersShuffle != null)
                playersShuffleTemp.add(_playersShuffle.get(i));
        }/*from  w  w w.j  av a2  s  . co m*/
        _playersShuffle = playersShuffleTemp;
        playersShuffleTemp.clear();
        // if (_playersShuffle.size() < (_teams.size()*2)){
        // return false;
        // }
    }
    return true;
}

From source file:net.sf.ginp.TestGinpModel.java

public void test_command_SetLanguageCode() {
    SetLanguageCode comm = new SetLanguageCode();
    Vector para = new Vector();

    para.add(new CommandParameter("code", "de_AT"));

    comm.action(model, para);/*from   w  w w  . ja  v  a 2s  .com*/
    assertEquals("Foo Bar de_AT", model.translate("testMessage"));

    para.clear();
    para.add(new CommandParameter("code", "de_FR"));
    comm.action(model, para);
    assertEquals("Foo Bar de", model.translate("testMessage"));
}

From source file:edu.stanford.cfuller.imageanalysistools.filter.ConvexHullByLabelFilter.java

/**
 * Applies the convex hull filter to the supplied mask.
 * @param im    The Image to process-- a mask whose regions will be replaced by their filled convex hulls.
 *///w w  w  .j a v a2 s. c  o m
@Override
public void apply(WritableImage im) {

    RelabelFilter RLF = new RelabelFilter();

    RLF.apply(im);

    Histogram h = new Histogram(im);

    java.util.Hashtable<Integer, java.util.Vector<Integer>> xLists = new java.util.Hashtable<Integer, java.util.Vector<Integer>>();
    java.util.Hashtable<Integer, java.util.Vector<Integer>> yLists = new java.util.Hashtable<Integer, java.util.Vector<Integer>>();

    java.util.Vector<Integer> minValues = new java.util.Vector<Integer>(h.getMaxValue() + 1);
    java.util.Vector<Integer> minIndices = new java.util.Vector<Integer>(h.getMaxValue() + 1);

    for (int i = 0; i < h.getMaxValue() + 1; i++) {
        minValues.add(im.getDimensionSizes().get(ImageCoordinate.X));
        minIndices.add(0);
    }

    for (ImageCoordinate i : im) {

        int value = (int) im.getValue(i);

        if (value == 0)
            continue;

        if (!xLists.containsKey(value)) {
            xLists.put(value, new java.util.Vector<Integer>());
            yLists.put(value, new java.util.Vector<Integer>());
        }

        xLists.get(value).add(i.get(ImageCoordinate.X));
        yLists.get(value).add(i.get(ImageCoordinate.Y));

        if (i.get(ImageCoordinate.X) < minValues.get(value)) {
            minValues.set(value, i.get(ImageCoordinate.X));
            minIndices.set(value, xLists.get(value).size() - 1);
        }

    }

    java.util.Vector<Integer> hullPointsX = new java.util.Vector<Integer>();
    java.util.Vector<Integer> hullPointsY = new java.util.Vector<Integer>();

    ImageCoordinate ic = ImageCoordinate.createCoordXYZCT(0, 0, 0, 0, 0);

    for (int k = 1; k < h.getMaxValue() + 1; k++) {
        hullPointsX.clear();
        hullPointsY.clear();

        java.util.Vector<Integer> xList = xLists.get(k);
        java.util.Vector<Integer> yList = yLists.get(k);

        int minIndex = (int) minIndices.get(k);

        //start at the leftmost point

        int currentIndex = minIndex;
        int currentX = xList.get(currentIndex);
        int currentY = yList.get(currentIndex);

        hullPointsX.add(currentX);
        hullPointsY.add(currentY);

        org.apache.commons.math3.linear.RealVector angles = new org.apache.commons.math3.linear.ArrayRealVector(
                xList.size());

        Vector3D currentVector = new Vector3D(0, -1, 0);

        java.util.HashSet<Integer> visited = new java.util.HashSet<Integer>();

        do {

            visited.add(currentIndex);

            int maxIndex = 0;
            double maxAngle = -2 * Math.PI;
            double dist = Double.MAX_VALUE;
            for (int i = 0; i < xList.size(); i++) {
                if (i == currentIndex)
                    continue;
                Vector3D next = new Vector3D(xList.get(i) - xList.get(currentIndex),
                        yList.get(i) - yList.get(currentIndex), 0);

                double angle = Vector3D.angle(currentVector, next);
                angles.setEntry(i, angle);
                if (angle > maxAngle) {
                    maxAngle = angle;
                    maxIndex = i;
                    dist = next.getNorm();
                } else if (angle == maxAngle) {
                    double tempDist = next.getNorm();
                    if (tempDist < dist) {
                        dist = tempDist;
                        maxAngle = angle;
                        maxIndex = i;
                    }
                }
            }

            currentX = xList.get(maxIndex);
            currentY = yList.get(maxIndex);

            currentVector = new Vector3D(xList.get(currentIndex) - currentX, yList.get(currentIndex) - currentY,
                    0);

            hullPointsX.add(currentX);
            hullPointsY.add(currentY);

            currentIndex = maxIndex;

        } while (!visited.contains(currentIndex));

        //hull vertices have now been determined .. need to fill in the lines
        //between them so I can apply a fill filter

        //approach: x1, y1 to x0, y0:
        //start at min x, min y, go to max x, max y
        // if x_i, y_i = x0, y0  + slope to within 0.5 * sqrt(2), then add to hull

        double eps = Math.sqrt(2);

        for (int i = 0; i < hullPointsX.size() - 1; i++) {

            int x0 = hullPointsX.get(i);
            int y0 = hullPointsY.get(i);

            int x1 = hullPointsX.get(i + 1);
            int y1 = hullPointsY.get(i + 1);

            int xmin = (x0 < x1) ? x0 : x1;
            int ymin = (y0 < y1) ? y0 : y1;
            int xmax = (x0 > x1) ? x0 : x1;
            int ymax = (y0 > y1) ? y0 : y1;

            x1 -= x0;
            y1 -= y0;

            double denom = (x1 * x1 + y1 * y1);

            for (int x = xmin; x <= xmax; x++) {
                for (int y = ymin; y <= ymax; y++) {

                    int rel_x = x - x0;
                    int rel_y = y - y0;

                    double projLength = (x1 * rel_x + y1 * rel_y) / denom;

                    double projPoint_x = x1 * projLength;
                    double projPoint_y = y1 * projLength;

                    if (Math.hypot(rel_x - projPoint_x, rel_y - projPoint_y) < eps) {
                        ic.set(ImageCoordinate.X, x);
                        ic.set(ImageCoordinate.Y, y);
                        im.setValue(ic, k);
                    }

                }
            }

        }

    }

    ic.recycle();

    FillFilter ff = new FillFilter();

    ff.apply(im);

}

From source file:wssec.TestWSSecurityUserProcessor.java

/**
 * Test to see that a custom action can be configured via WSSecurityUtil.decodeAction.
 * A standard Timestamp action is also configured.
 *//*from  ww  w  .ja  va  2s  .c om*/
public void testDecodeCustomAction() throws Exception {

    final WSSConfig cfg = WSSConfig.getNewInstance();
    final int customAction = 0xDEADF000;

    String actionString = WSHandlerConstants.TIMESTAMP + " " + new Integer(customAction).toString();
    Vector actionList = new Vector();
    //
    // This parsing will fail as it doesn't know what the custom action is
    //
    try {
        WSSecurityUtil.decodeAction(actionString, actionList);
        fail("Failure expected on unknown action");
    } catch (WSSecurityException ex) {
        // expected
    }
    actionList.clear();

    //
    // This parsing will fail as WSSConfig doesn't know what the custom action is
    //
    try {
        WSSecurityUtil.decodeAction(actionString, actionList, cfg);
        fail("Failure expected on unknown action");
    } catch (WSSecurityException ex) {
        // expected
    }
    actionList.clear();

    //
    // This parsing will fail as the action String is badly formed
    //
    try {
        String badActionString = WSHandlerConstants.TIMESTAMP + " " + "NewCustomAction";
        WSSecurityUtil.decodeAction(badActionString, actionList, cfg);
        fail("Failure expected on unknown action");
    } catch (WSSecurityException ex) {
        // expected
    }
    actionList.clear();

    //
    // This parsing should pass as WSSConfig has been configured with the custom action
    //
    cfg.setAction(customAction, "wssec.MyAction");
    int actions = WSSecurityUtil.decodeAction(actionString, actionList, cfg);

    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);

    final Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
    MyHandler handler = new MyHandler();
    reqData.setMsgContext("bread");
    assertEquals(reqData.getMsgContext(), "bread");
    handler.doit(actions, doc, reqData, actionList);
    assertEquals(reqData.getMsgContext(), "crumb");

    if (LOG.isDebugEnabled()) {
        LOG.debug("Message:");
        String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
        LOG.debug(outputString);
    }
}