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:oculus.xdataht.clustering.ClusterResults.java

public Map<String, List<ClusterLink>> getConnectivity(Iterable<String> srcClusters,
        Iterable<String> dstClusters, String datasetName, ArrayList<RestLinkCriteria> linkCriteria,
        boolean ignoreCommon) {
    Map<String, List<ClusterLink>> links = new HashMap<String, List<ClusterLink>>();
    Set<String> addedLinks = new HashSet<String>();

    ArrayList<String> allLinkKeys = new ArrayList<String>();
    for (RestLinkCriteria rlc : linkCriteria) {
        for (String attr : rlc.getAttributes()) {
            if (allLinkKeys.indexOf(attr) == -1) {
                allLinkKeys.add(attr);/*from w  w  w .  j av  a  2  s.  c  om*/
            }
        }
    }
    if (allLinkKeys.size() == 0)
        return links;
    DataTable table = TableDB.getInstance().getDataTableColumns(datasetName, allLinkKeys);

    HashMap<String, HashSet<String>> ignoreValues = new HashMap<String, HashSet<String>>();
    if (ignoreCommon) {
        // Create sets of values to ignore (because they are too common) for each linkBy attribute
        for (String key : allLinkKeys) {
            TableDistribution td = TableDB.getInstance().getValueCounts(datasetName, key);
            for (Map.Entry<String, Integer> entry : td.distribution.entrySet()) {
                if (entry.getValue() > 20) {
                    HashSet<String> ignore = ignoreValues.get(key);
                    if (ignore == null) {
                        ignore = new HashSet<String>();
                        ignoreValues.put(key, ignore);
                    }
                    ignore.add(entry.getKey());
                }
            }
        }
    }

    double sum = 0.0;
    for (RestLinkCriteria rlc : linkCriteria) {
        sum += rlc.getWeight();
    }
    HashMap<RestLinkCriteria, Double> normalizedWeights = new HashMap<RestLinkCriteria, Double>();
    for (RestLinkCriteria rlc : linkCriteria) {
        normalizedWeights.put(rlc, rlc.getWeight() / sum);
    }

    for (String srcId : srcClusters) {
        for (String dstId : dstClusters) {

            if (srcId.equals(dstId)) {
                continue;
            }

            // Each set of attributes in the RestLinkCriteria must be true for a pair of clusters to be connected
            // Create a link for each RestLinkCriteria (if they pass the connectivity test)
            for (RestLinkCriteria rlc : linkCriteria) {

                // Make sure we don't double up links
                if (addedLinks.contains(srcId + "-" + dstId + "-" + rlc.getName())
                        || addedLinks.contains(dstId + "-" + srcId + "-" + rlc.getName())) {
                    continue;
                }

                boolean createLink = true;
                for (String attr : rlc.getAttributes()) {
                    int numSharedValues = getCommonPropertyValueCount(table, _clusteringResult.get(srcId),
                            _clusteringResult.get(dstId), attr, ignoreValues.get(attr));
                    if (numSharedValues <= 0) {
                        createLink = false;
                        break;
                    }
                }
                if (createLink) {
                    List<ClusterLink> srcAdjList = links.get(srcId);
                    if (srcAdjList == null) {
                        srcAdjList = new ArrayList<ClusterLink>();
                    }
                    ClusterLink edge = new ClusterLink();
                    edge.linkedClusterId = dstId;
                    edge.clusterLinkAttribute = rlc.getName();
                    edge.weight = normalizedWeights.get(rlc);

                    addedLinks.add(srcId + "-" + dstId + "-" + rlc.getName());

                    srcAdjList.add(edge);
                    links.put(srcId, srcAdjList);
                }
            }
        }
    }
    return links;
}

From source file:nl.systemsgenetics.cellTypeSpecificAlleleSpecificExpression.ReadGenoAndAsFromIndividual.java

/**
 *
 * @param individual_names/*w  w w  . java  2 s.c o m*/
 * @param coupling_location
 * @return
 * @throws FileNotFoundException
 * @throws IOException
 * 
 */

