Example usage for java.lang Comparable toString

List of usage examples for java.lang Comparable toString

Introduction

In this page you can find the example usage for java.lang Comparable toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.newatlanta.bluedragon.PieURLGenerator.java

/**
 * Generates a URL.//ww w .j  av a 2  s. c  o  m
 *
 * @param data  the dataset.
 * @param key  the item key.
 * @param pieIndex  the pie index (ignored).
 *
 * @return A string containing the generated URL.
 */
@SuppressWarnings("deprecation")
public String generateURL(PieDataset data, Comparable key, int pieIndex) {

    String categoryKey = key.toString();
    Number numberValue = data.getValue(key);
    String value;
    if (numberValue == null)
        value = "";
    else if (dateFormat != null)
        value = this.dateFormat.format(numberValue);
    else
        value = this.numberFormat.format(numberValue);

    StringBuilder generatedURL = new StringBuilder(urlLower.length());
    for (int i = 0; i < urlLower.length();) {
        char ch = urlLower.charAt(i);
        if (ch == '$') {
            if (urlLower.regionMatches(i, "$serieslabel$", 0, "$serieslabel$".length())) {
                generatedURL.append("");
                i = i + "$serieslabel$".length();
            } else if (urlLower.regionMatches(i, "$itemlabel$", 0, "$itemlabel$".length())) {
                generatedURL.append(URLEncoder.encode(categoryKey));
                i = i + "$itemlabel$".length();
            } else if (urlLower.regionMatches(i, "$value$", 0, "$value$".length())) {
                generatedURL.append(URLEncoder.encode(value));
                i = i + "$value$".length();
            } else {
                // Preserve case by retrieving char from original URL
                generatedURL.append(url.charAt(i));
                i++;
            }
        } else {
            // Preserve case by retrieving char from original URL
            generatedURL.append(url.charAt(i));
            i++;
        }
    }
    return generatedURL.toString();
}

From source file:org.fhaes.fhrecorder.util.NumericCategoryAxis.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//from   w w  w .  j a v  a2  s  .c om
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {

    List ticks = new java.util.ArrayList();

    // sanity check for data area...
    if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) {
        return ticks;
    }

    CategoryPlot plot = (CategoryPlot) getPlot();
    List categories = plot.getCategoriesForAxis(this);
    double max = 0.0;

    if (categories != null) {
        CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge);
        float r = this.getMaximumCategoryLabelWidthRatio();
        if (r <= 0.0) {
            r = position.getWidthRatio();
        }

        float l = 0.0f;
        if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) {
            l = (float) calculateCategorySize(categories.size(), dataArea, edge);
        } else {
            if (RectangleEdge.isLeftOrRight(edge)) {
                l = (float) dataArea.getWidth();
            } else {
                l = (float) dataArea.getHeight();
            }
        }
        int categoryIndex = 0;
        Iterator iterator = categories.iterator();
        while (iterator.hasNext()) {
            Comparable category = (Comparable) iterator.next();

            try {
                Integer intcategory = Integer.valueOf(category.toString());

                int modulus = intcategory % labelEveryXCategories;

                if (modulus != 0)
                    category = " ";

            } catch (NumberFormatException e) {

            }

            TextBlock label = createLabel(category, l * r, edge, g2);
            if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
                max = Math.max(max, calculateTextBlockHeight(label, position, g2));
            } else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
                max = Math.max(max, calculateTextBlockWidth(label, position, g2));
            }
            Tick tick = new CategoryTick(category, label, position.getLabelAnchor(),
                    position.getRotationAnchor(), position.getAngle());
            ticks.add(tick);
            categoryIndex = categoryIndex + 1;
        }
    }
    state.setMax(max);
    return ticks;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.utils.MyCategoryToolTipGenerator.java

