Example usage for java.util SortedMap toString

List of usage examples for java.util SortedMap toString

Introduction

In this page you can find the example usage for java.util SortedMap toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:de.khiem.offsite.tree.tri.Main.java

void search(PatriciaTrie<O> t, String k) {
    O e = t.get(k);//  w  w  w  . ja v  a  2  s .com
    if (e == null) {
        System.out.println(k + " not found");
    } else {
        System.out.println("found " + e.toString());
        String childrenPref = k + ".";
        SortedMap m = t.prefixMap(childrenPref); // tailMap(k);
        System.out.println("prefixmap(children) of  " + k + ":" + m.toString());
        //            SortedMap m2 = t.headMap(k);
        //            System.out.println("headmap of  " + k + ":" + m2.toString());                     
    }
}

From source file:com.gtwm.pb.model.manageData.DataManagement.java

public String getReportCalendarJSON(AppUserInfo user, BaseReportInfo report,
        Map<BaseField, String> filterValues, Long startEpoch, Long endEpoch)
        throws CodingErrorException, CantDoThatException, SQLException, JsonGenerationException {
    ReportFieldInfo eventDateReportField = report.getCalendarStartField();
    if (eventDateReportField == null) {
        throw new CantDoThatException("The report '" + report + "' has no suitable date field");
    }/*w w  w . j  a va 2 s.  co  m*/
    ReportFieldInfo endDateReportField = report.getCalendarEndField();
    // Try cache first
    // Make a sortedMap so toString is always consistent for the same
    // key/value pairs and we can use it as an ID
    SortedMap<BaseField, String> sortedFilterValues = new TreeMap<BaseField, String>(filterValues);
    String id = report.getInternalReportName() + sortedFilterValues.toString();
    CachedReportFeedInfo cachedJSON = cachedCalendarJSONs.get(id);
    if (cachedJSON != null) {
        this.calendarJsonCacheHits.incrementAndGet();
        // Note: if we choose not to invalidate the cache on every data
        // change, we could return only JSON that was newer than a certain
        // time here, say the last data change time plus ten secs
        return cachedJSON.getFeed();
    }
    String dateFieldInternalName = eventDateReportField.getInternalFieldName();
    int dateResolution = 0;
    if (eventDateReportField instanceof ReportCalcFieldInfo) {
        dateResolution = ((ReportCalcFieldInfo) eventDateReportField).getDateResolution();
    } else {
        BaseField eventDateBaseField = eventDateReportField.getBaseField();
        DateField eventDateField = (DateField) eventDateBaseField;
        dateResolution = eventDateField.getDateResolution();
    }
    boolean allDayValues = true;
    if (dateResolution > Calendar.DAY_OF_MONTH) {
        allDayValues = false;
    }
    List<DataRowInfo> reportDataRows = this.getReportDataRows(user.getCompany(), report, filterValues, false,
            new HashMap<BaseField, Boolean>(0), 10000, QuickFilterType.AND, false);
    JsonFactory jsonFactory = new JsonFactory();
    StringWriter stringWriter = new StringWriter(1024);
    JsonGenerator jg;
    try {
        jg = jsonFactory.createJsonGenerator(stringWriter);
        jg.writeStartArray();
        String internalReportName = report.getInternalReportName();
        String internalTableName = report.getParentTable().getInternalTableName();
        ROWS_LOOP: for (DataRowInfo reportDataRow : reportDataRows) {
            DataRowFieldInfo eventDateValue = reportDataRow.getValue(eventDateReportField);
            if (eventDateValue.getKeyValue().equals("")) {
                continue ROWS_LOOP;
            }
            jg.writeStartObject();
            jg.writeStringField("id", internalReportName + "_" + reportDataRow.getRowId());
            jg.writeStringField("internalTableName", internalTableName);
            jg.writeNumberField("rowId", reportDataRow.getRowId());
            boolean allDayEvent = allDayValues;
            if (!allDayValues) {
                String eventDateDisplayValue = eventDateValue.getDisplayValue();
                // TODO: trim may not be necessary
                if (eventDateDisplayValue.trim().endsWith("00:00")) {
                    allDayEvent = true;
                }
            }
            jg.writeBooleanField("allDay", allDayEvent);
            // fullcalendar needs the number of seconds since the epoch
            Long eventDateEpoch = Long.parseLong(eventDateValue.getKeyValue()) / 1000;
            jg.writeNumberField("start", eventDateEpoch);
            if (!allDayEvent) {
                if (endDateReportField.equals(eventDateReportField)) {
                    jg.writeNumberField("end", eventDateEpoch + 3600);
                } else {
                    DataRowFieldInfo endDateValue = reportDataRow.getValue(endDateReportField);
                    String endDateEpochString = endDateValue.getKeyValue();
                    if (endDateEpochString.equals("")) {
                        // events last 1 hr by default
                        jg.writeNumberField("end", eventDateEpoch + 3600);
                    } else {
                        Long endDateEpoch = Long.parseLong(endDateValue.getKeyValue()) / 1000;
                        if (endDateEpoch > eventDateEpoch) {
                            jg.writeNumberField("end", endDateEpoch);
                        } else {
                            jg.writeNumberField("end", eventDateEpoch + 3600);
                        }
                    }
                }
            } else if (!endDateReportField.equals(eventDateReportField)) {
                // all day event possibly spans multiple days
                DataRowFieldInfo endDateValue = reportDataRow.getValue(endDateReportField);
                String endDateEpochString = endDateValue.getKeyValue();
                if (!endDateEpochString.equals("")) {
                    Long endDateEpoch = Long.parseLong(endDateValue.getKeyValue()) / 1000;
                    if (endDateEpoch > eventDateEpoch) {
                        jg.writeNumberField("end", endDateEpoch);
                    }
                }
            }
            jg.writeStringField("className", "report_" + internalReportName); // fullcalendar
            // TODO: check if classname is used in UI, remove if not
            jg.writeStringField("classname", "report_" + internalReportName);
            jg.writeStringField("dateFieldInternalName", dateFieldInternalName);
            String eventTitle = buildEventTitle(report, reportDataRow, false);
            jg.writeStringField("title", eventTitle);
            jg.writeEndObject();
        }
        jg.writeEndArray();
        jg.flush();
        jg.close();
    } catch (IOException e) {
        throw new CodingErrorException("StringWriter produced an IO exception: " + e);
    }
    UsageLogger usageLogger = new UsageLogger(this.dataSource);
    usageLogger.logReportView(user, report, filterValues, 10000, "getCalendarJSON");
    UsageLogger.startLoggingThread(usageLogger);
    String json = stringWriter.toString();
    cachedJSON = new CachedFeed(json);
    cachedCalendarJSONs.put(id, cachedJSON);
    int cacheMisses = this.calendarJsonCacheMisses.incrementAndGet();
    if (cacheMisses > 100) {
        logger.info("JSON cache hits: " + this.calendarJsonCacheHits + ", misses " + cacheMisses);
        this.calendarJsonCacheHits.set(0);
        this.calendarJsonCacheMisses.set(0);
    }
    return json;
}