public static HashMap convert_individual_names(String[] individual_names, String coupling_location)
        throws FileNotFoundException, IOException {

    String coupling_loc = coupling_location;

    //This will be filled while reading the file
    ArrayList<String> sample_names_in_file = new ArrayList<String>();
    ArrayList<String> individual_names_in_file = new ArrayList<String>();

    //This will be the one that is later returned
    HashMap ordered_sample_names = new HashMap();

    File coupling_file = new File(coupling_loc);

    FileInputStream fis;
    BufferedInputStream bis;
    DataInputStream dis;

    fis = new FileInputStream(coupling_file);

    // Here BufferedInputStream is added for fast reading.
    bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);

    // dis.available() returns 0 if the file does not have more lines.
    int i = 0;
    while (dis.available() != 0) {

        String[] curr_line = dis.readLine().split("\t");
        individual_names_in_file.add(i, curr_line[0]);
        sample_names_in_file.add(i, curr_line[1]);

        //print the individual al line for checking.
        //System.out.println("line: " + " " + curr_line[0] +" " + curr_line[1] );

    }

    // dispose all the resources after using them.
    fis.close();
    bis.close();
    dis.close();

    i = 0;
    for (String i_name : individual_names) {
        int index = individual_names_in_file.indexOf(i_name);

        if (index >= 0) {
            //We find a name in the genotype folder in the individual names stuff.
            ordered_sample_names.put(sample_names_in_file.get(index), i);
        }
        i++;

    }
    return (ordered_sample_names);

}

From source file:com.objectsecurity.xwiki.objects.classes.SPARQListClass.java

public String returnCol(String hibquery, boolean first) {
    LOG.info("SPARQListClass::returnCol: " + hibquery);
    String firstCol = "-", secondCol = "-";

    int fromIndx = hibquery.indexOf("from");

    if (fromIndx > 0) {
        String firstPart = hibquery.substring(0, fromIndx);
        firstPart.replaceAll("\\s+", " ");
        int comIndx = hibquery.indexOf(",");

        // there are more than one columns to select- take the second one (the value)
        if (comIndx > 0 && comIndx < fromIndx) {
            StringTokenizer st = new StringTokenizer(firstPart, " ,()", true);
            ArrayList<String> words = new ArrayList<String>();

            while (st.hasMoreTokens()) {
                words.add(st.nextToken().toLowerCase());
            }//from   w ww. j a v  a 2 s .  co m

            int comma = words.indexOf(",") - 1;
            while (words.get(comma).toString().compareTo(" ") == 0) {
                comma--;
            }
            firstCol = words.get(comma).toString().trim();

            comma = words.indexOf(",") + 1;
            while (words.get(comma).toString().compareTo(" ") == 0) {
                comma++;
            }

            if (words.get(comma).toString().compareTo("(") == 0) {
                int i = comma + 1;
                while (words.get(i).toString().compareTo(")") != 0) {
                    secondCol += words.get(i).toString();
                    i++;
                }
                secondCol += ")";
            } else {
                secondCol = words.get(comma).toString().trim();
            }
        }
        // has only one column
        else {
            int i = fromIndx - 1;
            while (firstPart.charAt(i) == ' ') {
                --i;
            }
            String col = " ";
            while (firstPart.charAt(i) != ' ') {
                col += firstPart.charAt(i);
                --i;
            }
            String reverse = " ";
            for (i = (col.length() - 1); i >= 0; --i) {
                reverse += col.charAt(i);
            }
            firstCol = reverse.trim();
        }
    }
    if (first == true) {
        return firstCol;
    } else {
        return secondCol;
    }
}

From source file:com.xpn.xwiki.objects.classes.DBListClass.java

public String returnCol(String hibquery, boolean first) {
    String firstCol = "-", secondCol = "-";

    int fromIndx = hibquery.indexOf("from");

    if (fromIndx > 0) {
        String firstPart = hibquery.substring(0, fromIndx);
        firstPart.replaceAll("\\s+", " ");
        int comIndx = hibquery.indexOf(",");

        // there are more than one columns to select- take the second one (the value)
        if (comIndx > 0 && comIndx < fromIndx) {
            StringTokenizer st = new StringTokenizer(firstPart, " ,()", true);
            ArrayList<String> words = new ArrayList<String>();

            while (st.hasMoreTokens()) {
                words.add(st.nextToken().toLowerCase());
            }//from   w  w w  . ja va 2  s.  com

            int comma = words.indexOf(",") - 1;
            while (words.get(comma).toString().compareTo(" ") == 0) {
                comma--;
            }
            firstCol = words.get(comma).toString().trim();

            comma = words.indexOf(",") + 1;
            while (words.get(comma).toString().compareTo(" ") == 0) {
                comma++;
            }

            if (words.get(comma).toString().compareTo("(") == 0) {
                int i = comma + 1;
                while (words.get(i).toString().compareTo(")") != 0) {
                    secondCol += words.get(i).toString();
                    i++;
                }
                secondCol += ")";
            } else {
                secondCol = words.get(comma).toString().trim();
            }
        }
        // has only one column
        else {
            int i = fromIndx - 1;
            while (firstPart.charAt(i) == ' ') {
                --i;
            }
            String col = " ";
            while (firstPart.charAt(i) != ' ') {
                col += firstPart.charAt(i);
                --i;
            }
            String reverse = " ";
            for (i = (col.length() - 1); i >= 0; --i) {
                reverse += col.charAt(i);
            }
            firstCol = reverse.trim();
        }
    }
    if (first == true) {
        return firstCol;
    } else {
        return secondCol;
    }
}

From source file:org.apache.hadoop.hbase.regionserver.compactions.RatioBasedCompactionPolicy.java

private ArrayList<StoreFile> getCurrentEligibleFiles(ArrayList<StoreFile> candidateFiles,
        final List<StoreFile> filesCompacting) {
    // candidates = all storefiles not already in compaction queue
    if (!filesCompacting.isEmpty()) {
        // exclude all files older than the newest file we're currently
        // compacting. this allows us to preserve contiguity (HBASE-2856)
        StoreFile last = filesCompacting.get(filesCompacting.size() - 1);
        int idx = candidateFiles.indexOf(last);
        Preconditions.checkArgument(idx != -1);
        candidateFiles.subList(0, idx + 1).clear();
    }/* w  w  w .  j a  v  a2 s. c o  m*/
    return candidateFiles;
}

From source file:org.ciasaboark.tacere.activity.fragment.MainSettingsFragment.java

private void drawRingerWidgets() {
    RelativeLayout ringerBox = (RelativeLayout) rootView.findViewById(R.id.settings_ringerBox);
    ringerBox.setOnClickListener(new View.OnClickListener() {
        @Override//from w w w  .  j a  v a 2  s. c  o  m
        public void onClick(View v) {
            String[] ringerTypes = RingerType.names();
            //we don't want ringer type UNDEFINED to be an option
            ArrayList<String> ringerList = new ArrayList<String>();
            for (String type : ringerTypes) {
                if (!type.equalsIgnoreCase(RingerType.UNDEFINED.toString())) {
                    type = type.charAt(0) + type.substring(1).toLowerCase();
                    ringerList.add(type);
                }
            }
            final String[] filteredRingerTypes = ringerList.toArray(new String[] {});
            int previouslySelectedRinger = ringerList.indexOf(prefs.getRingerType().toString());

            final AlertDialog alert = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.Dialog))
                    .setTitle(R.string.settings_section_general_ringer)
                    .setSingleChoiceItems(filteredRingerTypes, previouslySelectedRinger,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    String selectedRingerString = filteredRingerTypes[which];
                                    int selectedRingerValue = RingerType
                                            .getIntForStringValue(selectedRingerString);
                                    RingerType selectedRinger = RingerType.getTypeForInt(selectedRingerValue);
                                    prefs.setRingerType(selectedRinger);
                                    drawRingerWidgets();
                                    dialog.dismiss();
                                }
                            })
                    .create();

            alert.show();
        }
    });

    //the ringer type description
    TextView ringerDescriptionTV = (TextView) rootView.findViewById(R.id.ringerTypeDescription);
    TextView ringerTV = (TextView) rootView.findViewById(R.id.settings_ringerTitle);

    Drawable icon;
    switch (prefs.getRingerType()) {
    case NORMAL:
        ringerDescriptionTV.setText(R.string.settings_section_general_ringer_normal);
        icon = getResources().getDrawable(R.drawable.ic_state_normal);
        break;
    case VIBRATE:
        ringerDescriptionTV.setText(R.string.settings_section_general_ringer_vibrate);
        icon = getResources().getDrawable(R.drawable.ic_state_vibrate);
        break;
    case SILENT:
        ringerDescriptionTV.setText(R.string.settings_section_general_ringer_silent);
        icon = getResources().getDrawable(R.drawable.ic_state_silent);
        break;
    case IGNORE:
        ringerDescriptionTV.setText(R.string.settings_section_general_ringer_ignore);
        icon = getResources().getDrawable(R.drawable.ic_state_ignore);
        break;
    default:
        throw new IllegalStateException("Saved default ringer is of unknown type: " + prefs.getRingerType());
    }

    int iconColor = getResources().getColor(R.color.icon_tint);
    icon.mutate().setColorFilter(iconColor, PorterDuff.Mode.MULTIPLY);
    ringerDescriptionTV.setTextColor(getResources().getColor(R.color.text_color));
    ringerTV.setTextColor(getResources().getColor(R.color.text_color));

    ImageView ringerIcon = (ImageView) rootView.findViewById(R.id.settings_ringerIcon);
    ringerIcon.setImageDrawable(icon);
}