public String generateToolTip(CategoryDataset dataset, int row, int column) {
    logger.debug("IN");
    //String tooltip=super.generateToolTip(dataset, row, column);
    String rowName = "";
    String columnName = "";
    try {// w ww  . j  a va  2s .  c  o  m
        Comparable rowNameC = (String) dataset.getRowKey(row);
        Comparable columnNameC = (String) dataset.getColumnKey(column);
        if (rowNameC != null)
            rowName = rowNameC.toString();
        if (columnNameC != null)
            columnName = columnNameC.toString();

    } catch (Exception e) {
        logger.error("error in recovering name of row and column");
        return "undef";
    }

    // check if there is a predefined FREETIP message
    if (enableFreeTip == true) {
        if (categoriesToolTips.get("FREETIP_X_" + columnName) != null) {
            String freeName = categoriesToolTips.get("FREETIP_X_" + columnName);
            return freeName;
        }
    }

    String columnTipName = columnName;
    String rowTipName = rowName;
    // check if tip name are defined, else use standard
    if (categoriesToolTips.get("TIP_X_" + columnName) != null) {
        columnTipName = categoriesToolTips.get("TIP_X_" + columnName);
    }
    // search for series, if seriesCaption has a relative value use it! 
    String serieNameToSearch = null;
    if (seriesCaption != null) {
        serieNameToSearch = seriesCaption.get(rowName);
    }
    if (serieNameToSearch == null)
        serieNameToSearch = rowName;

    if (serieToolTips.get("TIP_" + serieNameToSearch) != null) {
        rowTipName = serieToolTips.get("TIP_" + serieNameToSearch);
    }

    Number num = dataset.getValue(row, column);
    String numS = (num != null) ? " = " + num.toString() : "";
    String toReturn = "(" + columnTipName + ", " + rowTipName + ")" + numS;

    logger.debug("OUT");
    return toReturn;

}

From source file:org.jboss.weld.benchmark.charts.Chart.java

/**
 * Saving a chart to hard disk as png image
 *
 * @param path absolute path/*from  w  w  w  .j  ava  2 s .  c  o m*/
 * @return true if no errors occurred
 */
