Example usage for java.util ArrayList indexOf

List of usage examples for java.util ArrayList indexOf

Introduction

In this page you can find the example usage for java.util ArrayList indexOf.

Prototype

public int indexOf(Object o) 

Source Link

Document

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void updateLists(@NotNull final List<Task> checkedTasks) {
    final ArrayList<String> contexts = new ArrayList<String>();
    Set<String> selectedContexts = new HashSet<String>();
    final TaskCache taskbag = getTaskBag();
    contexts.addAll(Util.sortWithPrefix(taskbag.getContexts(), m_app.sortCaseSensitive(), null));
    for (Task t : checkedTasks) {
        selectedContexts.addAll(t.getLists());
    }//from w  ww.j av a 2  s .c  o  m

    @SuppressLint("InflateParams")
    View view = getLayoutInflater().inflate(R.layout.tag_dialog, null, false);
    final ListView lv = (ListView) view.findViewById(R.id.listView);
    lv.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_multiple_choice,
            contexts.toArray(new String[contexts.size()])));
    lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    for (String context : selectedContexts) {
        int position = contexts.indexOf(context);
        if (position != -1) {
            lv.setItemChecked(position, true);
        }
    }

    final EditText ed = (EditText) view.findViewById(R.id.editText);
    m_app.setEditTextHint(ed, R.string.new_list_name);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(view);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ArrayList<String> originalLines = new ArrayList<String>();
            originalLines.addAll(Util.tasksToString(getCheckedTasks()));
            ArrayList<String> items = new ArrayList<String>();
            ArrayList<String> uncheckedItesm = new ArrayList<String>();
            uncheckedItesm.addAll(Util.getCheckedItems(lv, false));
            items.addAll(Util.getCheckedItems(lv, true));
            String newText = ed.getText().toString();
            if (!newText.equals("")) {
                items.add(ed.getText().toString());
            }
            for (String item : items) {
                for (Task t : checkedTasks) {
                    t.addList(item);
                }
            }
            for (String item : uncheckedItesm) {
                for (Task t : checkedTasks) {
                    t.removeTag("@" + item);
                }
            }
            finishActionmode();
            m_app.getTaskCache(null).modify(originalLines, checkedTasks, null, null);
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // User cancelled the dialog
        }
    });
    // Create the AlertDialog
    AlertDialog dialog = builder.create();
    dialog.setTitle(R.string.update_lists);
    dialog.show();
}

From source file:com.edgenius.wiki.service.impl.PageServiceImpl.java