From source file:com.almende.eve.agent.example.ChatAgent.java

/**
 * connect two agents with each other./*from   w  w  w .j a  v a  2 s  .  com*/
 *
 * @param url Url of an ChatAgent
 * @throws JSONRPCException the jSONRPC exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void connect(@Name("url") final String url) throws JSONRPCException, IOException {
    boolean otherAlreadyConnected = false;
    final ArrayList<String> newConnections = new ArrayList<String>();
    final ArrayList<String> otherConnections = send(URI.create(url), "getConnections",
            JOM.getTypeFactory().constructArrayType(String.class));

    // get my own connections from the state
    final String urlSelf = getMyUrl();
    ArrayList<String> connections = getState().get("connections", new TypeUtil<ArrayList<String>>() {
    });
    if (connections == null) {
        connections = new ArrayList<String>();
    }

    for (int i = 0; i < otherConnections.size(); i++) {
        final String connection = otherConnections.get(i);
        if (!connection.equals(urlSelf)) {
            // this agent is not me
            if (connections.indexOf(connection) == -1) {
                // this is an agent that I didn't knew before
                connections.add(connection);
                newConnections.add(connection);

                // trigger a "connected" event
                final ObjectNode params = JOM.createObjectNode();
                params.put("url", connection);
                getEventsFactory().trigger("connected", params);

                log(getUsername() + " connected to " + connection);
            }
        } else {
            // this agent is me. So, the other agent already knows me
            // (-> thus I don't have to connect to him again)
            otherAlreadyConnected = true;
        }
    }

    // add the agent that triggered the connect
    if (connections.indexOf(url) == -1) {
        connections.add(url);

        // trigger a "connected" event
        final ObjectNode params = JOM.createObjectNode();
        params.put("url", url);
        getEventsFactory().trigger("connected", params);

        log(getUsername() + " connected to " + url);
    }
    if (!otherAlreadyConnected) {
        // the other agent doesn't know me
        newConnections.add(url);
    }

    // store the connection list
    getState().put("connections", connections);

    // schedule tasks to connect to all newly connected agents
    for (final String connection : newConnections) {
        final ObjectNode params = JOM.createObjectNode();
        params.put("url", urlSelf);
        send(URI.create(connection), "connect", params);
    }
}

From source file:org.openmrs.module.accessmonitor.web.controller.AccessMonitorOrderController.java