public Boolean saveImageTo(String path) {
    try {
        JFreeChart lineChartObject = ChartFactory.createBarChart(NAME, X_AXIS_NAME, Y_AXIS_NAME,
                lineChartDataset, PlotOrientation.VERTICAL, true, true, false);

        CategoryPlot plot = (CategoryPlot) lineChartObject.getPlot();

        plot.setDomainAxis(new CategoryAxis() {
            private static final long serialVersionUID = 1L;

            @Override
            protected TextBlock createLabel(@SuppressWarnings("rawtypes") Comparable category, float width,
                    RectangleEdge edge, Graphics2D g2) {
                TextBlock label = TextUtilities.createTextBlock(category.toString(), getTickLabelFont(category),
                        getTickLabelPaint(category), ONE_PART_WIDTH - 30, 2, new G2TextMeasurer(g2));

                label.setLineAlignment(HorizontalAlignment.LEFT);
                return label;
            }
        });

        File lineChart = new File(path, NAME + ".png");
        ChartUtilities.saveChartAsPNG(lineChart, lineChartObject,
                ONE_PART_WIDTH * lineChartDataset.getColumnCount(), GRAPH_HEIGHT);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:org.cyberoam.iview.charts.CustomDomainAxis.java

protected TextBlock createLabel(Comparable category, float width, RectangleEdge edge, Graphics2D g2) {
    CustomDomainAxis.counter++;//from  w  ww  . j av  a  2  s  .c om
    String domainLabel = category.toString();
    int tempcounter = counter - colCount;
    if (colCount % 2 == 1) {
        if ((tempcounter == 1) || (tempcounter == (colCount / 4) + 1) || (tempcounter == (colCount / 2) + 1)
                || (tempcounter == (3 * colCount / 4) + 1) || (tempcounter == colCount)) {
            domainLabel = domainLabel.substring(0, domainLabel.toString().length() - 3);
        } else {
            domainLabel = "";
        }
    } else {
        if ((tempcounter == 1) || (tempcounter == (colCount / 4)) || (tempcounter == (colCount / 2))
                || (tempcounter == (3 * colCount / 4)) || (tempcounter == colCount)) {
            domainLabel = domainLabel.substring(0, domainLabel.toString().length() - 3);
        } else {
            domainLabel = "";
        }
    }
    return super.createLabel(domainLabel, width, edge, g2);
}

From source file:com.itemanalysis.psychometrics.irt.estimation.ItemResponseFileSummary.java

private ItemResponseVector[] readTapData() {
    byte[][] tap = new byte[35][18];
    try {//from   ww w  .  j  a  v a  2s . c  om
        File f = FileUtils.toFile(this.getClass().getResource("/testdata/tap-data.txt"));
        BufferedReader br = new BufferedReader(new FileReader(f));
        String line = "";
        String[] s = null;
        int row = 0;
        while ((line = br.readLine()) != null) {
            s = line.split(",");
            for (int j = 0; j < s.length; j++) {
                tap[row][j] = Byte.parseByte(s[j]);
            }
            row++;
        }
        br.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }

    Frequency freq = new Frequency();
    for (int i = 0; i < tap.length; i++) {
        freq.addValue(Arrays.toString(tap[i]));
    }

    ItemResponseVector[] responseData = new ItemResponseVector[freq.getUniqueCount()];
    ItemResponseVector irv = null;
    Iterator<Comparable<?>> iter = freq.valuesIterator();
    int index = 0;

    //create array of ItemResponseVector objects
    while (iter.hasNext()) {
        //get response string from frequency summary and convert to byte array
        Comparable<?> value = iter.next();
        String s = value.toString();
        s = s.substring(1, s.lastIndexOf("]"));
        String[] sa = s.split(",");
        byte[] rv = new byte[sa.length];
        for (int i = 0; i < sa.length; i++) {
            rv[i] = Byte.parseByte(sa[i].trim());
        }

        //create response vector objects
        irv = new ItemResponseVector(rv, Long.valueOf(freq.getCount(value)).doubleValue());
        responseData[index] = irv;
        index++;
    }
    //        //display results of summary
    //        for(int i=0;i<responseData.length;i++){
    //            System.out.println(responseData[i].toString() + ": " + responseData[i].getFrequency());
    //        }

    return responseData;
}

From source file:com.itemanalysis.psychometrics.irt.estimation.ItemResponseFileSummary.java

/**
 * Summarize comma delimited file. It will extract the data beginning in the column indicated by start
 * and it will continue for nItems columns.
 *
 * @param f file to summarize//from   ww w  . j a  va2s .c  o  m
 * @param start the column index of the first item. It is zero based. If teh data start in the first column, then start=0.
 * @param nItems number of items to read from the file. It will begin at the column indicated by start.
 * @param headerIncluded true if header is included. False otherwise. The header will be omitted.
 * @return an array of item resposne vectors
 */
public ItemResponseVector[] getCondensedResponseVectors(File f, int start, int nItems, boolean headerIncluded) {
    Frequency freq = new Frequency();
    String responseString = "";

    try {
        BufferedReader br = new BufferedReader(new FileReader(f));
        String line = "";
        String[] s = null;
        if (headerIncluded)
            br.readLine();//skip header
        while ((line = br.readLine()) != null) {
            s = line.split(",");
            line = "";

            for (int j = 0; j < nItems; j++) {
                line += s[j + start];
            }
            freq.addValue(line);
        }
        br.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }

    ItemResponseVector[] responseData = new ItemResponseVector[freq.getUniqueCount()];
    ItemResponseVector irv = null;
    Iterator<Comparable<?>> iter = freq.valuesIterator();
    int index = 0;
    byte[] rv = null;

    //create array of ItemResponseVector objects
    while (iter.hasNext()) {
        Comparable<?> value = iter.next();
        responseString = value.toString();

        int n = responseString.length();
        rv = new byte[n];

        String response = "";
        for (int i = 0; i < n; i++) {
            response = String.valueOf(responseString.charAt(i)).toString();
            rv[i] = Byte.parseByte(response);
        }

        //create response vector objects
        irv = new ItemResponseVector(rv, Long.valueOf(freq.getCount(value)).doubleValue());
        responseData[index] = irv;
        index++;
    }
    return responseData;

}

From source file:probe.com.view.body.quantcompare.PieChart.java

private String initPieChart(int width, int height, String title) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int x = 0; x < labels.length; x++) {
        dataset.setValue(labels[x], values[x]);

    }//from  www .  j  a va2  s .  c om
    PiePlot plot = new PiePlot(dataset);
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);

    plot.setLabelGap(0);

    plot.setLabelFont(new Font("Verdana", Font.BOLD, 10));
    plot.setLabelGenerator(new PieSectionLabelGenerator() {

        @Override
        public String generateSectionLabel(PieDataset pd, Comparable cmprbl) {
            return valuesMap.get(cmprbl.toString());
        }

        @Override
        public AttributedString generateAttributedSectionLabel(PieDataset pd, Comparable cmprbl) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    plot.setSimpleLabels(true);

    plot.setLabelBackgroundPaint(null);
    plot.setLabelShadowPaint(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelOutlinePaint(null);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInteriorGap(0);
    plot.setShadowPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f));
    plot.setInteriorGap(0.05);
    for (String label : labels) {
        plot.setSectionPaint(label, defaultKeyColorMap.get(label));
    }

    JFreeChart chart = new JFreeChart(plot);
    //        chart.setTitle(new TextTitle(title, new Font("Verdana", Font.BOLD, 13)));
    chart.setBorderPaint(null);
    chart.setBackgroundPaint(null);
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setItemFont(new Font("Verdana", Font.PLAIN, 10));
    String imgUrl = saveToFile(chart, width, height);

    return imgUrl;

}