From source file:com.gtwm.pb.model.manageData.DataManagement.java

public String getReportTimelineJSON(AppUserInfo user, Set<BaseReportInfo> reports,
        Map<BaseField, String> filterValues)
        throws CodingErrorException, CantDoThatException, SQLException, JsonGenerationException {
    String id = "";
    SortedMap<BaseField, String> sortedFilterValues = new TreeMap<BaseField, String>(filterValues);
    for (BaseReportInfo report : reports) {
        ReportFieldInfo eventDateReportField = report.getCalendarStartField();
        if (eventDateReportField == null) {
            throw new CantDoThatException("The report '" + report + "' has no suitable date field");
        }/*from  w  w w  . j  a  va 2s .  co m*/
        id += report.getInternalReportName();
    }
    id += sortedFilterValues.toString();
    CachedReportFeedInfo cachedJSON = cachedCalendarJSONs.get(id);
    if (cachedJSON != null) {
        this.calendarJsonCacheHits.incrementAndGet();
        // Note: if we choose not to invalidate the cache on every data
        // change, we could return only JSON that was newer than a certain
        // time here, say the last data change time plus ten secs
        return cachedJSON.getFeed();
    }
    // RFC 2822 date format used by Simile timeline
    DateFormat dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
    UsageLogger usageLogger = new UsageLogger(this.dataSource);
    JsonFactory jsonFactory = new JsonFactory();
    StringWriter stringWriter = new StringWriter(1024);
    JsonGenerator jg;
    try {
        jg = jsonFactory.createJsonGenerator(stringWriter);
        jg.writeStartObject();
        jg.writeArrayFieldStart("events");
        for (BaseReportInfo report : reports) {
            String className = "report_" + report.getInternalReportName();
            ReportFieldInfo eventDateReportField = report.getCalendarStartField();
            List<DataRowInfo> reportDataRows = this.getReportDataRows(user.getCompany(), report, filterValues,
                    false, new HashMap<BaseField, Boolean>(0), 10000, QuickFilterType.AND, false);
            ROWS_LOOP: for (DataRowInfo reportDataRow : reportDataRows) {
                DataRowFieldInfo eventDateValue = reportDataRow.getValue(eventDateReportField);
                if (eventDateValue.getKeyValue().equals("")) {
                    continue ROWS_LOOP;
                }
                jg.writeStartObject();
                // timeline needs formatted dates
                Long eventDateEpoch = Long.parseLong(eventDateValue.getKeyValue());
                // String formattedDate = dateFormatter.format(new
                // Date(eventDateEpoch));
                jg.writeStringField("start", "new Date(" + eventDateEpoch + ")");
                String eventTitle = eventDateValue.getDisplayValue() + ": "
                        + buildEventTitle(report, reportDataRow, false);
                jg.writeStringField("caption", eventTitle);
                jg.writeStringField("description", eventTitle);
                // TODO: build short title from long title, don't rebuild
                // from
                // scratch. Just cut off everything after the 5th comma for
                // example
                String shortTitle = buildEventTitle(report, reportDataRow, true);
                jg.writeStringField("classname", className);
                jg.writeEndObject();
            }
            usageLogger.logReportView(user, report, filterValues, 10000, "getTimelineJSON");
            UsageLogger.startLoggingThread(usageLogger);
        }
        jg.writeEndArray();
        jg.writeEndObject();
        jg.flush();
        jg.close();
    } catch (IOException e) {
        throw new CodingErrorException("StringWriter produced an IO exception: " + e);
    }
    String json = stringWriter.toString();
    cachedJSON = new CachedFeed(json);
    cachedCalendarJSONs.put(id, cachedJSON);
    int cacheMisses = this.calendarJsonCacheMisses.incrementAndGet();
    if (cacheMisses > 100) {
        logger.info("Calendar JSON cache hits: " + this.calendarJsonCacheHits + ", misses " + cacheMisses);
        this.calendarJsonCacheHits.set(0);
        this.calendarJsonCacheMisses.set(0);
    }
    return json;
}