@RequestMapping(value = "/module/accessmonitor/order", method = RequestMethod.POST)
public void postSave(ModelMap model, HttpServletRequest request) throws IOException {

    if (request.getParameter("offset") != null) {
        offset = Integer.parseInt(request.getParameter("offset"));
    }/*from  www  .  j  a v a2 s  .c o m*/
    int count = -1;
    // parse them to Date, null is acceptable
    DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
    // Get the from date and to date
    Date to = null;
    Date from = null;
    try {
        from = format.parse(request.getParameter("datepickerFrom"));
    } catch (Exception e) {
        //System.out.println("======From Date Empty=======");
    }
    try {
        to = format.parse(request.getParameter("datepickerTo"));
    } catch (Exception e) {
        //System.out.println("======To Date Empty=======");
    }

    if (orderAccessData == null || orderAccessData.size() == 0) {
        // get all the records in the date range
        orderAccessData = ((OrderAccessService) Context.getService(OrderAccessService.class))
                .getOrderAccessesByAccessDateOrderByPatientId(from, to);
        if (orderAccessData == null) {
            orderAccessData = new ArrayList<OrderServiceAccess>();
        }
    }

    // get date for small graph
    Date toSmall = to;
    Date fromSmall = null;
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1);
    if (toSmall == null) {
        toSmall = calendar.getTime();
    } else {
        calendar.setTime(toSmall);
    }
    calendar.add(Calendar.DATE, -DAYNUM);
    fromSmall = calendar.getTime();

    List<String> dateStrings = new ArrayList<String>();
    for (int i = 0; i < DAYNUM; i++) {
        if (i == DAYNUM - 1) {
            dateStrings.add(format.format(toSmall));
        } else if (i == 0) {
            dateStrings.add(format.format(fromSmall));
        } else {
            dateStrings.add("");
        }
    }

    ArrayList<ArrayList<Integer>> tooltip = new ArrayList<ArrayList<Integer>>();
    tooltip.add(new ArrayList<Integer>());
    for (int j = 0; j < SHOWNUM + 1; j++) {
        tooltip.get(0).add(1000 + j);
    }
    for (int i = 1; i < DAYNUM + 1; i++) {
        tooltip.add(new ArrayList<Integer>());
        tooltip.get(i).add(i);
        for (int j = 0; j < SHOWNUM; j++) {
            tooltip.get(i).add(0);
        }
    }

    ArrayList<String> patientIds = new ArrayList<String>();
    ArrayList<Integer> patientCounts = new ArrayList<Integer>();
    String last = "";
    for (OrderServiceAccess oa : orderAccessData) {
        // data for big graph
        String idString = (oa.getPatientId() == null) ? "No ID" : oa.getPatientId().toString();
        if (!idString.equals(last)) {
            count++;
            last = idString;
        }
        int index = patientIds.indexOf(idString);
        if (index < 0) {
            if (count < offset)
                continue;
            if (patientIds.size() >= SHOWNUM)
                break;
            patientIds.add(idString);
            patientCounts.add(1);
            index = patientIds.size() - 1;//index = personIds.indexOf(idString);
        } else {
            patientCounts.set(index, patientCounts.get(index) + 1);
        }
        // data for small graph
        if (oa.getAccessDate().after(fromSmall) && oa.getAccessDate().before(toSmall)) {
            int index2 = (int) ((oa.getAccessDate().getTime() - fromSmall.getTime()) / (1000 * 60 * 60 * 24));
            if (index2 < DAYNUM && index2 >= 0)
                tooltip.get(index2 + 1).set(index + 1, tooltip.get(index2 + 1).get(index + 1) + 1);
        }
    }
    String patientIdString = JSONValue.toJSONString(patientIds);
    String patientCountString = JSONValue.toJSONString(patientCounts);
    String dateSmallString = JSONValue.toJSONString(dateStrings);
    String tooltipdata = JSONValue.toJSONString(tooltip);
    model.addAttribute("patientIds", patientIdString);
    model.addAttribute("patientCounts", patientCountString);
    model.addAttribute("dateSmallString", dateSmallString);
    model.addAttribute("tooltipdata", tooltipdata);

    model.addAttribute("user", Context.getAuthenticatedUser());
    //model.addAttribute("tables1", orderAccessData);
    //model.addAttribute("dateSmall", dateStrings);
    model.addAttribute("currentoffset", String.valueOf(offset));
}

From source file:org.openmrs.module.accessmonitor.web.controller.AccessMonitorPersonController.java

@RequestMapping(value = "/module/accessmonitor/person", method = RequestMethod.POST)
public void postSave(ModelMap model, HttpServletRequest request) throws IOException {

    if (request.getParameter("offset") != null) {
        offset = Integer.parseInt(request.getParameter("offset"));
    }/*  w  ww.java 2  s . c om*/
    int count = -1;
    // parse them to Date, null is acceptabl
    DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
    // Get the from date and to date
    Date to = null;
    Date from = null;
    try {
        from = format.parse(request.getParameter("datepickerFrom"));
    } catch (Exception e) {
        //System.out.println("======From Date Empty=======");
    }
    try {
        to = format.parse(request.getParameter("datepickerTo"));
    } catch (Exception e) {
        //System.out.println("======To Date Empty=======");
    }

    // get all the records in the date range
    if (personAccessData == null || personAccessData.size() == 0) {
        personAccessData = ((PersonAccessService) Context.getService(PersonAccessService.class))
                .getPersonAccessesByAccessDateOrderByPersonId(from, to);
        if (personAccessData == null) {
            personAccessData = new ArrayList<PersonServiceAccess>();
        }
    }

    // get date for small graph
    Date toSmall = to;
    Date fromSmall = null;
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1);
    if (toSmall == null) {
        toSmall = calendar.getTime();
    } else {
        calendar.setTime(toSmall);
    }
    calendar.add(Calendar.DATE, -DAYNUM);
    fromSmall = calendar.getTime();

    List<String> dateStrings = new ArrayList<String>();
    for (int i = 0; i < DAYNUM; i++) {
        if (i == DAYNUM - 1) {
            dateStrings.add(format.format(toSmall));
        } else if (i == 0) {
            dateStrings.add(format.format(fromSmall));
        } else {
            dateStrings.add("");
        }
    }

    ArrayList<ArrayList<Integer>> tooltip = new ArrayList<ArrayList<Integer>>();
    tooltip.add(new ArrayList<Integer>());
    for (int j = 0; j < SHOWNUM + 1; j++) {
        tooltip.get(0).add(1000 + j);
    }
    for (int i = 1; i < DAYNUM + 1; i++) {
        tooltip.add(new ArrayList<Integer>());
        tooltip.get(i).add(i);
        for (int j = 0; j < SHOWNUM; j++) {
            tooltip.get(i).add(0);
        }
    }

    ArrayList<String> personIds = new ArrayList<String>();
    ArrayList<Integer> personCounts = new ArrayList<Integer>();
    String last = "";
    for (PersonServiceAccess pa : personAccessData) {
        // data for big graph
        String idString = (pa.getPersonId() == null) ? "No ID" : pa.getPersonId().toString();
        if (!idString.equals(last)) {
            count++;
            last = idString;
        }
        int index = personIds.indexOf(idString);
        if (index < 0) {
            if (count < offset)
                continue;
            if (personIds.size() >= SHOWNUM)
                break;
            personIds.add(idString);
            personCounts.add(1);
            index = personIds.size() - 1;//index = personIds.indexOf(idString);
        } else {
            personCounts.set(index, personCounts.get(index) + 1);
        }
        // data for small graph
        if (pa.getAccessDate().after(fromSmall) && pa.getAccessDate().before(toSmall)) {
            int index2 = (int) ((pa.getAccessDate().getTime() - fromSmall.getTime()) / (1000 * 60 * 60 * 24));
            if (index2 < DAYNUM && index2 >= 0)
                tooltip.get(index2 + 1).set(index + 1, tooltip.get(index2 + 1).get(index + 1) + 1);
        }
    }
    String personIdString = JSONValue.toJSONString(personIds);
    String personCountString = JSONValue.toJSONString(personCounts);
    String dateSmallString = JSONValue.toJSONString(dateStrings);
    String tooltipdata = JSONValue.toJSONString(tooltip);
    model.addAttribute("personIds", personIdString);
    model.addAttribute("personCounts", personCountString);
    model.addAttribute("dateSmallString", dateSmallString);
    model.addAttribute("tooltipdata", tooltipdata);

    model.addAttribute("user", Context.getAuthenticatedUser());
    //model.addAttribute("tables1", personAccessData);
    //model.addAttribute("dateSmall", dateStrings);
    model.addAttribute("currentoffset", String.valueOf(offset));

}

From source file:org.openmrs.module.accessmonitor.web.controller.AccessMonitorVisitController.java