From source file:org.adempiere.webui.apps.graph.jfreegraph.ChartRendererServiceImpl.java

@Override
public boolean renderPerformanceGraph(Component parent, int chartWidth, int chartHeight,
        final GoalModel goalModel) {
    GraphBuilder builder = new GraphBuilder();
    builder.setMGoal(goalModel.goal);//ww w  .j av  a  2s .com
    builder.setXAxisLabel(goalModel.xAxisLabel);
    builder.setYAxisLabel(goalModel.yAxisLabel);
    builder.loadDataSet(goalModel.columnList);
    JFreeChart chart = builder.createChart(goalModel.chartType);
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.getPlot().setForegroundAlpha(0.6f);
    if (goalModel.zoomFactor > 0) {
        chartWidth = chartWidth * goalModel.zoomFactor / 100;
        chartHeight = chartHeight * goalModel.zoomFactor / 100;
    }
    if (!goalModel.showTitle) {
        chart.setTitle("");
    }
    BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, info);
    try {
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage image = new AImage("", bytes);
        Imagemap myImage = new Imagemap();

        myImage.setContent(image);
        parent.appendChild(myImage);

        int count = 0;
        for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) {
            ChartEntity entity = (ChartEntity) it.next();

            String key = null;
            if (entity instanceof CategoryItemEntity) {
                Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey();
                if (colKey != null) {
                    key = colKey.toString();
                }
            } else if (entity instanceof PieSectionEntity) {
                Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
                if (sectionKey != null) {
                    key = sectionKey.toString();
                }
            }
            if (key == null) {
                continue;
            }

            Area area = new Area();
            myImage.appendChild(area);
            area.setCoords(entity.getShapeCoords());
            area.setShape(entity.getShapeType());
            area.setTooltiptext(entity.getToolTipText());
            area.setId(count + "_WG_" + key);
            count++;
        }

        myImage.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
            public void onEvent(Event event) throws Exception {
                MouseEvent me = (MouseEvent) event;
                String areaId = me.getArea();
                if (areaId != null) {
                    List<GraphColumn> list = goalModel.columnList;
                    for (int i = 0; i < list.size(); i++) {
                        String s = "_WG_" + list.get(i).getLabel();
                        if (areaId.endsWith(s)) {
                            chartMouseClicked(goalModel.goal, list.get(i));
                            return;
                        }
                    }
                }
            }
        });
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
        return false;
    }
    return true;
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputRadar.java

@Override
public void getModelCoordinatesInfo(final int xOnScreen, final int yOnScreen, final IDisplaySurface g,
        final Point positionInPixels, final StringBuilder sb) {
    final int x = xOnScreen - positionInPixels.x;
    final int y = yOnScreen - positionInPixels.y;
    final ChartEntity entity = info.getEntityCollection().getEntity(x, y);
    // getChart().handleClick(x, y, info);

    final Comparable<?> columnKey = ((CategoryItemEntity) entity).getColumnKey();
    final String title = columnKey.toString();
    final CategoryDataset data = ((CategoryItemEntity) entity).getDataset();
    final Comparable<?> rowKey = ((CategoryItemEntity) entity).getRowKey();
    final double xx = data.getValue(rowKey, columnKey).doubleValue();
    final boolean xInt = xx % 1 == 0;
    sb.append(title).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx));

}