Example usage for java.util Vector listIterator

List of usage examples for java.util Vector listIterator

Introduction

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

Prototype

public synchronized ListIterator<E> listIterator() 

Source Link

Document

Returns a list iterator over the elements in this list (in proper sequence).

Usage

From source file:Main.java

public static void main(String[] args) {
    Vector<String> v = new Vector<String>();

    v.add("1");//w w w .j  av a2s .c  o m
    v.add("2");
    v.add("3");
    v.add("4");
    v.add("5");

    ListIterator itr = v.listIterator();
    while (itr.hasNext()) {
        System.out.println(itr.next());
    }
    while (itr.hasPrevious()) {
        System.out.println(itr.previous());
    }
}

From source file:org.powertac.officecomplexcustomer.persons.Person.java

/**
 * This function fills out the vector containing the days that the person is
 * going to be sick. When a person is sick he stays in bed.
 * //from w  ww.  ja v  a  2s . com
 * @param mean
 * @param dev
 * @param gen
 * @return
 */
Vector<Integer> createSicknessVector(double mean, double dev) {
    // Create auxiliary variables

    int days = (int) (dev * gen.nextGaussian() + mean);
    Vector<Integer> v = new Vector<Integer>(days);

    for (int i = 0; i < days; i++) {
        int x = gen.nextInt(
                OfficeComplexConstants.DAYS_OF_COMPETITION + OfficeComplexConstants.DAYS_OF_BOOTSTRAP) + 1;
        ListIterator<Integer> iter = v.listIterator();
        while (iter.hasNext()) {
            int temp = (int) iter.next();
            if (x == temp) {
                x = x + 1;
                iter = v.listIterator();
            }
        }
        v.add(x);
    }
    java.util.Collections.sort(v);
    return v;
}

From source file:org.powertac.householdcustomer.persons.Person.java

/**
 * This function fills out the vector containing the days that the person is
 * going to be sick. When a person is sick he stays in the household.
 * //from  w  w  w.j a  va 2 s. co m
 * @param mean
 * @param dev
 * @param gen
 * @return
 */
Vector<Integer> createSicknessVector(double mean, double dev) {
    // Create auxiliary variables

    int days = (int) (dev * gen.nextGaussian() + mean);
    Vector<Integer> v = new Vector<Integer>(days);

    for (int i = 0; i < days; i++) {
        int x = gen.nextInt(VillageConstants.DAYS_OF_COMPETITION + VillageConstants.DAYS_OF_BOOTSTRAP) + 1;
        ListIterator<Integer> iter = v.listIterator();
        while (iter.hasNext()) {
            int temp = (int) iter.next();
            if (x == temp) {
                x = x + 1;
                iter = v.listIterator();
            }
        }
        v.add(x);
    }
    java.util.Collections.sort(v);
    return v;
}

From source file:org.powertac.officecomplexcustomer.customers.OfficeComplex.java

/**
 * This function is creating a certain number of random days that will be
 * public vacation for the people living in the environment.
 * //from w  w w. j a v  a2  s . c om
 * @param days
 * @param gen
 * @return
 */
Vector<Integer> createPublicVacationVector(int days) {
    // Creating auxiliary variables
    Vector<Integer> v = new Vector<Integer>(days);

    for (int i = 0; i < days; i++) {
        int x = gen
                .nextInt(OfficeComplexConstants.DAYS_OF_COMPETITION + OfficeComplexConstants.DAYS_OF_BOOTSTRAP);
        ListIterator<Integer> iter = v.listIterator();
        while (iter.hasNext()) {
            int temp = (int) iter.next();
            if (x == temp) {
                x = x + 1;
                iter = v.listIterator();
            }
        }
        v.add(x);
    }
    java.util.Collections.sort(v);
    return v;
}

From source file:org.powertac.householdcustomer.customers.Village.java

/**
 * This function is creating a certain number of RandomSeed days that will be
 * public vacation for the people living in the environment.
 * //from  w  ww  . j  av  a2  s.  c  om
 * @param days
 * @param gen
 * @return
 */
