All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javolution.text.DefaultTextFormat Maven / Gradle / Ivy

/*
 * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
 * Copyright (C) 2012 - Javolution (http://javolution.org/)
 * All rights reserved.
 * 
 * Permission to use, copy, modify, and distribute this software is
 * freely granted, provided that this notice is preserved.
 */
package javolution.text;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


/**
 * 

Specifies the default text format of a class (for parsing/formatting). * The default format is typically used by the {@link Object#toString()} * method and can be locally overridden in the scope of a * {@link javolution.text.TextContext TextContext}.

* * [code] * @DefaultTextFormat(Complex.Cartesian.class) * public class Complex { * public String toString() { // Uses the default format unless locally overridden. * return TextContext.toString(this); * } * public static Complex valueOf(CharSequence csq) { * return TextContext.parse(csq, Complex.class); * } * public static class Cartesian extends TextFormat { ... } * public static class Polar extends TextFormat { ... } * } * ... * TextContext ctx = TextContext.enter(); // Enters a local textual context. * try { * ctx.setFormat(Complex.class, new Complex.Polar()); // Configure the local context. * System.out.println(complexMatrix); // Displays complex numbers in polar coordinates. * } finally { * ctx.exit(); // Exits local context (reverts to previous Cartesian format). * }[/code] * * @author Jean-Marie Dautelle * @version 6.0, July 21, 2013 */ @Documented @Inherited @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface DefaultTextFormat { /** * Returns the default text format of the annotated class. */ Class> value(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy