List of usage examples for java.util List clear
void clear();
From source file:it.unicaradio.android.models.Schedule.java
public static Schedule fromJSON(JSONObject json) { Schedule result = new Schedule(); for (Day day : Day.values()) { result.transmissions.put(day, new ArrayList<Transmission>()); }/* w w w . j a v a2 s . co m*/ if (json == null) { Log.d(TAG, "JSON is null!!!"); return result; } for (Day day : Day.values()) { List<Transmission> transmissionsByDay = result.transmissions.get(day); String dayKey = day.toString(); try { JSONArray itemArray = json.getJSONArray(dayKey); for (int i = 0; i < itemArray.length(); i++) { JSONObject transmissionJSON = itemArray.getJSONObject(i); Transmission transmission = Transmission.fromJSON(transmissionJSON); if (transmission != null) { transmissionsByDay.add(transmission); } } } catch (JSONException e) { Log.e(TAG, "Error while parsing JSON", e); transmissionsByDay.clear(); } Collections.sort(transmissionsByDay); result.transmissions.put(day, transmissionsByDay); } return result; }
From source file:com.espertech.esper.regression.pattern.TestFollowedByMaxOperator.java
private static void assertContext(EPServiceProvider epService, EPStatement stmt, List<ConditionHandlerContext> contexts, int max) { assertEquals(1, contexts.size());/*ww w . j a v a 2 s.com*/ ConditionHandlerContext context = contexts.get(0); assertEquals(epService.getURI(), context.getEngineURI()); assertEquals(stmt.getText(), context.getEpl()); assertEquals(stmt.getName(), context.getStatementName()); ConditionPatternSubexpressionMax condition = (ConditionPatternSubexpressionMax) context .getEngineCondition(); assertEquals(max, condition.getMax()); contexts.clear(); }
From source file:weka.core.ChartUtils.java
/** * Render a combined histogram and box plot chart from summary data * /*from www.j a v a 2 s .c om*/ * @param width the width of the resulting image * @param height the height of the resulting image * @param bins the values for the chart * @param freqs the corresponding frequencies * @param summary the summary stats for the box plot * @param outliers an optional list of outliers for the box plot * @param additionalArgs optional arguments to the renderer (may be null) * @return a buffered image * @throws Exception if a problem occurs */ public static BufferedImage renderCombinedBoxPlotAndHistogramFromSummaryData(int width, int height, List<String> bins, List<Double> freqs, List<Double> summary, List<Double> outliers, List<String> additionalArgs) throws Exception { String plotTitle = "Combined Chart"; String userTitle = getOption(additionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; List<String> opts = new ArrayList<String>(); opts.add("-title=histogram"); BufferedImage hist = renderHistogramFromSummaryData(width / 2, height, bins, freqs, opts); opts.clear(); opts.add("-title=box plot"); BufferedImage box = null; try { box = renderBoxPlotFromSummaryData(width / 2, height, summary, outliers, opts); } catch (Exception ex) { // if we can't generate the box plot (i.e. probably because // data is 100% missing) then just return the histogram } if (box == null) { width /= 2; } BufferedImage img = new BufferedImage(width, height + 20, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); g2d.setFont(new Font("SansSerif", Font.BOLD, 12)); g2d.setColor(Color.lightGray); g2d.fillRect(0, 0, width, height + 20); g2d.setColor(Color.black); FontMetrics fm = g2d.getFontMetrics(); int fh = fm.getHeight(); int sw = fm.stringWidth(plotTitle); if (box != null) { g2d.drawImage(box, 0, 20, null); g2d.drawImage(hist, width / 2 + 1, 20, null); } else { g2d.drawImage(hist, 0, 20, null); } g2d.drawString(plotTitle, width / 2 - sw / 2, fh + 2); g2d.dispose(); return img; }
From source file:com.net2plan.utils.CollectionUtils.java
/** * Returns the key(s) where a given value can be found into a map. * /* www. j a va2s . c o m*/ * @param <A> Key type * @param <B> Value type * @param map Input map * @param value Value to be searched for * @param searchType Indicates whether the first, the last, or all occurrences are returned * @return Key(s) in which the given value can be found (in iteration order) */ public static <A, B> List<A> find(Map<A, B> map, B value, Constants.SearchType searchType) { List<A> out = new LinkedList<A>(); for (Entry<A, B> entry : map.entrySet()) { if ((value == null && entry.getValue() == null) || (value != null && value.equals(entry.getValue()))) { switch (searchType) { case FIRST: out.add(entry.getKey()); return out; case ALL: out.add(entry.getKey()); break; case LAST: out.clear(); out.add(entry.getKey()); break; default: throw new RuntimeException("Bad"); } } } return out; }
From source file:weka.core.ChartUtils.java
/** * Render a combined histogram and pie chart from summary data * /*from w w w . j av a 2 s . c o m*/ * @param width the width of the resulting image * @param height the height of the resulting image * @param values the values for the chart * @param freqs the corresponding frequencies * @param additionalArgs optional arguments to the renderer (may be null) * @return a buffered image * @throws Exception if a problem occurs */ public static BufferedImage renderCombinedPieAndHistogramFromSummaryData(int width, int height, List<String> values, List<Double> freqs, List<String> additionalArgs) throws Exception { String plotTitle = "Combined Chart"; String userTitle = getOption(additionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; List<String> opts = new ArrayList<String>(); opts.add("-title=distribution"); BufferedImage pie = renderPieChartFromSummaryData(width / 2, height, values, freqs, false, true, opts); opts.clear(); opts.add("-title=histogram"); BufferedImage hist = renderHistogramFromSummaryData(width / 2, height, values, freqs, opts); BufferedImage img = new BufferedImage(width, height + 20, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); g2d.setFont(new Font("SansSerif", Font.BOLD, 12)); g2d.setColor(Color.lightGray); g2d.fillRect(0, 0, width, height + 20); g2d.setColor(Color.black); FontMetrics fm = g2d.getFontMetrics(); int fh = fm.getHeight(); int sw = fm.stringWidth(plotTitle); g2d.drawImage(pie, 0, 20, null); g2d.drawImage(hist, width / 2 + 1, 20, null); g2d.drawString(plotTitle, width / 2 - sw / 2, fh + 2); g2d.dispose(); return img; }
From source file:de.fatalix.book.importer.BookMigrator.java
/** * * @param solrURL//from ww w. j a v a2s. co m * @param solrCore * @param batchSize * @param importPath * @param reset * @throws IOException * @throws SolrServerException */ public static void importBooks(String solrURL, String solrCore, int batchSize, List<File> bookFolders, boolean reset) throws IOException, SolrServerException { SolrServer server = SolrHandler.createConnection(solrURL, solrCore); if (reset) { System.out.println("RESET:"); server.deleteByQuery("*:*"); server.commit(); } System.out.println("Connection established"); Gson gson = new Gson(); int total = bookFolders.size(); int counter = 0; List<BookEntry> bookEntries = new ArrayList<>(); for (File bookFolder : bookFolders) { bookEntries.add(importBatchWise(bookFolder, gson)); counter++; if (bookEntries.size() >= batchSize) { UpdateResponse response = SolrHandler.addBeans(server, bookEntries); if (response.getStatus() != 0) { throw new SolrServerException("Update failed with CODE " + response.getStatus()); } bookEntries.clear(); System.out.println("Processed " + counter + " of " + total); } } if (bookEntries.size() > 0) { UpdateResponse response = SolrHandler.addBeans(server, bookEntries); if (response.getStatus() != 0) { throw new SolrServerException("Update failed with CODE " + response.getStatus()); } bookEntries.clear(); System.out.println("Processed " + counter + " of " + total); } }
From source file:com.github.abel533.mapperhelper.EntityHelper.java
/** * mapList?beanList//from www . j a v a2 s . c om * * @param mapList * @param beanClass * @return */ public static List<?> maplist2BeanList(List<?> mapList, Class<?> beanClass) { if (mapList == null || mapList.size() == 0) { return null; } List list = new ArrayList<Object>(mapList.size()); for (Object map : mapList) { list.add(map2Bean((Map) map, beanClass)); } mapList.clear(); mapList.addAll(list); return mapList; }
From source file:ddf.catalog.registry.converter.RegistryPackageConverter.java
private static void parseRegistryService(ServiceType service, MetacardImpl metacard) throws RegistryConversionException { validateIdentifiable(service);/*from w w w.ja v a 2s . co m*/ String xmlServiceBindingsTypesAttributeName = METACARD_XML_NAME_MAP .get(RegistryObjectMetacardType.SERVICE_BINDING_TYPES); String xmlServiceBindingsAttributeName = METACARD_XML_NAME_MAP .get(RegistryObjectMetacardType.SERVICE_BINDINGS); List<String> serviceBindings = new ArrayList<>(); List<String> serviceBindingTypes = new ArrayList<>(); List<String> bindings = new ArrayList<>(); List<String> bindingTypes = new ArrayList<>(); for (ServiceBindingType binding : service.getServiceBinding()) { bindings.clear(); bindingTypes.clear(); Map<String, List<SlotType1>> slotMap = getSlotMapWithMultipleValues(binding.getSlot()); if (slotMap.containsKey(xmlServiceBindingsTypesAttributeName)) { List<SlotType1> slots = slotMap.get(xmlServiceBindingsTypesAttributeName); for (SlotType1 slot : slots) { bindingTypes.addAll(getSlotStringAttributes(slot)); } } if (slotMap.containsKey(xmlServiceBindingsAttributeName)) { List<SlotType1> slots = slotMap.get(xmlServiceBindingsAttributeName); for (SlotType1 slot : slots) { bindings.addAll(getSlotStringAttributes(slot)); } } if (CollectionUtils.isEmpty(bindingTypes)) { String message = "Service Binding must contain at least one binding type. Service ID: " + service.getId(); if (binding.isSetId()) { message += ", Service binding ID: " + binding.getId(); } throw new RegistryConversionException(message); } serviceBindingTypes.addAll(bindingTypes); serviceBindings.addAll(bindings); } metacard.setAttribute(RegistryObjectMetacardType.SERVICE_BINDING_TYPES, (Serializable) serviceBindingTypes); metacard.setAttribute(RegistryObjectMetacardType.SERVICE_BINDINGS, (Serializable) serviceBindings); }
From source file:backup.namenode.NameNodeBackupBlockCheckProcessor.java
private static void backupBlock(BackupReportWriter writer, List<ExtendedBlockWithAddress> batch, ExtendedBlockEnum<Addresses> nnEnum, int backupRequestBatchSize, DataNodeBackupRPCLookup rpcLookup) { if (batch.size() >= backupRequestBatchSize) { writeBackupRequests(writer, batch, rpcLookup); batch.clear(); }/*from ww w .j a va 2 s . co m*/ batch.add(new ExtendedBlockWithAddress(nnEnum.current(), nnEnum.currentValue())); }
From source file:com.yahoo.glimmer.util.MergeSortTool.java
public static int mergeSort(FileSystem fs, List<Path> sourcePaths, Path outputPath, CompressionCodecFactory compressionCodecFactory) throws IOException { assert sourcePaths.size() > 0 : "No source paths given."; LOG.info("Sorted merge into " + outputPath.toString()); OutputStream outputStream = fs.create(outputPath); CompressionCodec inputCompressionCodec = compressionCodecFactory.getCodec(sourcePaths.get(0)); if (inputCompressionCodec != null) { LOG.info("Input compression codec " + inputCompressionCodec.getClass().getName()); }//from w w w . j a va 2 s . c o m CompressionCodec outputCompressionCodec = compressionCodecFactory.getCodec(outputPath); if (outputCompressionCodec != null) { LOG.info("Output compression codec " + outputCompressionCodec.getClass().getName()); outputStream = outputCompressionCodec.createOutputStream(outputStream); } List<BufferedReader> readers = new ArrayList<BufferedReader>(); OutputStreamWriter writer = new OutputStreamWriter(outputStream); for (Path partPath : sourcePaths) { LOG.info("\tAdding source " + partPath.toString()); InputStream inputStream = fs.open(partPath); if (inputCompressionCodec != null) { inputStream = inputCompressionCodec.createInputStream(inputStream); } BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); readers.add(reader); } int count = ReadersWriterMergeSort.mergeSort(readers, writer); writer.close(); for (BufferedReader reader : readers) { reader.close(); } readers.clear(); LOG.info("Processed " + count + " lines into " + outputPath.toString()); return count; }