From source file:org.jahia.services.render.filter.cache.QueryStringCacheKeyPartGenerator.java

@Override
public String replacePlaceholders(RenderContext renderContext, String keyPart) {
    Map parameterMap = renderContext.getRequest().getParameterMap();
    if (!parameterMap.isEmpty()) {
        Matcher m = QUERYSTRING_REGEXP.matcher(keyPart);
        if (m.matches()) {
            String qsString = m.group(2);
            String[] params = Patterns.COMMA.split(m.group(3));

            SortedMap<String, String> qs = new TreeMap<String, String>();
            for (String param : params) {
                param = param.trim();/*from   ww w . ja  v  a 2  s.  co m*/
                if (param.endsWith("*")) {
                    param = param.substring(0, param.length() - 1);
                    for (Map.Entry o : (Iterable<? extends Map.Entry>) parameterMap.entrySet()) {
                        String k = (String) o.getKey();
                        if (k.startsWith(param)) {
                            qs.put(k, Arrays.toString((String[]) o.getValue()));
                        }
                    }
                } else if (parameterMap.containsKey(param)) {
                    qs.put(param, Arrays.toString((String[]) parameterMap.get(param)));
                }
            }
            keyPart = keyPart.replace(qsString, qs.toString());
        }
        return keyPart;
    }
    return "{}";
}