Vector<Integer> createPublicVacationVector(int days) {
    // Creating auxiliary variables
    Vector<Integer> v = new Vector<Integer>(days);

    for (int i = 0; i < days; i++) {
        int x = gen.nextInt(VillageConstants.DAYS_OF_COMPETITION + VillageConstants.DAYS_OF_BOOTSTRAP);
        ListIterator<Integer> iter = v.listIterator();
        while (iter.hasNext()) {
            int temp = (int) iter.next();
            if (x == temp) {
                x = x + 1;
                iter = v.listIterator();
            }
        }
        v.add(x);
    }
    java.util.Collections.sort(v);
    return v;
}

From source file:org.alfresco.repo.transfer.AlienProcessorImpl.java

public void beforeDeleteAlien(NodeRef deletedNodeRef, ChildAssociationRef oldAssoc) {
    log.debug("before delete node - need to check for alien invaders");

    List<String> stuff = (List<String>) nodeService.getProperty(deletedNodeRef, TransferModel.PROP_INVADED_BY);
    if (stuff == null)
        return;//from   w w  w.j a v  a  2  s  .  c  o m
    Vector<String> exInvaders = new Vector<String>(stuff);

    /**
     * some fudge to get this to run after the node has been moved.
     */
    ChildAssociationRef currentAssoc;
    if (oldAssoc != null) {
        currentAssoc = oldAssoc;
    } else {
        currentAssoc = nodeService.getPrimaryParent(deletedNodeRef);
    }

    while (currentAssoc != null && exInvaders != null && exInvaders.size() > 0) {
        NodeRef parentNodeRef = currentAssoc.getParentRef();
        NodeRef currentNodeRef;

        if (currentAssoc == oldAssoc) {
            currentNodeRef = deletedNodeRef;
        } else {
            currentNodeRef = currentAssoc.getChildRef();
        }

        /**
         * Does the parent have alien invaders ?
         */
        if (nodeService.hasAspect(parentNodeRef, TransferModel.ASPECT_ALIEN)) {
            log.debug("parent node is invaded by aliens");

            /**
             * Remove the parent's origin from the list of exInvaders since the parent also invades.
             */
            String parentRepoId;
            if (nodeService.hasAspect(parentNodeRef, TransferModel.ASPECT_TRANSFERRED)) {
                parentRepoId = (String) nodeService.getProperty(parentNodeRef,
                        TransferModel.PROP_FROM_REPOSITORY_ID);
            } else {
                parentRepoId = descriptorService.getCurrentRepositoryDescriptor().getId();
            }

            exInvaders.remove(parentRepoId);

            /**
             * For each invader of the deletedNode
             */
            Iterator<String> i = exInvaders.listIterator();
            while (i.hasNext()) {
                String exInvader = i.next();
                log.debug("Checking exInvader:" + exInvader);

                /**
                  * Check the siblings of this node to see whether there are any other alien nodes for this invader.
                  */
                //List<ChildAssociationRef> refs = nodeService.getChildAssocs(parentNodeRef);
                List<ChildAssociationRef> refs = nodeService.getChildAssocsByPropertyValue(parentNodeRef,
                        TransferModel.PROP_INVADED_BY, exInvader);

                for (ChildAssociationRef ref : refs) {
                    NodeRef childRef = ref.getChildRef();
                    List<String> invadedBy = (List<String>) nodeService.getProperty(childRef,
                            TransferModel.PROP_INVADED_BY);

                    if (childRef.equals(currentNodeRef)) {
                        // do nothing - this is the node we are working with.
                    } else {
                        if (invadedBy != null && invadedBy.contains(exInvader)) {
                            // There is a sibling so remove this from the list of ex invaders.
                            log.debug("yes there is a sibling so it remains an invader");
                            i.remove();
                            break;
                        }
                    }
                } // for each child assoc

            } // for each invader

            log.debug("end of checking siblings");

            if (exInvaders.size() > 0) {
                log.debug("removing invaders from parent node:" + parentNodeRef);
                List<String> parentInvaders = (List<String>) nodeService.getProperty(parentNodeRef,
                        TransferModel.PROP_INVADED_BY);

                final List<String> newInvaders = new ArrayList<String>(10);
                for (String invader : parentInvaders) {
                    if (exInvaders.contains(invader)) {
                        log.debug("removing invader:" + invader);
                    } else {
                        newInvaders.add(invader);
                    }
                }

                final NodeRef oldAlien = parentNodeRef;

                /**
                 * Parent may be locked or not be editable by the current user 
                 * turn off auditing and lock service for this transaction and 
                 * run as admin.
                 */
                RunAsWork<Void> actionRunAs = new RunAsWork<Void>() {
                    public Void doWork() throws Exception {
                        behaviourFilter.disableBehaviour(oldAlien, ContentModel.ASPECT_AUDITABLE);
                        behaviourFilter.disableBehaviour(oldAlien, ContentModel.ASPECT_LOCKABLE);
                        if (newInvaders.size() > 0) {
                            nodeService.setProperty(oldAlien, TransferModel.PROP_INVADED_BY,
                                    (Serializable) newInvaders);
                        } else {
                            log.debug("parent node is no longer alien nodeRef" + oldAlien);
                            nodeService.removeAspect(oldAlien, TransferModel.ASPECT_ALIEN);
                        }
                        return null;
                    }
                };
                AuthenticationUtil.runAs(actionRunAs, AuthenticationUtil.getSystemUserName());
            }

            /**
             * Now step up to the parent's parent
             */
            currentAssoc = nodeService.getPrimaryParent(parentNodeRef);
        } else {
            log.debug("parent is not an alien node");
            currentAssoc = null;
        }
    } // end of while              
}

