Re: [Pvmanager-devel] org.epics.pvmanager.data.Display
Brought to you by:
carcassi,
epics-jenkins
|
From: Marty K. <mrk...@co...> - 2010-08-30 19:05:21
|
On 08/30/2010 10:28 AM, Carcassi, Gabriele wrote:
> Hi Marty,
>
>> The method
>> NumberFormat getFormat();
>> Is very Java specific.
> Yes, it's intended. This way we can "hide" the different implementations
> for CA 3 and CA V. The data on the wire (and on the server) is indeed a
> String for pvData (the current precision for CA 3).
>
OK now I get it. Thus implement something like the following:
public class MumberFormatTest extends TestCase {
public void testNumberFormat() {
NumberFormat nf = new NumberFormatDouble("%12.2f");
StringBuffer sb = new StringBuffer();
FieldPosition fp = new FieldPosition(0);
sb = nf.format(1.12, sb, fp);
System.out.println(sb.toString());
ParsePosition pp = new ParsePosition(0);
double xxx = (nf.parse(sb.toString(),pp)).doubleValue();
System.out.println("parse is "+ xxx);
}
static class NumberFormatDouble extends NumberFormat {
private final String format;
private NumberFormatDouble (String format) {
this.format = format;
}
@Override
public StringBuffer format(double arg0, StringBuffer
arg1,FieldPosition arg2) {
return arg1.append(String.format(format, arg0));
}
@Override
public StringBuffer format(long arg0, StringBuffer
arg1,FieldPosition arg2) {
throw new IllegalArgumentException("long not supported");
}
@Override
public Number parse(String arg0, ParsePosition arg1) {
return Double.parseDouble(arg0.substring(arg1.getIndex()));
}
}
}
Marty
> Gabriele
>
> -----Original Message-----
> From: Marty Kraimer [mailto:mrk...@co...]
> Sent: Monday, August 30, 2010 10:14 AM
> To: pvm...@li...
> Subject: [Pvmanager-devel] org.epics.pvmanager.data.Display
>
>
> The method
>
> NumberFormat getFormat();
>
> Is very Java specific.
>
> Instead how about
>
> String getFormat();
>
> Use C style formats. Examples are "14.2e", "14.2f","10d"
>
> All of these will work on both c, c++, and Java (since java supports
> printf).
>
> Marty
>
> ------------------------------------------------------------------------
> ------
> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
> Be part of this innovative community and reach millions of netbook users
>
> worldwide. Take advantage of special opportunities to increase revenue
> and
> speed time-to-market. Join now, and jumpstart your future.
> http://p.sf.net/sfu/intel-atom-d2d
> _______________________________________________
> Pvmanager-devel mailing list
> Pvm...@li...
> https://lists.sourceforge.net/lists/listinfo/pvmanager-devel
>
|