我需要返回Observable指定的泛型类型。但是在zip运算符之后我只得到了Observable,没有任何类型。
如何纠正常规20
到import java.awt.Color;
import java.awt.Paint;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetChangeEvent;
import org.jfree.data.general.DatasetChangeListener;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.TextAnchor;
/**
* A bar chart that uses a custom renderer to display different colors within a series.
* No legend is displayed because there is only one series but the colors are not consistent.
*
*/
public class BarChartDemo3 extends ApplicationFrame {
class CustomRenderer extends BarRenderer {
private Paint[] colors;
public CustomRenderer(final Paint[] colors) {
this.colors = colors;
}
public Paint getItemPaint(final int row, final int column) {
return this.colors[column % this.colors.length];
}
}
public BarChartDemo3(final String title) {
super(title);
double[][] data = new double[][] {{4.0, 3.0, 2.0, 3.0, 6.0}};
final CategoryDataset dataset = createDataset(data);
dataset.addChangeListener(new DatasetChangeListener() {
@Override
public void datasetChanged(DatasetChangeEvent arg0) {
// TODO Auto-generated method stub
repaint();
}
});
final JFreeChart chart = createChart(dataset);
final CategoryDataset data2 = createDataset(new double[][]{{10.0, 3.0, 2.0, 3.0, 6.0}});
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
private CategoryDataset createDataset(double[][] data) {
return DatasetUtilities.createCategoryDataset(
"Series ",
"Category ",
data
);
}
private JFreeChart createChart(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createBarChart(
"Bar Chart Demo 3", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // the plot orientation
false, // include legend
true,
false
);
// get a reference to the plot for further customisation...
final CategoryPlot plot = chart.getCategoryPlot();
plot.setNoDataMessage("NO DATA!");
final CategoryItemRenderer renderer = new CustomRenderer(
new Paint[] {Color.red, Color.blue, Color.green,
Color.yellow, Color.cyan,
Color.magenta}
);
// renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
renderer.setItemLabelsVisible(true);
final ItemLabelPosition p = new ItemLabelPosition(
ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0
);
renderer.setPositiveItemLabelPosition(p);
plot.setRenderer(renderer);
// change the margin at the top of the range axis...
final ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setLowerMargin(0.15);
rangeAxis.setUpperMargin(0.15);
rangeAxis.setAutoRange(true);
return chart;
}
public static void main(final String[] args) {
final BarChartDemo3 chart = new BarChartDemo3("Bar Chart Demo 3");
chart.pack();
RefineryUtilities.centerFrameOnScreen(chart);
chart.setVisible(true);
}
}
的投射?也许这有一些rx运算符?
代码示例:
Observable
答案 0 :(得分:1)
您需要在编译器可以使用它的位置提供类型信息:
public Observable<Schedule> updateSchedules(final List<ScheduleInfo> schedulesInfo) {
List<Observable<List<ScheduleItem>>> observables = makeScheduleTasks(schedulesInfo);
Observable<Schedule> observable = Observable.zip(observables, objects -> getSchedules(schedulesInfo, objects));
return observable;
}
只要getSchedules()
返回Schedule
。,就可以正常工作