List of usage examples for java.util Calendar getInstance
public static Calendar getInstance()
From source file:com.timothyyip.face.FaceDetector.java
public static void main(String[] args) throws ImageReadException, IOException, ImageWriteException { Detector detector = new Detector("C:\\Code\\Java\\FaceDetector\\lib\\haarcascade_frontalface_default.xml"); flickr.photoservice.flickrresponse.Rsp response = getFlickrPhotos(); for (Photo photo : response.getPhotos().getPhoto()) { String timestamp = String.valueOf(Calendar.getInstance().getTimeInMillis()); BufferedImage originalImage = getPhysicalFlickrImage(photo); if (originalImage != null) { File originalImageFile = new File( "C:\\Code\\Java\\FaceDetector\\images\\original\\" + timestamp + ".jpg"); //Sanselan.writeImage(originalImage, originalImageFile, ImageFormat.IMAGE_FORMAT_JPEG, null); ImageIO.write(originalImage, "JPG", originalImageFile); List<Rectangle> res = detector.getFaces(originalImageFile.getAbsolutePath(), 3, 1.25f, 0.1f, 1, false);//w w w . j av a2 s .co m for (Rectangle face : res) { BufferedImage faceImage = originalImage.getSubimage(face.x, face.y, face.width, face.height); Sanselan.writeImage(faceImage, new File("C:\\Code\\Java\\FaceDetector\\images\\" + String.valueOf(Calendar.getInstance().getTimeInMillis()) + ".png"), ImageFormat.IMAGE_FORMAT_PNG, null); } } } }
From source file:MainGeneratePicasaIniFile.java
public static void main(String[] args) { try {/*from w w w .ja v a2s. co m*/ Calendar start = Calendar.getInstance(); start.set(1899, 11, 30, 0, 0); PicasawebService myService = new PicasawebService("My Application"); myService.setUserCredentials(args[0], args[1]); // Get a list of all entries URL metafeedUrl = new URL("http://picasaweb.google.com/data/feed/api/user/" + args[0] + "?kind=album"); System.out.println("Getting Picasa Web Albums entries...\n"); UserFeed resultFeed = myService.getFeed(metafeedUrl, UserFeed.class); // resultFeed. File root = new File(args[2]); File[] albuns = root.listFiles(); int j = 0; List<GphotoEntry> entries = resultFeed.getEntries(); for (int i = 0; i < entries.size(); i++) { GphotoEntry entry = entries.get(i); String href = entry.getHtmlLink().getHref(); String name = entry.getTitle().getPlainText(); for (File album : albuns) { if (album.getName().equals(name) && !href.contains("02?")) { File picasaini = new File(album, "Picasa.ini"); if (!picasaini.exists()) { StringBuilder builder = new StringBuilder(); builder.append("\n"); builder.append("[Picasa]\n"); builder.append("name="); builder.append(name); builder.append("\n"); builder.append("location="); Collection<Extension> extensions = entry.getExtensions(); for (Extension extension : extensions) { if (extension instanceof GphotoLocation) { GphotoLocation location = (GphotoLocation) extension; if (location.getValue() != null) { builder.append(location.getValue()); } } } builder.append("\n"); builder.append("category=Folders on Disk"); builder.append("\n"); builder.append("date="); String source = name.substring(0, 10); DateFormat formater = new SimpleDateFormat("yyyy-MM-dd"); Date date = formater.parse(source); Calendar end = Calendar.getInstance(); end.setTime(date); builder.append(daysBetween(start, end)); builder.append(".000000"); builder.append("\n"); builder.append(args[0]); builder.append("_lh="); builder.append(entry.getGphotoId()); builder.append("\n"); builder.append("P2category=Folders on Disk"); builder.append("\n"); URL feedUrl = new URL("https://picasaweb.google.com/data/feed/api/user/" + args[0] + "/albumid/" + entry.getGphotoId()); AlbumFeed feed = myService.getFeed(feedUrl, AlbumFeed.class); for (GphotoEntry photo : feed.getEntries()) { builder.append("\n"); builder.append("["); builder.append(photo.getTitle().getPlainText()); builder.append("]"); builder.append("\n"); long id = Long.parseLong(photo.getGphotoId()); builder.append("IIDLIST_"); builder.append(args[0]); builder.append("_lh="); builder.append(Long.toHexString(id)); builder.append("\n"); } System.out.println(builder.toString()); IOUtils.write(builder.toString(), new FileOutputStream(picasaini)); j++; } } } } System.out.println(j); System.out.println("\nTotal Entries: " + entries.size()); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainJdbcTemplate.java
public static void main(String[] args) { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.dao.jdbc"); StockDao stockDao = context.getBean("jdbcTemplateStockDao", StockDao.class); Stock stock = new Stock("ORAC", "JDBCTPL0001", "QQQQ", 120.0f, 1100, Calendar.getInstance().getTime()); stockDao.insert(stock);//from ww w. j av a2s .c o m stock = new Stock("APRS", "JDBCTPL0002", "QQQQ", 150.00F, 1500, Calendar.getInstance().getTime()); stockDao.insert(stock); stock = stockDao.findByInventoryCode("JDBCTPL0001"); if (stock != null) { System.out.println("Template Version"); System.out.println("Stock Symbol :" + stock.getSymbol()); System.out.println("Inventory Code :" + stock.getInventoryCode()); System.out.println("purchased price:" + stock.getSharePrice()); System.out.println("Exchange ID:" + stock.getExchangeId()); System.out.println("Quantity Available :" + stock.getQuantityAvailable()); } }
From source file:TextVerifyInputFormatDate.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); final Text text = new Text(shell, SWT.BORDER); text.setText("YYYY/MM/DD"); ;/*w w w. j ava2 s.co m*/ final Calendar calendar = Calendar.getInstance(); text.addListener(SWT.Verify, new Listener() { boolean ignore; public void handleEvent(Event e) { if (ignore) return; e.doit = false; StringBuffer buffer = new StringBuffer(e.text); char[] chars = new char[buffer.length()]; buffer.getChars(0, chars.length, chars, 0); if (e.character == '\b') { for (int i = e.start; i < e.end; i++) { switch (i) { case 0: /* [Y]YYY */ case 1: /* Y[Y]YY */ case 2: /* YY[Y]Y */ case 3: /* YYY[Y] */ { buffer.append('Y'); break; } case 5: /* [M]M */ case 6: /* M[M] */ { buffer.append('M'); break; } case 8: /* [D]D */ case 9: /* D[D] */ { buffer.append('D'); break; } case 4: /* YYYY[/]MM */ case 7: /* MM[/]DD */ { buffer.append('/'); break; } default: return; } } text.setSelection(e.start, e.start + buffer.length()); ignore = true; text.insert(buffer.toString()); ignore = false; text.setSelection(e.start, e.start); return; } int start = e.start; if (start > 9) return; int index = 0; for (int i = 0; i < chars.length; i++) { if (start + index == 4 || start + index == 7) { if (chars[i] == '/') { index++; continue; } buffer.insert(index++, '/'); } if (chars[i] < '0' || '9' < chars[i]) return; if (start + index == 5 && '1' < chars[i]) return; /* [M]M */ if (start + index == 8 && '3' < chars[i]) return; /* [D]D */ index++; } String newText = buffer.toString(); int length = newText.length(); StringBuffer date = new StringBuffer(text.getText()); date.replace(e.start, e.start + length, newText); calendar.set(Calendar.YEAR, 1901); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DATE, 1); String yyyy = date.substring(0, 4); if (yyyy.indexOf('Y') == -1) { int year = Integer.parseInt(yyyy); calendar.set(Calendar.YEAR, year); } String mm = date.substring(5, 7); if (mm.indexOf('M') == -1) { int month = Integer.parseInt(mm) - 1; int maxMonth = calendar.getActualMaximum(Calendar.MONTH); if (0 > month || month > maxMonth) return; calendar.set(Calendar.MONTH, month); } String dd = date.substring(8, 10); if (dd.indexOf('D') == -1) { int day = Integer.parseInt(dd); int maxDay = calendar.getActualMaximum(Calendar.DATE); if (1 > day || day > maxDay) return; calendar.set(Calendar.DATE, day); } else { if (calendar.get(Calendar.MONTH) == Calendar.FEBRUARY) { char firstChar = date.charAt(8); if (firstChar != 'D' && '2' < firstChar) return; } } text.setSelection(e.start, e.start + length); ignore = true; text.insert(newText); ignore = false; } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:gr.seab.r2rml.beans.Main.java
public static void main(String[] args) { Calendar c0 = Calendar.getInstance(); long t0 = c0.getTimeInMillis(); CommandLineParser cmdParser = new PosixParser(); Options cmdOptions = new Options(); cmdOptions.addOption("p", "properties", true, "define the properties file. Example: r2rml-parser -p r2rml.properties"); cmdOptions.addOption("h", "print help", false, "help"); String propertiesFile = "r2rml.properties"; try {/* w w w. j a va2s .c om*/ CommandLine line = cmdParser.parse(cmdOptions, args); if (line.hasOption("h")) { HelpFormatter help = new HelpFormatter(); help.printHelp("r2rml-parser\n", cmdOptions); System.exit(0); } if (line.hasOption("p")) { propertiesFile = line.getOptionValue("p"); } } catch (ParseException e1) { //e1.printStackTrace(); log.error("Error parsing command line arguments."); System.exit(1); } try { if (StringUtils.isNotEmpty(propertiesFile)) { properties.load(new FileInputStream(propertiesFile)); log.info("Loaded properties from " + propertiesFile); } } catch (FileNotFoundException e) { //e.printStackTrace(); log.error("Properties file not found (" + propertiesFile + ")."); System.exit(1); } catch (IOException e) { //e.printStackTrace(); log.error("Error reading properties file (" + propertiesFile + ")."); System.exit(1); } ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml"); Database db = (Database) context.getBean("db"); db.setProperties(properties); Parser parser = (Parser) context.getBean("parser"); parser.setProperties(properties); MappingDocument mappingDocument = parser.parse(); mappingDocument.getTimestamps().add(t0); //0 Started mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //1 Finished parsing. Starting generating result model. Generator generator = (Generator) context.getBean("generator"); generator.setProperties(properties); generator.setResultModel(parser.getResultModel()); //Actually do the output generator.createTriples(mappingDocument); context.close(); Calendar c1 = Calendar.getInstance(); long t1 = c1.getTimeInMillis(); log.info("Finished in " + (t1 - t0) + " milliseconds. Done."); mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //5 Finished. //log.info("5 Finished."); //output the result for (int i = 0; i < mappingDocument.getTimestamps().size(); i++) { if (i > 0) { long l = (mappingDocument.getTimestamps().get(i).longValue() - mappingDocument.getTimestamps().get(i - 1).longValue()); //System.out.println(l); log.info(String.valueOf(l)); } } log.info("Parse. Generate in memory. Dump to disk/database. Log. - Alltogether in " + String.valueOf(mappingDocument.getTimestamps().get(5).longValue() - mappingDocument.getTimestamps().get(0).longValue()) + " msec."); log.info("Done."); System.out.println("Done."); }
From source file:org.ptm.translater.App.java
public static void main(String... args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("file:src/main/resources/spring/datasource.xml"); ctx.refresh();//from ww w. j a v a 2 s . c om GenericXmlApplicationContext ctx2 = new GenericXmlApplicationContext(); ctx2.load("file:src/main/resources/spring/datasource2.xml"); ctx2.refresh(); ArchiveDao archiveDao = ctx.getBean("archiveDao", ArchiveDao.class); List<Archive> archives = archiveDao.findAll(); UserDao userDao = ctx2.getBean("userDao", UserDao.class); TagDao tagDao = ctx2.getBean("tagDao", TagDao.class); PhotoDao photoDao = ctx2.getBean("photoDao", PhotoDao.class); List<Tag> tagz = tagDao.findAll(); Map<String, Long> hashTags = new HashMap<String, Long>(); for (Tag tag : tagz) hashTags.put(tag.getName(), tag.getId()); MongoCache cache = new MongoCache(); Calendar calendar = Calendar.getInstance(); Map<String, String> associates = new HashMap<String, String>(); for (Archive archive : archives) { AppUser appUser = new AppUser(); appUser.setName(archive.getName()); appUser.setEmail(archive.getUid() + "@mail.th"); appUser.setPassword("123456"); Role role = new Role(); role.setRoleId("ROLE_USER"); appUser.setRole(role); userDao.save(appUser); System.out.println("\tCreate user " + appUser); for (Photo photo : archive.getPhotos()) { // ? ??? if (cache.contains(photo.getUid())) continue; System.out.println("\tNew photo"); org.ptm.translater.ch2.domain.Photo photo2 = new org.ptm.translater.ch2.domain.Photo(); photo2.setAppUser(appUser); photo2.setName(photo.getTitle()); photo2.setLicense((byte) 7); photo2.setDescription(photo.getDescription()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { calendar.setTime(sdf.parse(photo.getTaken())); if (calendar.get(Calendar.YEAR) != 0 && calendar.get(Calendar.YEAR) > 1998) continue; photo2.setYear(calendar.get(Calendar.YEAR)); photo2.setMonth(calendar.get(Calendar.MONTH) + 1); photo2.setDay(calendar.get(Calendar.DAY_OF_MONTH)); } catch (Exception ex) { ex.printStackTrace(); } if (photo.getLongitude() != null && photo.getLongitude().length() > 0) { // String key = photo.getLongitude()+"#"+photo.getLatitude(); photo2.setLatitude(photo.getLatitude()); photo2.setLongitude(photo.getLongitude()); // if (associates.containsKey(key)) { // photo2.setAddress(associates.get(key)); // } else { // Geocoder geocoder = new Geocoder(); // GeocoderRequestBuilder geocoderRequest = new GeocoderRequestBuilder(); // GeocoderRequest request = // geocoderRequest.setLocation(new LatLng(photo.getLongitude(), photo.getLatitude())).getGeocoderRequest(); // // GeocodeResponse response = geocoder.geocode(request); // if (response.getResults().size() > 0) { // photo2.setAddress(response.getResults().get(0).getFormattedAddress()); // } // try { Thread.sleep(2000); } catch (InterruptedException ex) { ex.printStackTrace(); } // } } System.out.println("\tFind tags"); Set<Tag> tags = new HashSet<Tag>(); for (org.ptm.translater.ch1.domain.Tag tag : photo.getTags()) { Tag item = new Tag(); item.setName(tag.getName()); if (hashTags.containsKey(tag.getName())) { item.setId(hashTags.get(tag.getName())); } else { tagDao.save(item); hashTags.put(item.getName(), item.getId()); } System.out.println("\t\tinit tag " + tag.getName()); tags.add(item); } photo2.setTags(tags); System.out.println("\tFind " + tags.size() + " tags"); photoDao.save(photo2); System.out.println("\tSave photo"); Imaginator img = new Imaginator(); img.setFolder(photo2.getId().toString()); img.setPath(); for (PhotoSize ps : photo.getSizes()) { if (ps.getLabel().equals("Original")) { img.setImage(ps.getSource()); break; } } img.generate(); System.out.println("\tGenerate image of photo"); img = null; cache.create(photo.getUid()); cache.create(photo2); System.out.println("Generate: " + photo2); } } }
From source file:com.rabbitmq.perf.PerfTest.java
public static void main(String[] args) { Options options = getOptions();//w ww . j a v a 2 s .co m CommandLineParser parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('?')) { usage(options); System.exit(0); } String testID = new SimpleDateFormat("HHmmss-SSS").format(Calendar.getInstance().getTime()); testID = strArg(cmd, 'd', "test-" + testID); String exchangeType = strArg(cmd, 't', "direct"); String exchangeName = strArg(cmd, 'e', exchangeType); String queueNames = strArg(cmd, 'u', ""); String routingKey = strArg(cmd, 'k', null); boolean randomRoutingKey = cmd.hasOption('K'); int samplingInterval = intArg(cmd, 'i', 1); float producerRateLimit = floatArg(cmd, 'r', 0.0f); float consumerRateLimit = floatArg(cmd, 'R', 0.0f); int producerCount = intArg(cmd, 'x', 1); int consumerCount = intArg(cmd, 'y', 1); int producerTxSize = intArg(cmd, 'm', 0); int consumerTxSize = intArg(cmd, 'n', 0); long confirm = intArg(cmd, 'c', -1); boolean autoAck = cmd.hasOption('a'); int multiAckEvery = intArg(cmd, 'A', 0); int channelPrefetch = intArg(cmd, 'Q', 0); int consumerPrefetch = intArg(cmd, 'q', 0); int minMsgSize = intArg(cmd, 's', 0); int timeLimit = intArg(cmd, 'z', 0); int producerMsgCount = intArg(cmd, 'C', 0); int consumerMsgCount = intArg(cmd, 'D', 0); List<?> flags = lstArg(cmd, 'f'); int frameMax = intArg(cmd, 'M', 0); int heartbeat = intArg(cmd, 'b', 0); boolean predeclared = cmd.hasOption('p'); String uri = strArg(cmd, 'h', "amqp://localhost"); //setup PrintlnStats stats = new PrintlnStats(testID, 1000L * samplingInterval, producerCount > 0, consumerCount > 0, (flags.contains("mandatory") || flags.contains("immediate")), confirm != -1); ConnectionFactory factory = new ConnectionFactory(); factory.setShutdownTimeout(0); // So we still shut down even with slow consumers factory.setUri(uri); factory.setRequestedFrameMax(frameMax); factory.setRequestedHeartbeat(heartbeat); MulticastParams p = new MulticastParams(); p.setAutoAck(autoAck); p.setAutoDelete(true); p.setConfirm(confirm); p.setConsumerCount(consumerCount); p.setConsumerMsgCount(consumerMsgCount); p.setConsumerRateLimit(consumerRateLimit); p.setConsumerTxSize(consumerTxSize); p.setExchangeName(exchangeName); p.setExchangeType(exchangeType); p.setFlags(flags); p.setMultiAckEvery(multiAckEvery); p.setMinMsgSize(minMsgSize); p.setPredeclared(predeclared); p.setConsumerPrefetch(consumerPrefetch); p.setChannelPrefetch(channelPrefetch); p.setProducerCount(producerCount); p.setProducerMsgCount(producerMsgCount); p.setProducerTxSize(producerTxSize); p.setQueueNames(Arrays.asList(queueNames.split(","))); p.setRoutingKey(routingKey); p.setRandomRoutingKey(randomRoutingKey); p.setProducerRateLimit(producerRateLimit); p.setTimeLimit(timeLimit); MulticastSet set = new MulticastSet(stats, factory, p, testID); set.run(true); stats.printFinal(); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); usage(options); } catch (Exception e) { System.err.println("Main thread caught exception: " + e); e.printStackTrace(); System.exit(1); } }
From source file:DayWeek.java
public static void main(String[] av) { //+//from w ww.ja va 2s . c om Calendar c = Calendar.getInstance(); // today System.out.println("Year: " + c.get(Calendar.YEAR)); System.out.println("Month: " + c.get(Calendar.MONTH)); System.out.println("Day: " + c.get(Calendar.DAY_OF_MONTH)); System.out.println("Day of week = " + c.get(Calendar.DAY_OF_WEEK)); System.out.println("Day of year = " + c.get(Calendar.DAY_OF_YEAR)); System.out.println("Week in Year: " + c.get(Calendar.WEEK_OF_YEAR)); System.out.println("Week in Month: " + c.get(Calendar.WEEK_OF_MONTH)); System.out.println("Day of Week in Month: " + c.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println("Hour: " + c.get(Calendar.HOUR)); System.out.println("AM or PM: " + c.get(Calendar.AM_PM)); System.out.println("Hour (24-hour clock): " + c.get(Calendar.HOUR_OF_DAY)); System.out.println("Minute: " + c.get(Calendar.MINUTE)); System.out.println("Second: " + c.get(Calendar.SECOND)); //- }
From source file:CalCalcs.java
public static void main(String[] argv) { //+/*from www . j a v a 2 s .com*/ Calendar c = Calendar.getInstance(); System.out.println("I got a " + c.getClass()); c.set(1951, 03, 24, 12, 30, 0); System.out.println("I set it to " + c.getTime().toString()); System.out.println("I actually set the year to " + c.get(Calendar.YEAR)); System.out.println("In milliseconds, that's " + c.getTime().getTime()); System.out.println("Or, in seconds, " + c.getTime().getTime() / 1000); //- }
From source file:TestFormat.java
public static void main(String[] args) { long n = 461012; System.out.format("%d%n", n); System.out.format("%08d%n", n); System.out.format("%+8d%n", n); System.out.format("%,8d%n", n); System.out.format("%+,8d%n%n", n); double pi = Math.PI; System.out.format("%f%n", pi); System.out.format("%.3f%n", pi); System.out.format("%10.3f%n", pi); System.out.format("%-10.3f%n", pi); System.out.format(Locale.FRANCE, "%-10.4f%n%n", pi); Calendar c = Calendar.getInstance(); System.out.format("%tB %te, %tY%n", c, c, c); System.out.format("%tl:%tM %tp%n", c, c, c); System.out.format("%tD%n", c); }