List of usage examples for java.lang Double Double
@Deprecated(since = "9") public Double(String s) throws NumberFormatException
From source file:Main.java
/** * Get double from the JTextField input/*from w w w. j a v a 2 s.c o m*/ * * @param input the JTextField object * @return the double number */ public static double getDouble(javax.swing.JTextField input) throws Exception { return new Double(input.getText()).doubleValue(); }
From source file:Main.java
public static double tanh(double t) { Double aux = new Double(sinh(t) / cosh(t)); if (aux.isNaN()) { if (t > 0.0) return 1.0; else/* ww w. j av a 2 s . c o m*/ return -1.0; } return aux.doubleValue(); }
From source file:Main.java
public static boolean isNan(String param) { boolean result = false; if (param == null || "".equals(param)) { return result; }//from w w w .j a v a 2s. c o m param = param.replace('d', '_').replace('f', '_'); try { Double test = new Double(param); test.intValue(); result = true; } catch (NumberFormatException ex) { return result; } return result; }
From source file:com.hangum.tadpole.commons.util.NumberFormatUtils.java
/** * ?? ./* w w w . j ava 2s . c o m*/ * @param value * @return */ public static String commaFormat(String value) { if (null == value) return ""; try { return commaFormat(new Double(value)); } catch (NumberFormatException nfe) { return value; } }
From source file:io.anserini.index.UpdateIndex.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(HELP_OPTION, "show help")); options.addOption(new Option(OPTIMIZE_OPTION, "merge indexes into a single segment")); options.addOption(new Option(STORE_TERM_VECTORS_OPTION, "store term vectors")); options.addOption(/*from w w w .j a v a 2s.com*/ OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("file with deleted tweetids") .create(DELETES_OPTION)); options.addOption(OptionBuilder.withArgName("id").hasArg().withDescription("max id").create(MAX_ID_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (cmdline.hasOption(HELP_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(UpdateIndex.class.getName(), options); System.exit(-1); } String indexPath = cmdline.getOptionValue(INDEX_OPTION); final FieldType textOptions = new FieldType(); textOptions.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); textOptions.setStored(true); textOptions.setTokenized(true); textOptions.setStoreTermVectors(true); LOG.info("index: " + indexPath); File file = new File("PittsburghUserTimeline"); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } final StatusStream stream = new JsonStatusCorpusReader(file); Status status; String s; HashMap<Long, String> hm = new HashMap<Long, String>(); try { while ((s = stream.nextRaw()) != null) { try { status = DataObjectFactory.createStatus(s); if (status.getText() == null) { continue; } hm.put(status.getUser().getId(), hm.get(status.getUser().getId()) + status.getText().replaceAll("[\\r\\n]+", " ")); } catch (Exception e) { } } } catch (Exception e) { e.printStackTrace(); } finally { stream.close(); } ArrayList<String> userIDList = new ArrayList<String>(); try (BufferedReader br = new BufferedReader(new FileReader(new File("userID")))) { String line; while ((line = br.readLine()) != null) { userIDList.add(line.replaceAll("[\\r\\n]+", "")); // process the line. } } try { reader = DirectoryReader .open(FSDirectory.open(new File(cmdline.getOptionValue(INDEX_OPTION)).toPath())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } final Directory dir = new SimpleFSDirectory(Paths.get(cmdline.getOptionValue(INDEX_OPTION))); final IndexWriterConfig config = new IndexWriterConfig(ANALYZER); config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); final IndexWriter writer = new IndexWriter(dir, config); IndexSearcher searcher = new IndexSearcher(reader); System.out.println("The total number of docs indexed " + searcher.collectionStatistics(TweetStreamReader.StatusField.TEXT.name).docCount()); for (int city = 0; city < cityName.length; city++) { // Pittsburgh's coordinate -79.976389, 40.439722 Query q_long = NumericRangeQuery.newDoubleRange(TweetStreamReader.StatusField.LONGITUDE.name, new Double(longitude[city] - 0.05), new Double(longitude[city] + 0.05), true, true); Query q_lat = NumericRangeQuery.newDoubleRange(TweetStreamReader.StatusField.LATITUDE.name, new Double(latitude[city] - 0.05), new Double(latitude[city] + 0.05), true, true); BooleanQuery bqCityName = new BooleanQuery(); Term t = new Term("place", cityName[city]); TermQuery query = new TermQuery(t); bqCityName.add(query, BooleanClause.Occur.SHOULD); System.out.println(query.toString()); for (int i = 0; i < cityNameAlias[city].length; i++) { t = new Term("place", cityNameAlias[city][i]); query = new TermQuery(t); bqCityName.add(query, BooleanClause.Occur.SHOULD); System.out.println(query.toString()); } BooleanQuery bq = new BooleanQuery(); BooleanQuery finalQuery = new BooleanQuery(); // either a coordinate match bq.add(q_long, BooleanClause.Occur.MUST); bq.add(q_lat, BooleanClause.Occur.MUST); finalQuery.add(bq, BooleanClause.Occur.SHOULD); // or a place city name match finalQuery.add(bqCityName, BooleanClause.Occur.SHOULD); TotalHitCountCollector totalHitCollector = new TotalHitCountCollector(); // Query hasFieldQuery = new ConstantScoreQuery(new // FieldValueFilter("timeline")); // // searcher.search(hasFieldQuery, totalHitCollector); // // if (totalHitCollector.getTotalHits() > 0) { // TopScoreDocCollector collector = // TopScoreDocCollector.create(Math.max(0, // totalHitCollector.getTotalHits())); // searcher.search(finalQuery, collector); // ScoreDoc[] hits = collector.topDocs().scoreDocs; // // // HashMap<String, Integer> hasHit = new HashMap<String, Integer>(); // int dupcount = 0; // for (int i = 0; i < hits.length; ++i) { // int docId = hits[i].doc; // Document d; // // d = searcher.doc(docId); // // System.out.println(d.getFields()); // } // } // totalHitCollector = new TotalHitCountCollector(); searcher.search(finalQuery, totalHitCollector); if (totalHitCollector.getTotalHits() > 0) { TopScoreDocCollector collector = TopScoreDocCollector .create(Math.max(0, totalHitCollector.getTotalHits())); searcher.search(finalQuery, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; System.out.println("City " + cityName[city] + " " + collector.getTotalHits() + " hits."); HashMap<String, Integer> hasHit = new HashMap<String, Integer>(); int dupcount = 0; for (int i = 0; i < hits.length; ++i) { int docId = hits[i].doc; Document d; d = searcher.doc(docId); if (userIDList.contains(d.get(IndexTweets.StatusField.USER_ID.name)) && hm.containsKey(Long.parseLong(d.get(IndexTweets.StatusField.USER_ID.name)))) { // System.out.println("Has timeline field?" + (d.get("timeline") != null)); // System.out.println(reader.getDocCount("timeline")); // d.add(new Field("timeline", hm.get(Long.parseLong(d.get(IndexTweets.StatusField.USER_ID.name))), // textOptions)); System.out.println("Found a user hit"); BytesRefBuilder brb = new BytesRefBuilder(); NumericUtils.longToPrefixCodedBytes(Long.parseLong(d.get(IndexTweets.StatusField.ID.name)), 0, brb); Term term = new Term(IndexTweets.StatusField.ID.name, brb.get()); // System.out.println(reader.getDocCount("timeline")); Document d_new = new Document(); // for (IndexableField field : d.getFields()) { // d_new.add(field); // } // System.out.println(d_new.getFields()); d_new.add(new StringField("userBackground", d.get(IndexTweets.StatusField.USER_ID.name), Store.YES)); d_new.add(new Field("timeline", hm.get(Long.parseLong(d.get(IndexTweets.StatusField.USER_ID.name))), textOptions)); // System.out.println(d_new.get()); writer.addDocument(d_new); writer.commit(); // t = new Term("label", "why"); // TermQuery tqnew = new TermQuery(t); // // totalHitCollector = new TotalHitCountCollector(); // // searcher.search(tqnew, totalHitCollector); // // if (totalHitCollector.getTotalHits() > 0) { // collector = TopScoreDocCollector.create(Math.max(0, totalHitCollector.getTotalHits())); // searcher.search(tqnew, collector); // hits = collector.topDocs().scoreDocs; // // System.out.println("City " + cityName[city] + " " + collector.getTotalHits() + " hits."); // // for (int k = 0; k < hits.length; k++) { // docId = hits[k].doc; // d = searcher.doc(docId); // System.out.println(d.get(IndexTweets.StatusField.ID.name)); // System.out.println(d.get(IndexTweets.StatusField.PLACE.name)); // } // } // writer.deleteDocuments(term); // writer.commit(); // writer.addDocument(d); // writer.commit(); // System.out.println(reader.getDocCount("timeline")); // writer.updateDocument(term, d); // writer.commit(); } } } } reader.close(); writer.close(); }
From source file:org.jfree.chart.demo.LegendWrapperDemo1.java
private static PieDataset createDataset() { DefaultPieDataset defaultpiedataset = new DefaultPieDataset(); defaultpiedataset.setValue("One", new Double(43.200000000000003D)); defaultpiedataset.setValue("Two", new Double(10D)); defaultpiedataset.setValue("Three", new Double(27.5D)); defaultpiedataset.setValue("Four", new Double(17.5D)); defaultpiedataset.setValue("Five", new Double(11D)); defaultpiedataset.setValue("Six", new Double(19.399999999999999D)); return defaultpiedataset; }
From source file:Main.java
public static Object getPropertyValue(Element element) { NamedNodeMap map = element.getAttributes(); map.removeNamedItem(NAME_ATTR);// w w w. j a v a 2 s. c o m if (map.item(0).getNodeName().equals(STRING_ATTR)) return map.item(0).getNodeValue(); else if (map.item(0).getNodeName().equals(INTEGER_ATTR)) return new Integer(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(DOUBLE_ATTR)) return new Double(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(FLOAT_ATTR)) return new Float(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR)) return Boolean.valueOf(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(COLOR_ATTR)) { String[] rgb = map.item(0).getNodeValue().split(","); return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2])); } else if (map.item(0).getNodeName().equals(FONT_ATTR)) { String[] font = map.item(0).getNodeValue().split(","); return new Font(font[0], new Integer(font[1]), new Integer(font[2])); } else { return null; } }
From source file:Main.java
public static Double getCurrentLevelDoubleValue(Element ele, String tagName) { String textToDouble = getCurrentLevelTextValue(ele, tagName); Double valueDouble = null;/*from w ww. jav a 2 s . c o m*/ if (textToDouble != null) { valueDouble = new Double(textToDouble); } return valueDouble; }
From source file:Main.java
public static Set<Double> toSet(double... array) { if (isEmpty(array)) { return new HashSet<>(0); }//from w w w .j a v a 2 s .c om Set<Double> set = new HashSet<>(array.length); for (double d : array) { set.add(new Double(d)); } return set; }
From source file:Main.java
public static Object getPropertyValue(Element element) { NamedNodeMap map = element.getAttributes(); map.removeNamedItem(NAME_ATTR);/* w w w . j a v a2s .c om*/ if (map.item(0).getNodeName().equals(STRING_ATTR)) { return map.item(0).getNodeValue(); } else if (map.item(0).getNodeName().equals(INTEGER_ATTR)) { return new Integer(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(DOUBLE_ATTR)) { return new Double(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(FLOAT_ATTR)) { return new Float(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR)) { return Boolean.valueOf(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(COLOR_ATTR)) { String[] rgb = map.item(0).getNodeValue().split(","); return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2])); } else if (map.item(0).getNodeName().equals(FONT_ATTR)) { String[] font = map.item(0).getNodeValue().split(","); return new Font(font[0], new Integer(font[1]), new Integer(font[2])); } else { return null; } }