1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

merge from rustici cs2j_two branch to 431fb7d3c6d22669a8ec51d3421dacc10dc7b217

This commit is contained in:
Kevin Glynn 2012-02-07 10:46:47 +01:00
parent 86bacb0014
commit f6e7958041
10 changed files with 112 additions and 38 deletions

View File

@ -118,8 +118,10 @@
<Return>System.Void</Return> <Return>System.Void</Return>
</Method> </Method>
<Method> <Method>
<Imports /> <Imports>
<Java>${this:16}.reverse()</Java> <Import>java.util.Collections</Import>
</Imports>
<Java>Collections.reverse(${this:16})</Java>
<Params> <Params>
</Params> </Params>
<Name>Reverse</Name> <Name>Reverse</Name>
@ -171,7 +173,7 @@
</Params> </Params>
<Type>System.Object</Type> <Type>System.Object</Type>
<Get>${this:16}.get(${i})</Get> <Get>${this:16}.get(${i})</Get>
<Set>${this:16}.add(${i}, ${value})</Set> <Set>${this:16}.set(${i}, ${value})</Set>
</Indexer> </Indexer>
</Indexers> </Indexers>
<Constructors> <Constructors>

View File

@ -23,6 +23,13 @@
<Java>${expr}</Java> <Java>${expr}</Java>
</Iterable> </Iterable>
<Properties> <Properties>
<Property>
<Imports />
<Java>${this:16}.size()</Java>
<Type>System.Int32</Type>
<Name>Count</Name>
<Get>${this:16}.size()</Get>
</Property>
</Properties> </Properties>
<Methods> <Methods>
<Method> <Method>

View File

@ -99,5 +99,12 @@
<Name>Values</Name> <Name>Values</Name>
<Get>${this:16}.values()</Get> <Get>${this:16}.values()</Get>
</Property> </Property>
<Property>
<Imports />
<Java>${this:16}.size()</Java>
<Type>System.Int32</Type>
<Name>Count</Name>
<Get>${this:16}.size()</Get>
</Property>
</Properties> </Properties>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>BBHaGzWIzkVajkMtIotxcu6p5VY=</DigestValue></Reference></SignedInfo><SignatureValue>WOOzmkxA0yBm1tFVetTcQxQc7SztNyQygCPbn5vaHLtHI/MoQMuTuytu5BrGb4UJ7KG68galgfmWUlUD99Txs44X+XdHA7wY0XcAUwXHV+/uti6FicyhHw7mDr9Bj4+Rjq4RIA2I0gS5P25V9nMEIEQCD3/jjc+wc4Lt5AHw/b4=</SignatureValue></Signature></Interface> <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>BBHaGzWIzkVajkMtIotxcu6p5VY=</DigestValue></Reference></SignedInfo><SignatureValue>WOOzmkxA0yBm1tFVetTcQxQc7SztNyQygCPbn5vaHLtHI/MoQMuTuytu5BrGb4UJ7KG68galgfmWUlUD99Txs44X+XdHA7wY0XcAUwXHV+/uti6FicyhHw7mDr9Bj4+Rjq4RIA2I0gS5P25V9nMEIEQCD3/jjc+wc4Lt5AHw/b4=</SignatureValue></Signature></Interface>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
This file is This file is
@ -125,7 +125,7 @@
<Return>System.Void</Return> <Return>System.Void</Return>
</Method> </Method>
<Method> <Method>
<Java>${this:16}.toArray(new ${T}[${this}.size()])</Java> <Java>((${T}[]) ${this:16}.toArray())</Java>
<Params> <Params>
</Params> </Params>
<Name>ToArray</Name> <Name>ToArray</Name>

View File

@ -9,9 +9,9 @@
--> -->
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0"> <Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
<Imports> <Imports>
<Import>javax.mail.internet.InternetAddress</Import> <Import>CS2JNet.System.Net.Mail.MailAddress</Import>
</Imports> </Imports>
<Java>InternetAddress</Java> <Java>MailAddress</Java>
<Name>System.Net.Mail.MailAddress</Name> <Name>System.Net.Mail.MailAddress</Name>
<Uses /> <Uses />
<Inherits> <Inherits>
@ -24,9 +24,9 @@
<Constructors> <Constructors>
<Constructor> <Constructor>
<Imports> <Imports>
<Import>javax.mail.internet.InternetAddress</Import> <Import>CS2JNet.System.Net.Mail.MailAddress</Import>
</Imports> </Imports>
<Java>new InternetAddress(${address})</Java> <Java>new MailAddress(${address})</Java>
<Params> <Params>
<Param> <Param>
<Type>System.String</Type> <Type>System.String</Type>

View File

@ -26,6 +26,15 @@
</Params> </Params>
<Name>Equals</Name> <Name>Equals</Name>
<Return>System.Boolean</Return> <Return>System.Boolean</Return>
</Method>
<!-- added for Array.clone support, but since in java this is on Object, should be at System.Object level in
translation for those .net objects which have Clone().-->
<Method>
<Imports />
<Java>${this:16}.clone(${obj})</Java>
<Params />
<Name>Clone</Name>
<Return>System.Object</Return>
</Method> </Method>
<Method> <Method>
<Imports /> <Imports />
@ -60,6 +69,24 @@
<Name>GetHashCode</Name> <Name>GetHashCode</Name>
<Return>System.Int</Return> <Return>System.Int</Return>
</Method> </Method>
<Method>
<Imports>
<Import>CS2JNet.System.ObjectSupport</Import>
</Imports>
<Java>ObjectSupport.Equals(${obj1}, ${obj2})</Java>
<Params>
<Param>
<Type>System.Object</Type>
<Name>obj1</Name>
</Param>
<Param>
<Type>System.Object</Type>
<Name>obj2</Name>
</Param>
</Params>
<Name>Equals</Name>
<Return>System.Boolean</Return>
</Method>
</Methods> </Methods>
<Properties /> <Properties />
<Events /> <Events />

View File

@ -40,10 +40,7 @@
<Return>System.Int32</Return> <Return>System.Int32</Return>
</Method> </Method>
<Method> <Method>
<Imports> <Java>${this:16}.compareTo(${arg1})</Java>
<Import>CS2JNet.System.StringSupport</Import>
</Imports>
<Java>StringSupport.Compare(${arg1}, ${this})</Java>
<Params> <Params>
<Param> <Param>
<Type>System.String</Type> <Type>System.String</Type>
@ -68,7 +65,7 @@
<Name>arg2</Name> <Name>arg2</Name>
</Param> </Param>
<Param> <Param>
<Type>System.Bool</Type> <Type>System.Boolean</Type>
<Name>isCaseSensitive</Name> <Name>isCaseSensitive</Name>
</Param> </Param>
</Params> </Params>

View File