@RequestMapping(value = "/module/accessmonitor/visit", method = RequestMethod.POST)
public void postSave(ModelMap model, HttpServletRequest request) throws IOException {

    if (request.getParameter("offset") != null) {
        offset = Integer.parseInt(request.getParameter("offset"));
    }//from w w w. ja  v a 2s  .  c  om
    int count = -1;
    // parse them to Date, null is acceptabl
    DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
    // Get the from date and to date
    Date to = null;
    Date from = null;
    try {
        from = format.parse(request.getParameter("datepickerFrom"));
    } catch (Exception e) {
        //System.out.println("======From Date Empty=======");
    }
    try {
        to = format.parse(request.getParameter("datepickerTo"));
    } catch (Exception e) {
        //System.out.println("======To Date Empty=======");
    }

    if (visitAccessData == null || visitAccessData.size() == 0) {
        // get all the records in the date range
        visitAccessData = ((VisitAccessService) Context.getService(VisitAccessService.class))
                .getVisitAccessesByAccessDateOrderByPatientId(from, to);
        if (visitAccessData == null) {
            visitAccessData = new ArrayList<VisitServiceAccess>();
        }
    }

    // get date for small graph
    Date toSmall = to;
    Date fromSmall = null;
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1);
    if (toSmall == null) {
        toSmall = calendar.getTime();
    } else {
        calendar.setTime(toSmall);
    }
    calendar.add(Calendar.DATE, -DAYNUM);
    fromSmall = calendar.getTime();

    List<String> dateStrings = new ArrayList<String>();
    for (int i = 0; i < DAYNUM; i++) {
        if (i == DAYNUM - 1) {
            dateStrings.add(format.format(toSmall));
        } else if (i == 0) {
            dateStrings.add(format.format(fromSmall));
        } else {
            dateStrings.add("");
        }
    }

    ArrayList<ArrayList<Integer>> tooltip = new ArrayList<ArrayList<Integer>>();
    tooltip.add(new ArrayList<Integer>());
    for (int j = 0; j < SHOWNUM + 1; j++) {
        tooltip.get(0).add(1000 + j);
    }
    for (int i = 1; i < DAYNUM + 1; i++) {
        tooltip.add(new ArrayList<Integer>());
        tooltip.get(i).add(i);
        for (int j = 0; j < SHOWNUM; j++) {
            tooltip.get(i).add(0);
        }
    }

    ArrayList<String> patientIds = new ArrayList<String>();
    ArrayList<Integer> patientCounts = new ArrayList<Integer>();
    String last = "";
    for (VisitServiceAccess va : visitAccessData) {
        // data for big graph
        String idString = (va.getPatientId() == null) ? "No ID" : va.getPatientId().toString();
        if (!idString.equals(last)) {
            count++;
            last = idString;
        }
        int index = patientIds.indexOf(idString);
        if (index < 0) {
            if (count < offset)
                continue;
            if (patientIds.size() >= SHOWNUM)
                break;
            patientIds.add(idString);
            patientCounts.add(1);
            index = patientIds.size() - 1;//index = patientIds.indexOf(idString);
        } else {
            patientCounts.set(index, patientCounts.get(index) + 1);
        }
        // data for small graph
        if (va.getAccessDate().after(fromSmall) && va.getAccessDate().before(toSmall)) {
            int index2 = (int) ((va.getAccessDate().getTime() - fromSmall.getTime()) / (1000 * 60 * 60 * 24));
            if (index2 < DAYNUM && index2 >= 0)
                tooltip.get(index2 + 1).set(index + 1, tooltip.get(index2 + 1).get(index + 1) + 1);
        }
    }
    String patientIdString = JSONValue.toJSONString(patientIds);
    String patientCountString = JSONValue.toJSONString(patientCounts);
    String dateSmallString = JSONValue.toJSONString(dateStrings);
    String tooltipdata = JSONValue.toJSONString(tooltip);
    model.addAttribute("patientIds", patientIdString);
    model.addAttribute("patientCounts", patientCountString);
    model.addAttribute("dateSmallString", dateSmallString);
    model.addAttribute("tooltipdata", tooltipdata);

    model.addAttribute("user", Context.getAuthenticatedUser());
    //        model.addAttribute("tables1", visitAccessData);
    //        model.addAttribute("dateSmall", dateStrings);
    model.addAttribute("currentoffset", String.valueOf(offset));

}