List of usage examples for java.util Calendar getInstance
public static Calendar getInstance()
From source file:ObjectStreams.java
public static void main(String[] args) throws IOException, ClassNotFoundException { ObjectOutputStream out = null; try {/*from w w w . j av a 2s. c o m*/ out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(dataFile))); out.writeObject(Calendar.getInstance()); for (int i = 0; i < prices.length; i++) { out.writeObject(prices[i]); out.writeInt(units[i]); out.writeUTF(descs[i]); } } finally { out.close(); } ObjectInputStream in = null; try { in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(dataFile))); Calendar date = null; BigDecimal price; int unit; String desc; BigDecimal total = new BigDecimal(0); date = (Calendar) in.readObject(); System.out.format("On %tA, %<tB %<te, %<tY:%n", date); try { while (true) { price = (BigDecimal) in.readObject(); unit = in.readInt(); desc = in.readUTF(); System.out.format("You ordered %d units of %s at $%.2f%n", unit, desc, price); total = total.add(price.multiply(new BigDecimal(unit))); } } catch (EOFException e) { } System.out.format("For a TOTAL of: $%.2f%n", total); } finally { in.close(); } }
From source file:com.glaf.core.job.SysDataLogCreateTableJob.java
public static void main(String[] args) { Date date = DateUtils.getDateAfter(new Date(), 0); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/* www. j a v a 2s. com*/ int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int daysOfMonth = DateUtils.getYearMonthDays(year, month + 1); calendar.set(year, month, daysOfMonth); int begin = getYearMonthDay(date); int end = getYearMonthDay(calendar.getTime()); for (int i = begin; i <= end; i++) { logger.debug(i); try { SysDataLogTableUtils.createTable("SYS_DATA_LOG_" + i); } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } } }
From source file:Student.java
public static void main(String[] a) throws Exception { em.getTransaction().begin();/*from ww w . ja va 2 s. c o m*/ Student student = new Student(); student.setId(UUID.randomUUID().toString()); student.setName("Joe"); student.setDob(Calendar.getInstance().getTime()); em.persist(student); em.flush(); em.getTransaction().commit(); Query query = em.createQuery("SELECT e FROM Student e"); List<Student> list = (List<Student>) query.getResultList(); System.out.println(list); em.close(); emf.close(); Helper.checkData(); }
From source file:com.hygenics.parser.MainApp.java
/** * The entire programs main method.//w ww. jav a 2 s . c o m * * @param args */ public static void main(String[] args) { final Logger log = LoggerFactory.getLogger(MainApp.class); log.info("Starting Parse @ " + Calendar.getInstance().getTime().toString()); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( ("file:" + System.getProperty("beansfile").trim())); log.info("Found beans @ " + System.getProperty("beansfile").trim()); log.info("Starting"); ArrayList<String> results = null; String activity = null; log.info("Obtaining Activities"); ActivitiesStack stack = (ActivitiesStack) context.getBean("ActivitiesStack"); // integers keeping track of bean number to pull (e.g. DumpToText0 or // DumpToText1) // in keeping with the spirit of dumping out data int n = 0, srn = 0, mv = 0, cen = 0, pps = 0, sb = 0, kv = 0, cf = 0, zip = 0, bm = 0, dump = 0, kettle = 0, execute = 0, transfer = 0, sqls = 0, job = 0, parsepages = 0, getpages = 0, map = 0, js = 0, sdump = 0, transforms = 0, execs = 0, gim = 0, ems = 0, jd = 0; Pattern p = Pattern.compile("[A-Za-z]+[0-9]+"); Matcher m; // start stack init log.info("Stack Initialized with Size of " + stack.getSize() + " @ " + Calendar.getInstance().getTime().toString()); while (stack.getSize() > 0) { // pop activity form stack activity = stack.Pop(); log.info("Activities Remaining " + stack.getSize()); m = p.matcher(activity); log.info("\n\nACTIVITY: " + activity + "\n\n"); if (activity.toLowerCase().contains("manualrepconn")) { log.info("Manual Transformation Started @ " + Calendar.getInstance().getTime().toString()); ManualReplacement mrp = (ManualReplacement) context.getBean("ManualRepConn"); mrp.run(); log.info("Manual Transformation Finished @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("cleanfolder")) { log.info("Folder Cleanup Started @ " + Calendar.getInstance().getTime().toString()); CleanFolder c; if (cf == 0 || context.containsBean("CleanFolder")) { c = (CleanFolder) ((context.containsBean("CleanFolder")) ? context.getBean("CleanFolder") : context.getBean("CleanFolder" + cf)); } else { c = (CleanFolder) context.getBean("CleanFolder" + cf); } c.run(); cf++; log.info("File Cleanup Complete @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("zip")) { log.info("Zip File Creation Started @ " + Calendar.getInstance().getTime().toString()); Archiver a; if (zip == 0 || context.containsBean("Zip")) { a = (Archiver) ((context.containsBean("Zip")) ? context.getBean("Zip") : context.getBean("Zip" + zip)); } else { a = (Archiver) context.getBean("Zip" + zip); } a.run(); zip++; log.info("Zip File Creation Complete @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("transfer")) { log.info("File Transfer Started @ " + Calendar.getInstance().getTime().toString()); Upload u; if (transfer == 0 || context.containsBean("FileTransfer")) { u = (Upload) ((context.containsBean("FileTransfer")) ? context.getBean("FileTransfer") : context.getBean("FileTransfer" + transfer)); } else { u = (Upload) context.getBean("FileTransfer" + transfer); } u.run(); transfer++; log.info("File Transfer Complete @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("droptables")) { // drop tables log.info("Dropping Tables @ " + Calendar.getInstance().getTime().toString()); DropTables droptables = (DropTables) context.getBean("DropTables"); droptables.run(); droptables = null; log.info("Done Dropping Tables @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().equals("createtables")) { // create tables log.info("Creating Tables @ " + Calendar.getInstance().getTime().toString()); CreateTable create = (CreateTable) context.getBean("CreateTables"); create.run(); create = null; log.info("Done Creating Tables @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("createtableswithreference")) { // create tables log.info("Creating Tables @ " + Calendar.getInstance().getTime().toString()); CreateTablesWithReference create = (CreateTablesWithReference) context .getBean("CreateTablesWithReference"); create.run(); create = null; log.info("Done Creating Tables @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("truncate")) { // truncate table log.info("Truncating @ " + Calendar.getInstance().getTime().toString()); Truncate truncate = (Truncate) context.getBean("Truncate"); truncate.truncate(); truncate = null; log.info("Truncated @ " + Calendar.getInstance().getTime().toString()); Runtime.getRuntime().gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().equals("enforce")) { // enforce schema log.info("Enforcing Schema @" + Calendar.getInstance().getTime().toString()); ForceConformity ef = (ForceConformity) context.getBean("EnforceStandards"); ef.run(); log.info("Done Enforcing Schema @" + Calendar.getInstance().getTime().toString()); Runtime.getRuntime().gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().contains("enforcewithreference")) { // enforce schema ForceConformityWithReference ef = (ForceConformityWithReference) context .getBean("EnforceStandardsWithReference"); log.info("Enforcing Schema By Reference @" + Calendar.getInstance().getTime().toString()); ef.run(); log.info("Done Enforcing Schema @" + Calendar.getInstance().getTime().toString()); Runtime.getRuntime().gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().trim().equals("repconn")) { log.info("Replacing Transformation Connection Information @" + Calendar.getInstance().getTime().toString()); RepConn rep = (RepConn) context.getBean("repconn"); rep.run(); log.info("Finished Replacing Connection Information @" + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("job")) { // run a Pentaho job as opposed to a Pentaho Transformation log.info("Run Job kjb file @" + Calendar.getInstance().getTime().toString()); RunJob kjb = null; if (m.find()) { kjb = (RunJob) context.getBean(activity); } else { kjb = (RunJob) context.getBean("Job" + job); } kjb.run(); kjb = null; log.info("Pentaho Job Complete @" + Calendar.getInstance().getTime().toString()); Runtime.getRuntime().gc(); } else if (activity.toLowerCase().compareTo("execute") == 0) { // Execute a process log.info("Executing Process @" + Calendar.getInstance().getTime().toString()); if (context.containsBean("Execute") && execs == 0) { ExecuteProcess proc = (ExecuteProcess) context.getBean(("Execute")); proc.Execute(); } else { ExecuteProcess proc = (ExecuteProcess) context.getBean(("Execute" + execute)); proc.Execute(); } execs++; log.info("Pages Obtained @" + Calendar.getInstance().getTime().toString()); Runtime.getRuntime().gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().contains("parsepageswithscala") || activity.toLowerCase().contains("parsepagesscala")) { //parse pages with scala log.info("Parsing Pages with Scala @ " + Calendar.getInstance().getTime().toString()); ScalaParseDispatcher pds = null; if (context.containsBean("ParsePagesScala" + pps)) { pds = (ScalaParseDispatcher) context.getBean("ParsePagesScala" + pps); } else if (context.containsBean("ParsePagesScala") && pps > 0) { pds = (ScalaParseDispatcher) context.getBean("ParsePagesScala"); } pps++; pds.run(); Runtime.getRuntime().gc(); log.info("Finished Parsing Pages with Scala @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("parsepages")) { // Parse Pages with java log.info("Parsing Individual Pages @" + Calendar.getInstance().getTime().toString()); if (context.containsBean("ParsePages") && parsepages == 0) { ParseDispatcher pd = (ParseDispatcher) context.getBean("ParsePages"); pd.run(); pd = null; } else { ParseDispatcher pd = (ParseDispatcher) context.getBean("ParsePages" + parsepages); pd.run(); pd = null; } parsepages++; log.info("Finished Parsing @" + Calendar.getInstance().getTime().toString()); Runtime.getRuntime().gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().contains("kvparser")) { // Parse Pages using the KV Parser log.info("Parsing Individual Pages with Key Value Pairs @" + Calendar.getInstance().getTime().toString()); if (context.containsBean("KVParser") && parsepages == 0) { KVParser pd = (KVParser) context.getBean("KVParser"); pd.run(); pd = null; } else { KVParser pd = (KVParser) context.getBean("KVParser" + kv); pd.run(); pd = null; } parsepages++; log.info("Finished Parsing @" + Calendar.getInstance().getTime().toString()); Runtime.getRuntime().gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().contains("parsewithsoup")) { // Parse Pages with Jsoup log.info("Parsing Pages with JSoup @ " + Calendar.getInstance().getTime().toString()); if (context.containsBean("ParseJSoup") && js == 0) { ParseJSoup psj = (ParseJSoup) context.getBean("ParseJSoup"); psj.run(); } else { ParseJSoup psj = (ParseJSoup) context.getBean("ParseJSoup" + Integer.toString(js)); psj.run(); } js++; log.info("Finished Parsing @" + Calendar.getInstance().getTime().toString()); Runtime.getRuntime().gc(); log.info("Finished Parsing with JSoup @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("breakmultiplescala") || activity.toLowerCase().contains("breakmultiplewithscala")) { log.info("Breaking Records"); BreakMultipleScala bms = null; if (context.containsBean("BreakMultipleScala" + ems)) { bms = (BreakMultipleScala) context.getBean("BreakMultipleScala" + sb); } else { bms = (BreakMultipleScala) context.getBean("BreakMultipleScala"); } bms.run(); bms = null; sb++; Runtime.getRuntime().gc(); System.gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); log.info("Completed Breaking Tasks"); } else if (activity.toLowerCase().contains("breakmultiple")) { // break apart multi-part records log.info("Breaking apart Records (BreakMultiple) @" + Calendar.getInstance().getTime().toString()); if (context.containsBean("BreakMultiple") && bm == 0) { BreakMultiple br = (BreakMultiple) context.getBean(("BreakMultiple")); br.run(); br = null; } else { BreakMultiple br = (BreakMultiple) context.getBean(("BreakMultiple" + Integer.toString(bm))); br.run(); br = null; } bm++; log.info("Finished Breaking Apart Records @" + Calendar.getInstance().getTime().toString()); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().compareTo("mapper") == 0) { // remap data log.info("Mapping Records @" + Calendar.getInstance().getTime().toString()); if (context.containsBean("Mapper") && map == 0) { Mapper mp = (Mapper) context.getBean("Mapper"); mp.run(); mp = null; } else { Mapper mp = (Mapper) context.getBean("Mapper" + Integer.toString(map)); mp.run(); mp = null; } map++; log.info("Completed Mapping Records @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("getimages")) { // Get Images in a Separate Step log.info("Beggining Image Pull @ " + Calendar.getInstance().getTime().toString()); if (context.containsBean("getImages") && gim == 0) { GetImages gi = (GetImages) context.getBean("getImages"); gi.run(); log.info("Image Pull Complete @ " + Calendar.getInstance().getTime().toString()); gi = null; } else { GetImages gi = (GetImages) context.getBean("getImages"); gi.run(); log.info("Image Pull Complete @ " + Calendar.getInstance().getTime().toString()); gi = null; } gim++; Runtime.getRuntime().gc(); System.gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().compareTo("sql") == 0) { // execute a sql command log.info("Executing SQL Query @ " + Calendar.getInstance().getTime().toString()); if (context.containsBean("SQL") && sqls == 0) { ExecuteSQL sql; if (m.find()) { sql = (ExecuteSQL) context.getBean(activity); } else { sql = (ExecuteSQL) context.getBean("SQL"); } sql.execute(); sql = null; } else { ExecuteSQL sql; if (m.find()) { sql = (ExecuteSQL) context.getBean(activity); } else { sql = (ExecuteSQL) context.getBean("SQL" + sqls); } sql.execute(); sql = null; } sqls++; log.info("Finished SQL Query @ " + Calendar.getInstance().getTime().toString()); Runtime.getRuntime().gc(); System.gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().compareTo("kettle") == 0) { // run one or more kettle transformation(s) log.info("Beginning Kettle Transformation @ " + Calendar.getInstance().getTime().toString()); RunTransformation rt = null; if (context.containsBean("kettle") && transforms == 0) { if (m.find()) { rt = (RunTransformation) context.getBean(activity); } else { rt = (RunTransformation) context.getBean(("kettle")); } rt.run(); rt = null; } else { if (m.find()) { rt = (RunTransformation) context.getBean(activity); } else { rt = (RunTransformation) context.getBean(("kettle" + kettle)); } rt.run(); rt = null; } transforms++; log.info("Ending Kettle Transformation @ " + Calendar.getInstance().getTime().toString()); Runtime.getRuntime().gc(); System.gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); kettle++; } else if (activity.toLowerCase().contains("dumptotext")) { // dump to a text file via java log.info("Dumping to Text @ " + Calendar.getInstance().getTime().toString()); DumptoText dtt = null; if (m.find()) { dtt = (DumptoText) context.getBean(activity); } else { dtt = (DumptoText) context.getBean("DumpToText" + dump); } dtt.run(); dump++; log.info("Completed Dump @ " + Calendar.getInstance().getTime().toString()); dtt = null; Runtime.getRuntime().gc(); System.gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().equals("jdump")) { log.info("Dumping via JDump @ " + Calendar.getInstance().getTime().toString()); if (jd == 0 && context.containsBean("JDump")) { JDump j = (JDump) context.getBean("JDump"); jd++; j.run(); } else { JDump j = (JDump) context.getBean("JDump" + jd); jd++; j.run(); } Runtime.getRuntime().gc(); System.gc(); log.info("Finished Dumping via JDump @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("jdumpwithreference")) { log.info("Dumping via JDump @ " + Calendar.getInstance().getTime().toString()); if (jd == 0 && context.containsBean("JDumpWithReference")) { JDumpWithReference j = (JDumpWithReference) context.getBean("JDumpWithReference"); jd++; j.run(); } else { JDumpWithReference j = (JDumpWithReference) context.getBean("JDumpWithReference" + jd); jd++; j.run(); } Runtime.getRuntime().gc(); System.gc(); log.info("Finished Dumping via JDump @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().compareTo("commanddump") == 0) { // dump to text using a client side sql COPY TO command log.info("Dumping via SQL @ " + Calendar.getInstance().getTime().toString()); CommandDump d = (CommandDump) context.getBean("dump"); d.run(); d = null; log.info("Completed Dump @ " + Calendar.getInstance().getTime().toString()); // most likely not needed by satisfies my paranoia Runtime.getRuntime().gc(); System.gc(); } else if (activity.toLowerCase().equals("specdump")) { // Specified Dump log.info("Dumping via Specified Tables, Files, and Attributes @ " + Calendar.getInstance().getTime().toString()); if (context.containsBean("SpecDump") && sdump == 0) { sdump++; SpecifiedDump sd = (SpecifiedDump) context.getBean("SpecDump"); sd.run(); sd = null; } else if (context.containsBean("SpecDump" + Integer.toString(sdump))) { SpecifiedDump sd = (SpecifiedDump) context.getBean("SpecDump" + Integer.toString(sdump)); sd.run(); sd = null; } sdump++; log.info("Completed Dumping via Specified Tables, Files, and Attributes @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("specdumpwithreference")) { // Specified Dump log.info("Dumping via Specified Tables, Files, and Attributes by Reference @ " + Calendar.getInstance().getTime().toString()); if (context.containsBean("SpecDumpWithReference") && sdump == 0) { sdump++; SpecDumpWithReference sd = (SpecDumpWithReference) context.getBean("SpecDumpWithReference"); sd.run(); sd = null; } else if (context.containsBean("SpecDumpWithReference" + Integer.toString(sdump))) { SpecDumpWithReference sd = (SpecDumpWithReference) context .getBean("SpecDumpWithReference" + Integer.toString(sdump)); sd.run(); sd = null; } else { log.info("Bean Not Found For " + activity); } sdump++; log.info("Completed Dumping via Specified Tables, Files, and Attributes @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().compareTo("email") == 0) { // email completion notice log.info("Sending Notice of Completion @ " + Calendar.getInstance().getTime().toString()); if (context.containsBean("Email") && ems == 0) { Send s = (Send) context.getBean("Email"); s.run(); s = null; } else { Send s = (Send) context.getBean("Email" + Integer.toString(ems)); s.run(); s = null; } ems++; Runtime.getRuntime().gc(); System.gc(); log.info("Completed Email @ " + Calendar.getInstance().getTime().toString()); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().equals("qa")) { // perform qa log.info("Performing Quality Assurance @ " + Calendar.getInstance().getTime().toString()); if (context.containsBean("QA")) { QualityAssurer qa = (QualityAssurer) context.getBean("QA"); qa.run(); qa = null; } // attempt to hint --> all tasks are really intense so anything // is nice Runtime.getRuntime().gc(); System.gc(); log.info("Completed QA @ " + Calendar.getInstance().getTime().toString()); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); } else if (activity.toLowerCase().equals("notify")) { log.info("Running Notification Tasks"); Notification nt = null; if (context.containsBean("Notify" + Integer.toString(n))) { nt = (Notification) context.getBean("Notify" + Integer.toString(n)); } else { nt = (Notification) context.getBean("Notify"); } nt.run(); nt = null; n++; if (context.containsBean("Email") && ems == 0) { Send s = (Send) context.getBean("Email"); s.run(); s = null; } else if (context.containsBean("Email" + ems)) { Send s = (Send) context.getBean("Email" + Integer.toString(ems)); s.run(); s = null; } ems++; Runtime.getRuntime().gc(); System.gc(); log.info("Free Memory: " + Runtime.getRuntime().freeMemory()); log.info("Completed Notification Tasks"); } else if (activity.toLowerCase().contains("move")) { log.info("Moving Files @ " + Calendar.getInstance().getTime().toString()); MoveFile mf = null; if (context.containsBean("Move" + Integer.toString(mv))) { mf = (MoveFile) context.getBean("Move" + Integer.toString(mv)); } else { mf = (MoveFile) context.getBean("Move"); } mf.run(); mv++; Runtime.getRuntime().gc(); log.info("Finished Moving Files @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("numericalcheck")) { log.info("Checking Counts"); NumericalChecker nc = (NumericalChecker) context.getBean("NumericalChecker"); nc.run(); Runtime.getRuntime().gc(); log.info("Finished Checking Counts @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("runscript")) { log.info("Running Script @ " + Calendar.getInstance().getTime().toString()); RunScript runner = null; if (context.containsBean("RunScript" + srn)) { runner = (RunScript) context.getBean("RunScript" + srn); } else { runner = (RunScript) context.getBean("RunScript"); } runner.run(); srn++; Runtime.getRuntime().gc(); log.info("Finished Running SCript @ " + Calendar.getInstance().getTime().toString()); } else if (activity.toLowerCase().contains("checkexistance")) { log.info("Checking Existance @ " + Calendar.getInstance().getTime().toString()); ExistanceChecker runner = null; if (context.containsBean("CheckExistance" + srn)) { runner = (ExistanceChecker) context.getBean("CheckExistance" + cen); } else { runner = (ExistanceChecker) context.getBean("CheckExistance"); } runner.run(); cen++; Runtime.getRuntime().gc(); log.info("Finished Checking Existance @ " + Calendar.getInstance().getTime().toString()); } else { log.info("Activity " + activity + " does not exist!"); } } log.info("Completed Parse @ " + Calendar.getInstance().getTime().toString()); context.destroy(); context.close(); }
From source file:ClassKeyword.java
public static void main(String[] argv) { //+/* ww w.j av a2s.c o m*/ System.out.println("Trying the ClassName.class keyword:"); System.out.println("Object class: " + Object.class); System.out.println("String class: " + String.class); System.out.println("String[] class: " + String[].class); System.out.println("Calendar class: " + Calendar.class); System.out.println("Current class: " + ClassKeyword.class); System.out.println("Class for int: " + int.class); System.out.println(); System.out.println("Trying the instance.getClass() method:"); System.out.println("Sir Robin the Brave".getClass()); System.out.println(Calendar.getInstance().getClass()); //- }
From source file:info.usbo.skypetwitter.Run.java
public static void main(String[] args) { System.out.println("Working Directory = " + System.getProperty("user.dir")); Properties props;//from w w w . ja va 2 s . c om props = (Properties) System.getProperties().clone(); //loadProperties(props, "D:\\Data\\Java\\classpath\\twitter.props"); work_dir = System.getProperty("user.dir"); loadProperties(props, work_dir + "\\twitter.props"); twitter_user_id = props.getProperty("twitter.user"); twitter_timeout = Integer.parseInt(props.getProperty("twitter.timeout")); System.out.println("Twitter user: " + twitter_user_id); System.out.println("Twitter timeout: " + twitter_timeout); if ("".equals(twitter_user_id)) { return; } if (load_file() == 0) { System.out.println("File not found"); return; } while (true) { bChanged = 0; /* create_id(); Chat ch = Chat.getInstance(chat_group_id); ch.send("!"); */ SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm"); System.out.println("Looking at " + sdf.format(Calendar.getInstance().getTime())); Chat ch = Chat.getInstance(chat_group_id); Twitter twitter = new TwitterFactory().getInstance(); try { List<Status> statuses; statuses = twitter.getUserTimeline(twitter_user_id); //System.out.println("Showing @" + twitter_user_id + "'s user timeline."); String sText; for (Status status : statuses) { //System.out.println(status.getId()); Date d = status.getCreatedAt(); // ? Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.HOUR_OF_DAY, 7); d = cal.getTime(); sText = "@" + status.getUser().getScreenName() + " " + sdf.format(d) + " ( https://twitter.com/" + twitter_user_id + "/status/" + status.getId() + " ): \r\n" + status.getText() + "\r\n***"; for (URLEntity e : status.getURLEntities()) { sText = sText.replaceAll(e.getURL(), e.getExpandedURL()); } for (MediaEntity e : status.getMediaEntities()) { sText = sText.replaceAll(e.getURL(), e.getMediaURL()); } if (twitter_ids.indexOf(status.getId()) == -1) { System.out.println(sText); ch.send(sText); twitter_ids.add(status.getId()); bChanged = 1; } } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); //System.exit(-1); } catch (SkypeException ex) { ex.printStackTrace(); System.out.println("Failed to send message: " + ex.getMessage()); } // VK try { vk(); for (VK v : vk) { if (vk_ids.indexOf(v.getId()) == -1) { Date d = v.getDate(); // ? Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.HOUR_OF_DAY, 7); d = cal.getTime(); String sText = "@Depersonilized (VK) " + sdf.format(d) + " ( http://vk.com/Depersonilized?w=wall-0_" + v.getId() + " ): \r\n" + v.getText(); if (!"".equals(v.getAttachment())) { sText += "\r\n" + v.getAttachment(); } sText += "\r\n***"; System.out.println(sText); ch.send(sText); vk_ids.add(v.getId()); bChanged = 1; } } } catch (ParseException e) { e.printStackTrace(); System.out.println("Failed to get vk: " + e.getMessage()); //System.exit(-1); } catch (SkypeException ex) { ex.printStackTrace(); System.out.println("Failed to send message: " + ex.getMessage()); } if (bChanged == 1) { save_file(); } try { Thread.sleep(1000 * 60 * twitter_timeout); } catch (InterruptedException ex) { ex.printStackTrace(); System.out.println("Failed to sleep: " + ex.getMessage()); } } }
From source file:com.mozilla.bagheera.util.IdUtil.java
public static void main(String[] args) throws IOException { String id = "06b87727-2946-4b1e-b654-8bafb60bb995"; long timestamp = 1360493115891L; Calendar cal = Calendar.getInstance(); //cal.set(2013, Calendar.FEBRUARY, 10); cal.setTimeInMillis(timestamp);/*from www. j a va 2 s . c o m*/ System.out.println(IdUtil.hbaseShellId(id, cal.getTime())); }
From source file:com.dc.gameserver.extComponents.Kit.DateUtil.java
public static void main(String args[]) throws ParseException { //Date date1 = new Date(playerDailyTaskModel.getCreateTime().getTime()); Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(new Date(Timestamp.valueOf("2012-04-15 20:00:00").getTime())); cal2.setTime(new Date(Timestamp.valueOf("2012-04-16 12:00:00").getTime())); System.out.println("cal1.WEEK_OF_YEAR=:" + cal1.get(Calendar.WEEK_OF_YEAR)); System.out.println("cal2.WEEK_OF_YEAR=:" + cal2.get(Calendar.WEEK_OF_YEAR)); }
From source file:com.mozilla.socorro.RawDumpSizeScan.java
public static void main(String[] args) throws ParseException { String startDateStr = args[0]; String endDateStr = args[1];/*from w w w . j a v a 2 s . co m*/ // Set both start/end time and start/stop row Calendar startCal = Calendar.getInstance(); Calendar endCal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); if (!StringUtils.isBlank(startDateStr)) { startCal.setTime(sdf.parse(startDateStr)); } if (!StringUtils.isBlank(endDateStr)) { endCal.setTime(sdf.parse(endDateStr)); } DescriptiveStatistics stats = new DescriptiveStatistics(); long numNullRawBytes = 0L; HTable table = null; Map<String, Integer> rowValueSizeMap = new HashMap<String, Integer>(); try { table = new HTable(TABLE_NAME_CRASH_REPORTS); Scan[] scans = generateScans(startCal, endCal); for (Scan s : scans) { ResultScanner rs = table.getScanner(s); Iterator<Result> iter = rs.iterator(); while (iter.hasNext()) { Result r = iter.next(); ImmutableBytesWritable rawBytes = r.getBytes(); //length = r.getValue(RAW_DATA_BYTES, DUMP_BYTES); if (rawBytes != null) { int length = rawBytes.getLength(); if (length > 20971520) { rowValueSizeMap.put(new String(r.getRow()), length); } stats.addValue(length); } else { numNullRawBytes++; } if (stats.getN() % 10000 == 0) { System.out.println("Processed " + stats.getN()); System.out.println(String.format("Min: %.02f Max: %.02f Mean: %.02f", stats.getMin(), stats.getMax(), stats.getMean())); System.out.println( String.format("1st Quartile: %.02f 2nd Quartile: %.02f 3rd Quartile: %.02f", stats.getPercentile(25.0d), stats.getPercentile(50.0d), stats.getPercentile(75.0d))); System.out.println("Number of large entries: " + rowValueSizeMap.size()); } } rs.close(); } System.out.println("Finished Processing!"); System.out.println(String.format("Min: %.02f Max: %.02f Mean: %.02f", stats.getMin(), stats.getMax(), stats.getMean())); System.out.println(String.format("1st Quartile: %.02f 2nd Quartile: %.02f 3rd Quartile: %.02f", stats.getPercentile(25.0d), stats.getPercentile(50.0d), stats.getPercentile(75.0d))); for (Map.Entry<String, Integer> entry : rowValueSizeMap.entrySet()) { System.out.println(String.format("RowId: %s => Length: %d", entry.getKey(), entry.getValue())); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (table != null) { try { table.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:gov.nih.nci.ncicb.tcga.dcc.dam.util.TempClinicalDataLoader.java
public static void main(String[] args) { // first get the db connection properties String url = urlSet.get(args[1]); String user = args[2];/* w ww . j av a2 s. co m*/ String word = args[3]; // make sure we have the Oracle driver somewhere try { Class.forName("oracle.jdbc.OracleDriver"); Class.forName("org.postgresql.Driver"); } catch (Exception x) { System.out.println("Unable to load the driver class!"); System.exit(0); } // connect to the database try { dbConnection = DriverManager.getConnection(url, user, word); ClinicalBean.setDBConnection(dbConnection); } catch (SQLException x) { x.printStackTrace(); System.exit(1); } final String xmlList = args[0]; BufferedReader br = null; try { final Map<String, String> clinicalFiles = new HashMap<String, String>(); final Map<String, String> biospecimenFiles = new HashMap<String, String>(); final Map<String, String> fullFiles = new HashMap<String, String>(); //noinspection IOResourceOpenedButNotSafelyClosed br = new BufferedReader(new FileReader(xmlList)); // read the file list to get all the files to load while (br.ready()) { final String[] in = br.readLine().split("\\t"); String xmlfile = in[0]; String archive = in[1]; if (xmlfile.contains("_clinical")) { clinicalFiles.put(xmlfile, archive); } else if (xmlfile.contains("_biospecimen")) { biospecimenFiles.put(xmlfile, archive); } else { fullFiles.put(xmlfile, archive); } } Date dateAdded = Calendar.getInstance().getTime(); // NOTE!!! This deletes all data before the load starts, assuming we are re-loading everything. // a better way would be to figure out what has changed and load that, or to be able to load multiple versions of the data in the schema emptyClinicalTables(user); // load any "full" files first -- in case some archives aren't split yet for (final String file : fullFiles.keySet()) { String archive = fullFiles.get(file); System.out.println("Full file " + file + " in " + archive); // need to re-instantiate the disease-specific beans for each file createDiseaseSpecificBeans(xmlList); String disease = getDiseaseName(archive); processFullXmlFile(file, archive, disease, dateAdded); // memory leak or something... have to commit and close all connections and re-get connection // after each file to keep from using too much heap space. this troubles me, but I have never had // the time to figure out why it happens resetConnections(url, user, word); } // now process all clinical files, and insert patients and clinical data for (final String clinicalFile : clinicalFiles.keySet()) { createDiseaseSpecificBeans(xmlList); String archive = clinicalFiles.get(clinicalFile); System.out.println("Clinical file " + clinicalFile + " in " + archive); String disease = getDiseaseName(archive); processClinicalXmlFile(clinicalFile, archive, disease, dateAdded); resetConnections(url, user, word); } // now process biospecimen files for (final String biospecimenFile : biospecimenFiles.keySet()) { createDiseaseSpecificBeans(xmlList); String archive = biospecimenFiles.get(biospecimenFile); String disease = getDiseaseName(archive); System.out.println("Biospecimen file " + biospecimenFile); processBiospecimenXmlFile(biospecimenFile, archive, disease, dateAdded); resetConnections(url, user, word); } // this sets relationships between these clinical tables and data browser tables, since we delete // and reload every time setForeignKeys(); dbConnection.commit(); dbConnection.close(); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } finally { IOUtils.closeQuietly(br); } }