@ -115,6 +115,17 @@
<Name>GetTypeCode</Name> <Name>GetTypeCode</Name>
<Return>System.TypeCode</Return> <Return>System.TypeCode</Return>
</Method> </Method>
<Method>
<Return>System.Boolean</Return>
<Name>IsAssignableFrom</Name>
<Params>
<Param>
<Name>arg1</Name>
<Type>System.Type</Type>
</Param>
</Params>
<Java>${this:16}.isAssignableFrom(${arg1})</Java>
</Method>
</Methods> </Methods>
<Properties> <Properties>
<Property> <Property>

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2007,2008,2009,2010 Rustici Software, LLC Copyright 2007,2008,2009,2010 Rustici Software, LLC
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com) Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
@ -33,7 +33,7 @@ import CS2JNet.JavaSupport.util.LocaleSupport;
public class DateTimeSupport { public class DateTimeSupport {
public static String ToString(Date d, String format, Locale loc) { public static String ToString(Date d, String format, Locale loc) {
SimpleDateFormat formatter = null; SimpleDateFormat formatter = null;
if (format.equals("s")) { if (format.equals("s")) {
//TODO: Is this really a db-friendly sortable format? //TODO: Is this really a db-friendly sortable format?
@ -43,14 +43,22 @@ public class DateTimeSupport {
formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'Z'", loc); formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'Z'", loc);
} else if (format.equals("yyyy-MM-ddTHH:mm:ss.ffZ")) { } else if (format.equals("yyyy-MM-ddTHH:mm:ss.ffZ")) {
formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'", loc); formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'", loc);
} else { } else if (format.equals("yyyy-MM-ddTHH:mm:ss.fffZ")) {
formatter = new SimpleDateFormat(format, loc); formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", loc);
} else if (format.equals("ddd',' dd MMM yyyy HH':'mm':'ss'.'fff GMT")) {
formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss.SSS 'GMT'");
} else {
formatter = new SimpleDateFormat(format, loc);
}
if (formatter.toPattern().contains("'Z'") || formatter.toPattern().contains("'GMT'")){
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
} }
if (d instanceof DateTZ) { if (d instanceof DateTZ) {
formatter.setTimeZone(((DateTZ)d).getTimeZone()); formatter.setTimeZone(((DateTZ)d).getTimeZone());
} }
return formatter.format(d); return formatter.format(d);
} }
@ -75,10 +83,14 @@ public class DateTimeSupport {
private static final String[] DATE_FORMATS = new String[] { private static final String[] DATE_FORMATS = new String[] {
"E MMM d HH:mm:ss Z yyyy", "E MMM d HH:mm:ss Z yyyy",
"MM/dd/yyyy HH:mm:ss a", "MM/dd/yyyy HH:mm:ss a",
"yyyy-MM-dd HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"yyyy-MM-dd'T'HH:mm:ssZ",
"yyyy-MM-dd'T'HH:mm:ss'Z'",
"yyyy-MM-dd'T'HH:mm:ss'.'SSSZ", "yyyy-MM-dd'T'HH:mm:ss'.'SSSZ",
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ss",
"yyyy-MM-dd HH:mm:ss'Z'",
"yyyy-MM-dd"}; "yyyy-MM-dd"};
public static Date parse(String s) throws ParseException public static Date parse(String s) throws ParseException
@ -92,21 +104,21 @@ public class DateTimeSupport {
return parse(val, DATE_FORMATS, Locale.getDefault(), utc); return parse(val, DATE_FORMATS, Locale.getDefault(), utc);
} }
protected static String trimMilliSecondsToThreeDigits(String dateString){ protected static String trimMilliSecondsToThreeDigits(String dateString){
String val = dateString; String val = dateString;
if(val != null){ if(val != null){
int milliStart = val.lastIndexOf("."); int milliStart = val.lastIndexOf(".");
if(milliStart != -1){ if(milliStart != -1){
milliStart = milliStart + 1; milliStart = milliStart + 1;
int milliEnd = val.lastIndexOf("Z"); int milliEnd = Math.max(val.lastIndexOf("+"), val.lastIndexOf("Z"));
milliEnd = (milliEnd == -1) ? val.length() : milliEnd; milliEnd = (milliEnd == -1) ? val.length() : milliEnd;
if((milliEnd - milliStart) > 3){ if((milliEnd - milliStart) > 3){
String newMillis = val.substring(milliStart).substring(0, 3); String newMillis = val.substring(milliStart).substring(0, 3);
val = val.substring(0, milliStart) + newMillis + val.substring(milliEnd, val.length()); val = val.substring(0, milliStart) + newMillis + val.substring(milliEnd, val.length());
} }
} }
} }
return val; return val;
} }
public static Date parse(String s, String f) throws ParseException public static Date parse(String s, String f) throws ParseException
@ -132,7 +144,7 @@ public class DateTimeSupport {
try try
{ {
SimpleDateFormat sdf = new SimpleDateFormat(f); SimpleDateFormat sdf = new SimpleDateFormat(f);
if(utc){ if(utc || f.contains("Z")){
sdf.setTimeZone(TimeZone.getTimeZone("UTC")); sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
} }
Date d = sdf.parse(s); Date d = sdf.parse(s);
@ -167,7 +179,7 @@ public class DateTimeSupport {
cal.add(field, amount); cal.add(field, amount);
return cal.getTime(); return cal.getTime();
} }
public static boolean equals(Date d1, Date d2) { public static boolean equals(Date d1, Date d2) {
return d1 == d2 || (d1 != null && d2 != null && d1.getTime() == d2.getTime()); return d1 == d2 || (d1 != null && d2 != null && d1.getTime() == d2.getTime());
} }

View File

@ -0,0 +1,11 @@
package CS2JNet.System;
public class ObjectSupport {
public static boolean Equals(Object obj1, Object obj2) {
if (obj1 == null) {
return obj2 == null;
} else {
return obj1.equals(obj2);
}
}
}