Package java.util

Examples of java.util.ArrayList


    mapper = getMapper("knownFailures.xml");
    Room room = new Room();
    room.setRoomName("some room name");
    House house = new House();
    house.setHouseName("some house name");
    house.setBathrooms(new ArrayList(Arrays.asList("master", "spare")));
    house.setRoom(room);
   
    Map<String, Object> result = mapper.map(house, HashMap.class);
    assertNotNull("bathrooms should exist", result.containsKey("bathrooms"));
    assertEquals("wrong bathrooms found", house.getBathrooms(), result.get("bathrooms"));
View Full Code Here


    private static int countConflictsForResources(Solution sol,
            Collection<? extends Resource> resources, boolean throwExc) {
        int counter = 0;
        for (Resource res : resources) {
            List<Event> events = new ArrayList(res.getEvents());
            for (int i = 0; i < events.size(); i++) {
                Event ev1 = events.get(i);
                if (sol.isEventAssigned(ev1))
                    for (int j = i + 1; j < events.size(); j++) {
                        Event ev2 = events.get(j);
                        if (sol.isEventAssigned(ev2) && ev1.overlapps(ev2))
                            if (throwExc)
                                throw new IllegalStateException("conflicting events in resource " +
                                        res + " ev1:" + ev1 + " " + ev1.getLocation() + " ev2:" + ev2 + " " + ev2.getLocation());
                            else
View Full Code Here

            model.addConstraint(rooms[ii]);
            ii++;
        }

        // avoid creating a Vector each time in UniActivity.addResourceGroup
        List<UniResource> allRooms = new ArrayList();
        for (int j = 0; j < rooms.length; j++) {
            allRooms.add(rooms[j]);
        }

        //TODO GroupsOfRooms
//        Vector groupOfRooms[] = new Vector[nrGroupsOfRooms];
//        for (int i = 0; i < nrGroupsOfRooms; i++) {
//            groupOfRooms[i] = new FastVector();
//
//            groupOfRooms[i].add(rooms[r]);
//            groupForRoom[r].add(groupOfRooms[i]);
//        }
//
//        for (int i = 0; i < nrLocations; i++) {
//            int cnt = 0;
//            for (int j = 0; j < nrGroupsOfRooms; j++) {
//                if (groupOfRooms[j].contains(rooms[i]))
//                    cnt++;
//            }
//            while (cnt < nrRoomInGroupMin) {
//                groupOfRooms[r].add(rooms[i]);
//                groupForRoom[i].add(groupOfRooms[r]);
//                cnt++;
//            }
//        }

        int nrTeachers = personDao.getAll().size();
        UniResource instructors[] = new UniResource[nrTeachers];
        Map<Person, UniResource> personToResource = FastMap.newInstance();
        ii = 0;
        for (Person p : personDao.getAll()) {
            instructors[ii] = new UniResource(p.getId() + "",
                    UniResource.TYPE_INSTRUCTOR, p.getName());
            model.addConstraint(instructors[ii]);
            personToResource.put(p, instructors[ii]);

            ii++;
        }

        List<Integer> starts = new ArrayList();
        Map<UniActivity, UniResource> activityToInitialRoom = FastMap.newInstance();

        for (Event event : eventDao.getAll()) {
            UniActivity activity = new UniActivity(event.getDuration(), ""
                    + event.getId(), event.getName());
            eventForActivity.put(activity, event);
            starts.add(event.getStart());

            UniResource roomRes = null;
            if (event.getLocation() != null)
                roomRes = locToRoom.get(event.getLocation());

            if (roomRes == null) {
                int room = ToolBox.random(nrRooms);
                activityToInitialRoom.put(activity, rooms[room]);
            } else
                activityToInitialRoom.put(activity, roomRes);

            activity.addResourceGroup(allRooms);
            for (Person p : event.getPersons()) {
                UniResource res = personToResource.get(p);
                if (res == null)
                    throw new NullPointerException("cannot find activity for:" + p.getName());
                activity.addResourceGroup(res);
            }

//            activity.addResourceGroup(classes[aclass]);
            model.addVariable(activity);
        }

        // specify dicourage slots
        for (int i = 0; i < model.variables().size(); i++) {
            UniActivity activity = (UniActivity) model.variables().elementAt(i);
            for (int day = 0; day < nrDays; day++) {
                for (int hour = 0; hour < slotsPerDay; hour++) {
                    addDiscouragedSlot(activity, day, hour, slotsPerDay);
                }
            }

            // create values/assigments
            activity.init();
        }

        for (int i = 0; i < model.variables().size(); i++) {
            UniActivity activity = (UniActivity) model.variables().elementAt(i);

            if (initialAssignment) {
                int start = starts.get(i);
                UniResource room = activityToInitialRoom.get(activity);

                // find value/assignment with specific room and slot
                UniAssignment assignment = null;
                for (Enumeration e = activity.values().elements(); e.hasMoreElements();) {
View Full Code Here

        int startOld = ass.getStart();
        List undoRemoveList = Collections.emptyList();
        if (startOld >= 0) {
            Event ev = ass.getEvent();
            int end = startOld + ev.getDuration();
            undoRemoveList = new ArrayList(end - startOld);
            for (int slot = startOld; slot < end; slot++) {
                Object obj = clusterArray.get(slot).remove(ass);
                if (obj == null)
                    throw new IllegalStateException("Cannot remove assignment:" + ass);
                undoRemoveList.add(obj);
View Full Code Here

        if (old >= 0)
            throw new IllegalStateException(ass + " was unassigned; " + startTimeNew);

        ass.setStart(startTimeNew);
        Event ev = ass.getEvent();
        List matrixList = new ArrayList();
        Object oldMatrix;
        if (ev.getDuration() == 1) {
            oldMatrix = clusterArray.get(startTimeNew).assign(ass);
            if (oldMatrix == null) {
                ass.setStart(old);
                return null;
            }
            matrixList.add(oldMatrix);
        } else {
            int slot = startTimeNew;
            int end = startTimeNew + ass.getEvent().getDuration();
            Location loc = clusterArray.get(slot).calculateLocation(ass);
            if (loc == null) {
                ass.setStart(old);
                return null;
            }

            slot++;
            for (; slot < end; slot++) {
                if (!clusterArray.get(slot).isForcedAssignmentPossible(ass, loc)) {
                    ass.setStart(old);
                    return null;
                }
            }

            slot = startTimeNew;
            for (; slot < end; slot++) {
                oldMatrix = clusterArray.get(slot).forceAssignment(ass, loc);
                if (oldMatrix == null)
                    throw new IllegalStateException("Although it was calculated that"
                            + " adding event is possible it can't!!??: " + ass + " start:" + slot + " loc:" + loc);
                matrixList.add(oldMatrix);
            }
        }

        conflictMatrix.add(ass);
        return matrixList;
View Full Code Here

            for (int i = 0; i < todo; i++) {
                eventToTrees.add(null);
                eventsDuration.add(null);
            }
            // create an empty arrayList at the correct index 'todo'
            eventToTrees.add(new ArrayList());
            eventsDuration.add(eDur);
        }
    }
View Full Code Here

            eventsDuration.add(eDur);
        }
    }

    protected ArrayList<EventTree> sortTrees() {
        ArrayList<EventTree> list = new ArrayList();
        for (List<EventTree> trees : eventToTrees) {
            for (EventTree tree : trees) {
                if (tree.isEnabled()) // && tree.getWeight() > 0)
                    list.add(tree);
            }
        }

        if (list.size() == 0)
            throw new IllegalStateException("No elements in list!?");

        // not faster:
//        LinearSort.sort(list);
View Full Code Here

    handler.setTargetBeanExpression(null);
    handler.setBeanPropertyName("domainClass");
    handler.setBeanPropertyClass(Integer.class);

    BindableBean form = new BindableBean();
    Collection collection = new ArrayList();
    collection.add(new DomainClass(1));
    collection.add(new DomainClass(3));
    collection.add(new DomainClass(4));
    Map map = handler.getPropertyAsMap(collection);
    form.setLookupMap(map);

    TargetBean targetBean = new TargetBean();
    form.setTargetBean(targetBean);
View Full Code Here

  @Test
  public void testNullTargetBindOutwards()
  {

    BindableBean form = new BindableBean();
    Collection collection = new ArrayList();
    collection.add(new DomainClass(1));
    collection.add(new DomainClass(3));
    collection.add(new DomainClass(4));
    Map map = handler.getPropertyAsMap(collection);
    form.setLookupMap(map);

    TargetBean targetBean = new TargetBean();
    // form.setTargetBean(targetBean);
View Full Code Here

    public void setLocale(Locale locale) {
        noHHmmFormatter1 = new SimpleDateFormat("MMM-dd-yyyy", locale);
        noHHmmFormatter2 = new SimpleDateFormat("dd-MMM-yyyy", locale);
        noHHmmFormatter = noHHmmFormatter1;
       
        hhmmFormatters = new ArrayList();
        hhmmFormatters.add(new SimpleDateFormat("MMM-d-yyyy-HH:mm", locale));
        hhmmFormatters.add(new SimpleDateFormat("MMM-dd-yyyy-HH:mm", locale));
        hhmmFormatters.add(new SimpleDateFormat("MMM-d-yyyy-H:mm", locale));
        hhmmFormatters.add(new SimpleDateFormat("MMM-dd-yyyy-H:mm", locale));
        hhmmFormatters.add(new SimpleDateFormat("MMM-dd-yyyy-H.mm", locale));
View Full Code Here

TOP

Related Classes of java.util.ArrayList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.