From source file:org.rhq.enterprise.server.plugins.alertSnmp.SnmpSenderTest.java

private void assertExpectedPdu(PDU pdu, PduExpectedValues expectedValues) {
    Vector variableBindings = pdu.getVariableBindings();

    assertTrue(variableBindings.size() == 9, "Variable bindings should contain 9 variable bindings and not "
            + variableBindings.size() + ": " + variableBindings);

    @SuppressWarnings("unchecked")
    ListIterator<VariableBinding> variableBindingsIterator = variableBindings.listIterator();

    VariableBinding variableBinding = variableBindingsIterator.next();
    assertEquals(variableBinding.getOid(), SnmpConstants.sysUpTime);

    variableBinding = variableBindingsIterator.next();
    assertEquals(variableBinding.getOid(), SnmpConstants.snmpTrapOID);
    assertEquals(variableBinding.getVariable(), expectedValues.getSnmpTrapOid());

    OID oidPrefix = new OID(TEST_VARIABLE_BINDING_PREFIX);
    while (variableBindingsIterator.hasNext()) {
        variableBinding = variableBindingsIterator.next();

        assertVariableBindingIsPrefixed(variableBinding, oidPrefix);
        assertVariableBindingHasStringValue(variableBinding);

        switch (variableBindingsIterator.previousIndex()) {
        case 2://w  w w . ja  v a2s .  c o m
            assertEquals(variableBinding.getVariable(),
                    new OctetString(expectedValues.getAlertDefinitionName()));
            break;
        case 3:
            assertEquals(variableBinding.getVariable(), new OctetString(expectedValues.getResourceName()));
            break;
        case 4:
            assertEquals(variableBinding.getVariable(), new OctetString(expectedValues.getPlatformName()));
            break;
        case 5:
            assertEquals(variableBinding.getVariable(), new OctetString(expectedValues.getAlertConditions()));
            break;
        case 6:
            assertEquals(variableBinding.getVariable(),
                    new OctetString(expectedValues.getAlertPriority().toString().toLowerCase()));
            break;
        case 7:
            assertEquals(variableBinding.getVariable(), new OctetString(expectedValues.getAlertUrl()));
            break;
        case 8:
            assertEquals(variableBinding.getVariable(), new OctetString(
                    expectedValues.getPlatformName() + "::" + expectedValues.getResourceName() + "::"));
            break;
        default:
            throw new RuntimeException("Unexpected index: " + variableBindingsIterator.previousIndex());
        }
    }
}