public Page savePage(Page pageValue, int requireNotified, boolean forceSave)
        throws PageException, VersionConflictException, DuplicatedPageException, PageSaveTiemoutExcetpion {
    Page page = null;/*from   ww  w  .j a  v a 2  s. c o m*/
    String spaceUname = pageValue.getSpace().getUnixName();
    String newPageTitle = pageValue.getTitle();
    Integer newPageUid = pageValue.getUid();

    log.info("Page saving for " + pageValue.getTitle() + " on space " + spaceUname);
    Space space;
    //page already exist, need clone then save a new record in database
    String oldTitle = null;
    boolean needRefreshCache = false;

    if (newPageUid != null) {
        //The page will create  old version to new record but update same UID as current 
        //it would get same result by pageDAO.getCurrentByUuid() but a little bit faster in performance.
        page = pageDAO.get(newPageUid);
    } else if (!StringUtils.isBlank(pageValue.getPageUuid())) {
        //if user choose a item from My Draft in Dashboard, this won't bring in a newPageUid 
        //There are 3 scenarios for this case. 
        //1. it is a existed page draft.Following method returns current page,
        //2. non-existed page draft. Following method returns null.
        //3. non-existed page but page has a copy in trash bin! The below method return null as well, but the uuid is already invalid
        // as it is used by trashed page - so need further check - if it has trashed page, reset pageUUID
        page = pageDAO.getCurrentByUuid(pageValue.getPageUuid());

        if (page == null) {
            Page removedPage = pageDAO.getByUuid(pageValue.getPageUuid());
            if (removedPage != null && removedPage.isRemoved()) {
                //case 3, treat it as new page
                pageValue.setPageUuid(null);
            }
        }
    }

    if (!forceSave && !checkVersion(pageValue, page)) {
        throw new VersionConflictException(page.getVersion());
    }

    //!!!Title duplicated problem: user try to create a new page or rename a page but same title already exist in space 
    Page sameTitlePage = pageDAO.getCurrentPageByTitle(spaceUname, newPageTitle);
    if (page != null) {
        if (sameTitlePage != null) {
            if (!sameTitlePage.getPageUuid().equals(page.getPageUuid()))
                throw new DuplicatedPageException();
        }

        //keep old page :NOTE: this piece code has duplicate with fixLinksToTitle() method
        History oldPage = (History) page.cloneToHistory();
        //put this page to history page:create a new record with cloned value except Uid
        //         history page does not save link, tag and attachment info. 
        //         The key is save content change!
        oldPage.setAttachments(null);
        oldPage.setParent(null);
        historyDAO.saveOrUpdate(oldPage);

        if (!StringUtils.equalsIgnoreCase(oldPage.getTitle(), newPageTitle)) {
            // oldTitle is not null, so that update PageLink on below
            oldTitle = oldPage.getTitle();
            needRefreshCache = true;
            //remove old page with old title from cache first, new page should add after page saved
            removePageCache(spaceUname, page, false);
        }
        //update current page with new value
        space = page.getSpace();

        copyValueFromView(page, pageValue);
        //         page.setUnixName(WikiUtil.getPageUnixname(newPageTitle));
        WikiUtil.setTouchedInfo(userReadingService, page);
        page.setVersion(page.getVersion() + 1);
    } else {
        //for new create page: same title page must not exist
        if (sameTitlePage != null) {
            throw new DuplicatedPageException("Page has duplicated title:" + newPageTitle);
        }

        needRefreshCache = true;
        //a new page first time save:
        page = new Page();
        copyValueFromView(page, pageValue);

        space = spaceDAO.getByUname(spaceUname);
        page.setSpace(space);

        //??? CascadeType.PERSIST seems does not work well. I must explicit call save(), but in CascadeType.ALL, it is not necessary.
        pageProgressDAO.saveOrUpdate(page.getPageProgress());

        page.setVersion(1);
        //if there is draft existed before page first create, keep draft uuid as page uuid!!! 
        if (StringUtils.isBlank(pageValue.getPageUuid()))
            page.setPageUuid(WikiUtil.createPageUuid(spaceUname, spaceUname, spaceUname, repositoryService));
        else
            page.setPageUuid(pageValue.getPageUuid());
        //         page.setUnixName(WikiUtil.getPageUnixname(newPageTitle));
        WikiUtil.setTouchedInfo(userReadingService, page);

        if (pageValue.getParent() != null && !StringUtils.isBlank(pageValue.getParent().getPageUuid())) {
            Page parentPage = pageDAO.getCurrentByUuid(pageValue.getParent().getPageUuid());
            if (parentPage != null) {
                //maybe parent page is deleted as well.
                page.setParent(parentPage);
                page.setLevel(parentPage.getLevel() + 1);
            } else {
                log.warn("page parent page does not exist. Page title is " + pageValue.getTitle()
                        + ". Parent page uuid is " + pageValue.getParent().getPageUuid());
            }
        } else
            //root page, such as home page
            page.setLevel(0);
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //update page tags
    tagService.saveUpdatePageTag(page, pageValue.getTagString());

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // !!!! Important: this update attachments status must before  renderService.renderHTML(page)
    // otherwise, the drafts attachment won't render in {attach} or {gallery} macro....

    // Update page attachment status 
    //   remove this user's draft, does not use getDraft() then remove, because following error: 
    //      org.hibernate.HibernateException: Found shared references to a collection: com.edgenius.wiki.model.Page.tags
    try {
        User viewer = WikiUtil.getUser(userReadingService);
        mergeAttahment(getPageAttachment(spaceUname, page.getPageUuid(), true, true, viewer),
                pageValue.getAttachments(), spaceUname, viewer, PageType.NONE_DRAFT);
        upgradeAttachmentStatus(spaceUname, page.getPageUuid(), page.getModifier(), PageType.NONE_DRAFT);
    } catch (RepositoryException e) {
        //not critical exception, just log:
        log.error("Update attachment status during saving page:" + page.getPageUuid() + " in space "
                + spaceUname + ".Error: ", e);
    } catch (RepositoryTiemoutExcetpion e) {
        log.error("Merge attachment saving page:" + page.getPageUuid() + " in space " + spaceUname + ".Error: ",
                e);
    }

    List<RenderPiece> pieces = renderService.renderHTML(page);
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //update page links
    Set<PageLink> links = page.getLinks();
    if (links == null) {
        links = new HashSet<PageLink>();
        page.setLinks(links);
    }

    List<PageLink> newLinks = new ArrayList<PageLink>();
    for (RenderPiece object : pieces) {
        if (object instanceof LinkModel) {
            LinkModel ln = (LinkModel) object;
            //!!! Only linkToCreate and LinkToView support at moment(29/10/2008)
            if (ln.getType() == LinkModel.LINK_TO_CREATE_FLAG || ln.getType() == LinkModel.LINK_TO_VIEW_FLAG) {
                if (StringUtils.length(ln.getLink()) > SharedConstants.TITLE_MAX_LEN) {
                    log.warn("Found invalid link(too long), skip it on PageLink table:" + ln.getLink()
                            + " on page " + newPageTitle);
                } else {
                    PageLink link = PageLink.copyFrom(page, ln);
                    newLinks.add(link);
                }
            }
        }
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //update menu item for space
    //found other if current page has menuItem macro.

    MenuItem menuItem = null;
    //if this marked true, it will trigger the Shell update space request, so update Shell menu.
    page.setMenuUpdated(false);

    for (RenderPiece renderPiece : pieces) {
        if (renderPiece instanceof MacroModel
                && MenuItemMacro.NAME.equalsIgnoreCase(((MacroModel) renderPiece).macroName)) {
            //copy value to MenuItem object
            menuItem = new MenuItem();
            HashMap<String, String> values = ((MacroModel) renderPiece).values;
            if (values != null) {
                menuItem.setTitle(values.get(NameConstants.TITLE));
                menuItem.setOrder(NumberUtils.toInt(values.get(NameConstants.ORDER)));
                menuItem.setParent(values.get(NameConstants.PARENT_UUID));
            }
            menuItem.setPageTitle(page.getTitle());
            menuItem.setPageUuid(page.getPageUuid());
            //suppose only one menuItem in a page, if multiple, even also only use first of them.
            break;
        }
    }

    Set<MenuItem> menuItems = space.getSetting().getMenuItems();
    if (menuItem != null) {
        //update menu list in current space setting
        if (menuItems == null) {
            menuItems = new TreeSet<MenuItem>(new MenuItemComparator());
            space.getSetting().setMenuItems(menuItems);
        } else {
            //try to remove old value
            menuItems.remove(menuItem);
        }

        log.info("Menu item is add or update to page {}.", page.getPageUuid());
        menuItems.add(menuItem);
        settingService.saveOrUpdateSpaceSetting(space, space.getSetting());
        page.setMenuUpdated(true);
    } else if (menuItems != null) {
        //need check if menu item is deleted from page if it had. Try to remove it.
        if (menuItems.remove(new MenuItem(page.getPageUuid()))) {
            log.info("Menu item is removed from page {}.", page.getPageUuid());
            settingService.saveOrUpdateSpaceSetting(space, space.getSetting());
            page.setMenuUpdated(true);
        }
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //merge new links and existed links
    //delete non-existed
    for (Iterator<PageLink> iter = links.iterator(); iter.hasNext();) {
        PageLink ln = iter.next();
        ln.setAmount(0);
        for (Iterator<PageLink> newIter = newLinks.iterator(); newIter.hasNext();) {
            PageLink nlnk = newIter.next();
            if (ln.equals(nlnk)) {
                ln.setAmount(ln.getAmount() + 1);
                newIter.remove();
            }
        }
        if (ln.getAmount() == 0) {
            iter.remove();
        }
    }
    if (newLinks.size() > 0) {
        ArrayList<PageLink> linksList = new ArrayList<PageLink>(links);
        //there some new added links
        int idx;
        for (PageLink newLnk : newLinks) {
            if ((idx = linksList.indexOf(newLnk)) != -1) {
                PageLink ln = linksList.get(idx);
                ln.setAmount(ln.getAmount() + 1);
            } else {
                linksList.add(newLnk);
            }
        }
        links.clear();
        links.addAll(linksList);
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //persistent
    page.setType(PageType.NONE_DRAFT);
    pageDAO.saveOrUpdate(page);

    //!!!NOTE: follow 3 lines code must after pageDAO.saveOrUpdate(),otherwise, if home page
    // is new page and contain link, method pageDAO.getCurrentByTitle() in LinkRenderHelper.exist() 
    //method will throw exception!!!(15/03/2007_my new car Honda Accord arrives in home:)
    if (pageValue.getNewPageType() == PageAttribute.NEW_HOMEPAGE) {
        space.setHomepage(page);
        spaceDAO.saveOrUpdate(space);
    }

    //update cache only when a new page created or page title updated
    if (needRefreshCache) {
        addPageCache(spaceUname, page);
    }
    refreshAncestors(spaceUname, page);

    //page title change so change all page which refer link to this page.
    //only title change,oldTitle is not null.
    if ((Global.AutoFixLinks & WikiConstants.AUTO_FIX_TITLE_CHANGE_LINK) > 0 && oldTitle != null) {
        String newTitle = page.getTitle();
        try {
            fixLinksToTitle(spaceUname, oldTitle, newTitle);
        } catch (Exception e) {
            log.error("Unable to fix page title change on other pages content.", e);
        }
    }

    //remove all draft whatever auto or manual
    removeDraftInternal(spaceUname, page.getPageUuid(), page.getModifier(), PageType.NONE_DRAFT, false);

    //MOVE to PageIndexInterceptor
    //      if(requireNotified)
    //         sendNodification(page);

    log.info("Page saved " + newPageTitle + " on space " + spaceUname + ". Page uid: " + newPageUid);

    PageEventListener[] listeners = eventContainer.getPageEventListeners(page.getPageUuid());
    if (listeners != null && listeners.length > 0) {
        log.info("Page saved event dispatching...");
        for (PageEventListener listener : listeners) {
            try {
                listener.pageSaving(page.getPageUuid());
            } catch (PageEventHanderException e) {
                log.error("Page saved event processed failed on " + listener.getClass().getName(), e);
            }
        }
    }
    return page;

}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.GUIComponents.XYSequencing.java

public void generatesearchFOVs() { // Copied from generateFOVs()
    ArrayList<FOV> searchfovs = new ArrayList<FOV>();
    //Use the display table to 
    ArrayList<FOV> preexisting = new ArrayList<FOV>(tableModel_.getData());
    searchFOVtableModel_.clearAllData();
    tableModel_.clearAllData();//from  w  w w  . j av  a  2  s  .c  o  m
    //Clear pre-existing FOV table? Not sure yet, so comment out
    //tableModel_.clearAllData();

    for (int cols = 0; cols < pp_.getPlateColumns(); cols++) {
        ArrayList<Boolean> temp = pmdp_.wellsSelected_.get(cols);
        for (int rows = 0; rows < pp_.getPlateRows(); rows++) {
            if (temp.get(rows)) {

                //Always do spiral for now...

                String wellString = Character.toString((char) (65 + rows)) + Integer.toString(cols + 1);
                //Max # of times to search = #of FOVs desired * #to try before giving up
                searchfovs = generateSpiral(
                        parent_.getPrefind_NoOfAttempts() * parent_.getPrefind_NoOfFOVToFind(), wellString);
                //searchfovs = generateSpiral(Integer.parseInt(FOVToFindField.getText())*(Integer.parseInt(attemptsField.getText())),wellString);

                for (FOV fov : searchfovs) {
                    //Do we need this part?
                    if (preexisting.contains(fov)) {
                        fov.setGroup(preexisting.get(preexisting.indexOf(fov)).getGroup());
                    } else {
                        fov.setGroup(groupDescField.getText());
                    }

                    searchFOVtableModel_.addRow(fov);
                }
                //Can ignore the Z stuff?
                //doZStackGeneration(getZStackParams());
            }
        }
    }
}

From source file:ch.icclab.cyclops.resource.impl.GenerateResource.java

/**
 * Generate the CDR of all the users for the selected meters
 * <p>/*  w w  w  . j a v a2  s  . com*/
 * Pseudo Code
 * 1. Get the list of selected meters
 * 2. Query the UDR service to get the usage information under these meters for all the users for a time period
 * 3. Get the rate for the same meters for a same time period
 * 4. Combine the rate and usage to get the charge value
 * 5. Save it in the db
 *
 * @return boolean
 */
private boolean generateCdr() throws IOException, JSONException {
    //TODO: split it into smaller methods
    logger.trace("BEGIN boolean generateCdr() throws IOException, JSONException");
    Object usage;
    double charge;
    String from, to;
    String[] time;
    int indexUserId, indexUsage;
    ArrayList usageListArr, usageArr;
    ArrayList columnArr;
    UDRServiceClient udrClient = new UDRServiceClient();
    RateResource rateResource = new RateResource();
    ArrayList<ArrayList<Object>> objArr = new ArrayList<ArrayList<Object>>();
    Double rate;
    TSDBData tsdbData;
    boolean result;
    String userid;
    ArrayList<ResourceUsage> resourceUsageArray;
    ArrayList<Object> objArrNode;
    HashMap tags;
    POJOUtil pojoUtil = new POJOUtil();

    DateTimeUtil dateTimeUtil = new DateTimeUtil();
    time = dateTimeUtil.getRange();

    from = time[1];
    to = time[0];
    logger.trace("DATA boolean generateCdr() throws IOException, JSONException: enabledResourceList"
            + enabledResourceList);
    for (int i = 0; i < enabledResourceList.size(); i++) {
        tsdbData = rateResource.getResourceRate(enabledResourceList.get(i).toString(), from, to);
        rate = calculateRate(tsdbData);
        resourceUsageArray = udrClient.getResourceUsageData(enabledResourceList.get(i).toString(), from, to);
        logger.trace("DATA boolean generateCdr() throws IOException, JSONException: resourceUsageStr"
                + resourceUsageArray);
        for (ResourceUsage resource : resourceUsageArray) {
            columnArr = resource.getColumn();
            logger.trace("DATA boolean generateCdr()...: columnArr=" + Arrays.toString(columnArr.toArray()));
            usageListArr = resource.getUsage();
            tags = resource.getTags();
            logger.trace("DATA boolean generateCdr()...: tags=" + tags);
            //indexUserId = columnArr.indexOf("userid");
            userid = tags.get("userid").toString();
            //userid = userid.substring(0, userid.length());
            logger.trace("DATA boolean generateCdr()...: userid=" + userid);
            logger.trace("DATA boolean generateCdr()...: usageListArr=" + usageListArr.toString());
            indexUsage = columnArr.indexOf("mean");
            // The below if condition differentiates between the gauge and cumulative meters of openstack
            if (indexUsage < 0) {
                indexUsage = columnArr.indexOf("usage");//usage if we are not using the sum in the sql else "sum"
            }
            // Iterate through the usage arraylist to extract the userid and usage.
            // Multiple the usage with the rate of the resource and save it into an arraylist
            for (int j = 0; j < usageListArr.size(); j++) {
                usageArr = (ArrayList) usageListArr.get(j);
                logger.trace("DATA boolean generateCdr()...: indexUsage=" + indexUsage);
                usage = usageArr.get(indexUsage);
                // Calculate the charge for a resource per user
                Double d = Double.parseDouble(usage.toString());
                charge = (d * rate);
                String resources = enabledResourceList.get(i).toString();
                logger.trace("DATA boolean generateCdr()...: objArr=" + Arrays.toString(objArr.toArray()));
                objArr = pojoUtil.populateList(usageListArr, objArr, resources, userid, usage, charge);
                /*for (int k = 0; k < usageListArr.size(); k++) {//resourceUsageStr.get(usage).size()
                objArrNode = new ArrayList<Object>();
                //userid = (String) usageArr.get(indexUserId);
                        
                objArrNode.add(resources);
                objArrNode.add(userid);
                objArrNode.add(usage);
                objArrNode.add(charge);
                objArr.add(objArrNode);
                }*/
            }
        }

    }
    // Save the charge array into the database
    result = savePrice(objArr);
    logger.trace("END boolean generateCdr() throws IOException, JSONException");
    return result;
}

From source file:ded.ui.DiagramController.java

/** If a controller is selected, cycle to either the next or
  * previous depending on 'forward' (true means next).
  *//from  w  ww .j  ava  2 s .  c  om
  * Otherwise, select the first controller if there is one. */
public void selectNextController(boolean forward) {
    // Make a list of cyclable controllers.  In particular, we need
    // to ignore resize handles.
    ArrayList<Controller> controllerCycle = new ArrayList<Controller>();
    for (Controller c : this.controllers) {
        if (c.wantLassoSelection()) {
            controllerCycle.add(c);
        }
    }

    // The insertion order isn't very meaningful and cannot be
    // easily changed by the user.  So, instead, sort by the
    // controllers' locations to make the cycle order more
    // predictable.
    Collections.sort(controllerCycle, new ControllerLocationComparator());

    // Locate the currently selected controller in the sorted cycle.
    int curSelIndex = controllerCycle.indexOf(this.getUniqueSelected());
    if (curSelIndex == -1) {
        // Nothing selected, start with first controller if
        // there is one.
        if (!controllerCycle.isEmpty()) {
            selectOnly(controllerCycle.get(0));
        }
        return;
    }

    // Compute index of next to select, cycling as necessary.
    // The extra size() term is to ensure the dividend does not
    // become negative.
    int nextSelIndex = (controllerCycle.size() + curSelIndex + (forward ? +1 : -1)) % controllerCycle.size();

    // Select it.
    selectOnly(controllerCycle.get(nextSelIndex));
}

From source file:org.sakaiproject.tool.assessment.qti.helper.ExtractionHelper.java

/**
 * Check to find out it response label is in the list of correct responses
 * @param testLabel response label//from   www . java  2  s .  com
 * @param labels the list of correct responses
 * @return
 */
private boolean isCorrectLabel(String testLabel, ArrayList labels) {
    if (testLabel == null || labels == null || labels.indexOf(testLabel) == -1) {
        return false;
    }

    return true;
}

From source file:org.prom5.analysis.performance.dottedchart.model.DottedChartModel.java

/**
 * construct dotted chart model/* w ww. jav a  2  s .  c  o  m*/
 */
public void construct() {
    //initialize list that is used to keep track of the data-elements that
    //appear in the process log
    inputLog.reset();
    LogUnitList.resetIdCounter();
    AbstractLogUnit event = null;

    // originators
    String[] originators = inputLog.getLogSummary().getOriginators();
    ArrayList originatorList = new ArrayList(Arrays.asList(originators));
    LogUnitList[] logUnitList = new LogUnitList[originators.length];
    for (int i = 0; i < originators.length; i++) {
        logUnitList[i] = new LogUnitList();
    }
    // tasks
    String[] tasks = inputLog.getLogSummary().getModelElements();
    ArrayList taskList = new ArrayList(Arrays.asList(tasks));
    LogUnitList[] logUnitforTaskList = new LogUnitList[tasks.length];
    for (int i = 0; i < tasks.length; i++) {
        logUnitforTaskList[i] = new LogUnitList();
    }
    // events
    String[] events = inputLog.getLogSummary().getEventTypes();
    ArrayList eventList = new ArrayList(Arrays.asList(events));
    LogUnitList[] logUnitforEventList = new LogUnitList[events.length];
    for (int i = 0; i < events.length; i++) {
        logUnitforEventList[i] = new LogUnitList();
    }

    Iterator it = inputLog.instanceIterator();

    while (it.hasNext()) {
        ProcessInstance pi = (ProcessInstance) it.next();
        Iterator ates = pi.getAuditTrailEntryList().iterator();
        LogUnitList logUnitListforInstance = new LogUnitList();
        while (ates.hasNext()) {
            AuditTrailEntry ate = (AuditTrailEntry) ates.next();
            if (ate.getTimestamp() == null)
                continue;
            event = AbstractLogUnit.create(pi, ate);
            // for instance
            logUnitListforInstance.addEvent(event);
            // for tasks
            if (taskDateMap.get(event.getElement()) == null
                    || taskDateMap.get(event.getElement()).after(ate.getTimestamp())) {
                taskDateMap.remove(event.getElement());
                taskDateMap.put(event.getElement(), ate.getTimestamp());
            }
            if (taskEndDateMap.get(event.getElement()) == null
                    || taskEndDateMap.get(event.getElement()).before(ate.getTimestamp())) {
                taskEndDateMap.remove(event.getElement());
                taskEndDateMap.put(event.getElement(), ate.getTimestamp());
            }

            logUnitforTaskList[taskList.indexOf(event.getElement())].addEvent(event);
            // for events
            if (eventDateMap.get(event.getType()) == null
                    || eventDateMap.get(event.getType()).after(ate.getTimestamp())) {
                eventDateMap.remove(event.getType());
                eventDateMap.put(event.getType(), ate.getTimestamp());
            }
            if (eventEndDateMap.get(event.getType()) == null
                    || eventEndDateMap.get(event.getType()).before(ate.getTimestamp())) {
                eventEndDateMap.remove(event.getType());
                eventEndDateMap.put(event.getType(), ate.getTimestamp());
            }
            logUnitforEventList[eventList.indexOf(event.getType())].addEvent(event);
            //for data elements
            Iterator it2 = ate.getAttributes().keySet().iterator();
            //run through attributes
            while (it2.hasNext()) {
                String tempString = (String) it2.next();
                if (tempString != "") {
                    //add tempString to elts if it is not equal to the empty String
                    if (dataMap.containsKey(tempString)) {
                        ((LogUnitList) dataMap.get(tempString)).addEvent(event);
                    } else {
                        LogUnitList tempLogUnitList = new LogUnitList(tempString);
                        tempLogUnitList.addEvent(event);
                        dataMap.put(tempString, tempLogUnitList);
                    }
                }
            }
            //for originators
            if (originatorList.indexOf(event.getOriginator()) < 0)
                continue;
            if (originatorDateMap.get(event.getOriginator()) == null
                    || originatorDateMap.get(event.getOriginator()).after(ate.getTimestamp())) {
                originatorDateMap.remove(event.getOriginator());
                originatorDateMap.put(event.getOriginator(), ate.getTimestamp());
            }
            if (originatorEndDateMap.get(event.getOriginator()) == null
                    || originatorEndDateMap.get(event.getOriginator()).before(ate.getTimestamp())) {
                originatorEndDateMap.remove(event.getOriginator());
                originatorEndDateMap.put(event.getOriginator(), ate.getTimestamp());
            }

            logUnitList[originatorList.indexOf(event.getOriginator())].addEvent(event);
        }
        instanceMap.put(pi.getName(), logUnitListforInstance);
    }
    for (int i = 0; i < tasks.length; i++) {
        taskMap.put(tasks[i], logUnitforTaskList[i]);
    }
    for (int i = 0; i < events.length; i++) {
        eventMap.put(events[i], logUnitforEventList[i]);
    }
    for (int i = 0; i < originators.length; i++) {
        originatorMap.put(originators[i], logUnitList[i]);
    }
    sortedKeys = new ArrayList(taskMap.keySet());
}

From source file:org.sakaiproject.tool.assessment.qti.helper.ExtractionHelper.java

/**
 * Respondus questions/* w  w  w . j  a va 2s. co m*/
 */
private boolean isCorrectAnswer(String answerText, ArrayList correctLabels) {
    if (answerText == null || correctLabels == null || correctLabels.indexOf(answerText) == -1) {
        return false;
    }

    return true;
}

From source file:org.processmining.analysis.performance.dottedchart.model.DottedChartModel.java

/**
 * construct dotted chart model// w  w  w.j  a va 2 s.  c om
 */
public void construct() {
    // initialize list that is used to keep track of the data-elements that
    // appear in the process log
    inputLog.reset();
    LogUnitList.resetIdCounter();
    AbstractLogUnit event = null;

    // originators
    String[] originators = inputLog.getLogSummary().getOriginators();
    ArrayList originatorList = new ArrayList(Arrays.asList(originators));
    LogUnitList[] logUnitList = new LogUnitList[originators.length];
    for (int i = 0; i < originators.length; i++) {
        logUnitList[i] = new LogUnitList();
    }
    // tasks
    String[] tasks = inputLog.getLogSummary().getModelElements();
    ArrayList taskList = new ArrayList(Arrays.asList(tasks));
    LogUnitList[] logUnitforTaskList = new LogUnitList[tasks.length];
    for (int i = 0; i < tasks.length; i++) {
        logUnitforTaskList[i] = new LogUnitList();
    }
    // events
    String[] events = inputLog.getLogSummary().getEventTypes();
    ArrayList eventList = new ArrayList(Arrays.asList(events));
    LogUnitList[] logUnitforEventList = new LogUnitList[events.length];
    for (int i = 0; i < events.length; i++) {
        logUnitforEventList[i] = new LogUnitList();
    }

    Iterator it = inputLog.instanceIterator();

    while (it.hasNext()) {
        ProcessInstance pi = (ProcessInstance) it.next();
        Iterator ates = pi.getAuditTrailEntryList().iterator();
        LogUnitList logUnitListforInstance = new LogUnitList();
        while (ates.hasNext()) {
            AuditTrailEntry ate = (AuditTrailEntry) ates.next();
            if (ate.getTimestamp() == null)
                continue;
            event = AbstractLogUnit.create(pi, ate);
            // for instance
            logUnitListforInstance.addEvent(event);
            // for tasks
            if (taskDateMap.get(event.getElement()) == null
                    || taskDateMap.get(event.getElement()).after(ate.getTimestamp())) {
                taskDateMap.remove(event.getElement());
                taskDateMap.put(event.getElement(), ate.getTimestamp());
            }
            if (taskEndDateMap.get(event.getElement()) == null
                    || taskEndDateMap.get(event.getElement()).before(ate.getTimestamp())) {
                taskEndDateMap.remove(event.getElement());
                taskEndDateMap.put(event.getElement(), ate.getTimestamp());
            }

            logUnitforTaskList[taskList.indexOf(event.getElement())].addEvent(event);
            // for events
            if (eventDateMap.get(event.getType()) == null
                    || eventDateMap.get(event.getType()).after(ate.getTimestamp())) {
                eventDateMap.remove(event.getType());
                eventDateMap.put(event.getType(), ate.getTimestamp());
            }
            if (eventEndDateMap.get(event.getType()) == null
                    || eventEndDateMap.get(event.getType()).before(ate.getTimestamp())) {
                eventEndDateMap.remove(event.getType());
                eventEndDateMap.put(event.getType(), ate.getTimestamp());
            }
            logUnitforEventList[eventList.indexOf(event.getType())].addEvent(event);
            // for data elements
            Iterator it2 = ate.getAttributes().keySet().iterator();
            // run through attributes
            while (it2.hasNext()) {
                String tempString = (String) it2.next();
                if (tempString != "") {
                    // add tempString to elts if it is not equal to the
                    // empty String
                    if (dataMap.containsKey(tempString)) {
                        ((LogUnitList) dataMap.get(tempString)).addEvent(event);
                    } else {
                        LogUnitList tempLogUnitList = new LogUnitList(tempString);
                        tempLogUnitList.addEvent(event);
                        dataMap.put(tempString, tempLogUnitList);
                    }
                }
            }
            // for originators
            if (originatorList.indexOf(event.getOriginator()) < 0)
                continue;
            if (originatorDateMap.get(event.getOriginator()) == null
                    || originatorDateMap.get(event.getOriginator()).after(ate.getTimestamp())) {
                originatorDateMap.remove(event.getOriginator());
                originatorDateMap.put(event.getOriginator(), ate.getTimestamp());
            }
            if (originatorEndDateMap.get(event.getOriginator()) == null
                    || originatorEndDateMap.get(event.getOriginator()).before(ate.getTimestamp())) {
                originatorEndDateMap.remove(event.getOriginator());
                originatorEndDateMap.put(event.getOriginator(), ate.getTimestamp());
            }

            logUnitList[originatorList.indexOf(event.getOriginator())].addEvent(event);
        }
        instanceMap.put(pi.getName(), logUnitListforInstance);
    }
    for (int i = 0; i < tasks.length; i++) {
        taskMap.put(tasks[i], logUnitforTaskList[i]);
    }
    for (int i = 0; i < events.length; i++) {
        eventMap.put(events[i], logUnitforEventList[i]);
    }
    for (int i = 0; i < originators.length; i++) {
        originatorMap.put(originators[i], logUnitList[i]);
    }
    sortedKeys = new ArrayList(taskMap.keySet());
}

From source file:com.photon.maven.plugins.android.phase09package.ApkMojo.java

/**
 * Creates the APK file using the internal APKBuilder.
 *
 * @param outputFile/*from w ww .  j a  v a2 s  . co m*/
 *            the output file
 * @param dexFile
 *            the dex file
 * @param zipArchive
 *            the classes folder
 * @param sourceFolders
 *            the resources
 * @param jarFiles
 *            the embedded java files
 * @param nativeFolders
 *            the native folders
 * @param verbose
 *            enables the verbose mode
 * @param signWithDebugKeyStore
 *            enables the signature of the APK using the debug key
 * @param debug
 *            enables the debug mode
 * @throws MojoExecutionException
 *             if the APK cannot be created.
 */
private void doAPKWithAPKBuilder(File outputFile, File dexFile, File zipArchive, ArrayList<File> sourceFolders,
        ArrayList<File> jarFiles, ArrayList<File> nativeFolders, boolean verbose, boolean signWithDebugKeyStore,
        boolean debug) throws MojoExecutionException {

    /* Following line doesn't make any difference if we keep it or comment it
     * Commented By - Viral - Feb 11, 2012
     */
    //      sourceFolders.add(new File(project.getBuild().getDirectory(), "android-classes"));

    for (Artifact artifact : getRelevantCompileArtifacts()) {
        if (extractDuplicates) {
            try {
                computeDuplicateFiles(artifact.getFile());
            } catch (Exception e) {
                getLog().warn("Cannot compute duplicates files from " + artifact.getFile().getAbsolutePath(),
                        e);
            }
        }
        jarFiles.add(artifact.getFile());
    }

    // Check duplicates.
    if (extractDuplicates) {
        List<String> duplicates = new ArrayList<String>();
        List<File> jarToModify = new ArrayList<File>();
        for (String s : m_jars.keySet()) {
            List<File> l = m_jars.get(s);
            if (l.size() > 1) {
                getLog().warn("Duplicate file " + s + " : " + l);
                duplicates.add(s);
                for (int i = 1; i < l.size(); i++) {
                    if (!jarToModify.contains(l.get(i))) {
                        jarToModify.add(l.get(i));
                    }
                }
            }
        }

        // Rebuild jars.
        for (File file : jarToModify) {
            File newJar;
            newJar = removeDuplicatesFromJar(file, duplicates);
            int index = jarFiles.indexOf(file);
            if (newJar != null) {
                jarFiles.set(index, newJar);
            }

        }
    }

    ApkBuilder builder = new ApkBuilder(outputFile, zipArchive, dexFile, signWithDebugKeyStore,
            (verbose) ? System.out : null);

    if (debug) {
        builder.setDebugMode(debug);
    }
    /* Following code block is responsible to make the .apk size almost doubled.
     * Commented By - Viral - Feb 11, 2012
     */
    //      for (File sourceFolder : sourceFolders) {
    //         builder.addSourceFolder(sourceFolder);
    //      }

    for (File jarFile : jarFiles) {
        if (jarFile.isDirectory()) {
            String[] filenames = jarFile.list(new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                    return PATTERN_JAR_EXT.matcher(name).matches();
                }
            });

            for (String filename : filenames) {
                builder.addResourcesFromJar(new File(jarFile, filename));
            }
        } else {
            builder.addResourcesFromJar(jarFile);
        }
    }

    for (File nativeFolder : nativeFolders) {
        builder.addNativeLibraries(nativeFolder, null);
    }

    builder.sealApk();
}