Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-06-2007, 09:09 AM
Member
 
Join Date: Nov 2007
Location: taguig city, philippines
Posts: 4
vhannierose is on a distinguished road
Send a message via AIM to vhannierose Send a message via Yahoo to vhannierose
Hi! Pls help me with this
Hi Everybody!

I'm just a newbie here at Java forums as well as I'm just also learning Java right now.

Do you know resources online or books as my reference while I'm just learning java.

Also, Can you help me with this?? Thank you very much.. Any suggestions??

Code:
package com.jds.architecture.utilities; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * Transform strategy object used to transform a <code>Calendar</code> instance * to a <code>String</code>. This class uses the <code>java.text.DateFormat</code> * to provide the formatting. * * The overriden method <code>transform(Object target)</code> accepts a <code>java.util.Calendar</code> * or <code>java.util.Date</code>object representing the date to be transformed. RuntimeExceptions will be thrown when any other * argument is passed to the method. * * Classes that implement the <code>TransformStrategy</code> interface should be * passed to <code>Transformer</code> objects via their constructor or to the * <code>Transformer.transform(TransformStrategy, Object)</code> method. * * @see Transformer * @see TransformStrategy */ public class CalendarToString implements TransformStrategy{ private DateFormat df; /** * Constructs a new strategy object using the specified format for its transform rule. * * @param format format to be used by this transfrom strategy * @see java.text.DateFormat */ public CalendarToString(int format) { df = DateFormat.getDateInstance(format); } /** * Constructs a new strategy object using the default format DateFormat.FULL for its * transform rule. */ public CalendarToString(){ //df = DateFormat.getDateInstance(DateFormat.FULL); df = new SimpleDateFormat("dd-MMM-yy"); } /** * Returns the specified argument <code>Calendar<code> instance as a string * * @param target <code>Calendar</code> instance to transform * @return formatted string representing the <code>Calendar</code> instance * */ public Object transform(Object target) { return null; } }

Last edited by JavaBean : 11-06-2007 at 09:20 AM. Reason: Code placed inside [code] tag.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-06-2007, 08:47 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,191
hardwired is on a distinguished road
Code:
import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class CalendarToStringTest { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); System.out.println("now = " + now); CalendarToString ctsDefault = new CalendarToString(); System.out.println("ctsDefault(now) = " + ctsDefault.transform(now)); System.out.println("ctsDefault(calendar) = " + ctsDefault.transform(calendar)); CalendarToString ctsMedium = new CalendarToString(DateFormat.MEDIUM); System.out.println("ctsMedium(now) = " + ctsMedium.transform(now)); System.out.println("ctsMedium(calendar) = " + ctsMedium.transform(calendar)); // Test IllegalArgumentException. new CalendarToString().transform("hello world"); } } /** * Transform strategy object used to transform a <code>Calendar</code> instance * to a <code>String</code>. This class uses the <code>java.text.DateFormat</code> * to provide the formatting. * * The overriden method <code>transform(Object target)</code> accepts a <code>java.util.Calendar</code> * or <code>java.util.Date</code>object representing the date to be transformed. * RuntimeExceptions will be thrown when any other argument is passed to the method. * * Classes that implement the <code>TransformStrategy</code> interface should be * passed to <code>Transformer</code> objects via their constructor or to the * <code>Transformer.transform(TransformStrategy, Object)</code> method. * * @see Transformer * @see TransformStrategy */ class CalendarToString implements TransformStrategy { private DateFormat df; /** * Constructs a new strategy object using the specified format for its * transform rule. * * @param format format to be used by this transfrom strategy * @see java.text.DateFormat */ public CalendarToString(int format) { df = DateFormat.getDateInstance(format); } /** * Constructs a new strategy object using the default format DateFormat.FULL for its * transform rule. */ public CalendarToString() { df = DateFormat.getDateInstance(DateFormat.FULL); //df = new SimpleDateFormat("dd-MMM-yy"); } /** * Returns the specified argument <code>Calendar<code> instance as a string * * @param target <code>Calendar</code> instance to transform * @return formatted string representing the <code>Calendar</code> instance * */ public Object transform(Object target) { String parsed = null; if(target instanceof Date) parsed = df.format((Date)target); else if(target instanceof Calendar) parsed = df.format(((Calendar)target).getTime()); else throw new IllegalArgumentException("CalendarToString.transform for: " + target.getClass().getName()); return parsed; } } interface TransformStrategy { public Object transform(Object o); }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-06-2007, 08:51 PM
Member
 
Join Date: Nov 2007
Posts: 7
assamhammad is on a distinguished road
salaam i m new to this forum
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 10:57 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org