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

add some built in delegates, predicate and action

This commit is contained in:
Kevin Glynn 2011-09-21 14:35:43 +02:00
parent 946bd4741a
commit 78d2ed1e29
7 changed files with 391 additions and 3 deletions

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
-->
<Delegate 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>
<Import>CS2JNet.System.Action</Import>
</Imports>
<Java>Action*[${T}]*</Java>
<Name>System.Action</Name>
<TypeParams>
<Name>T</Name>
</TypeParams>
<Uses />
<Inherits>
<Type>System.Object</Type>
</Inherits>
<Methods>
<Method static="true">
<Imports>
<Import>CS2JNet.System.__MultiAction</Import>
</Imports>
<Java>__MultiAction.Combine(${a},${b})</Java>
<Params>
<Param>
<Type>System.Action*[T]*</Type>
<Name>a</Name>
</Param>
<Param>
<Type>System.Action*[T]*</Type>
<Name>b</Name>
</Param>
</Params>
<Name>Combine</Name>
<TypeParams>
<Name>T</Name>
</TypeParams>
<Return>System.Action*[T]*</Return>
</Method>
<Method static="true">
<Imports>
<Import>CS2JNet.System.__MultiAction</Import>
</Imports>
<Java>__MultiAction.Remove(${a},${b})</Java>
<Params>
<Param>
<Type>System.Action*[T]*</Type>
<Name>a</Name>
</Param>
<Param>
<Type>System.Action*[T]*</Type>
<Name>b</Name>
</Param>
</Params>
<Name>Remove</Name>
<TypeParams>
<Name>T</Name>
</TypeParams>
<Return>System.Action*[T]*</Return>
</Method>
</Methods>
<Invoke>
<Java>${this:16}.Invoke(${a})</Java>
<Params>
<Param>
<Type>T</Type>
<Name>a</Name>
</Param>
</Params>
<Name>Invoke</Name>
<TypeParams />
<Return>System.Boolean</Return>
</Invoke>
<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>yz+yOlqpwafASqBPdP2mB/lVgZk=</DigestValue></Reference></SignedInfo><SignatureValue>Nv+agoqBJd5WaI7/+c3HuvQ/dt5/5j3fHCKxNm4v8TZITAC8J+AbF8DN3l3ZZC1+zmhBzRTyrMMD7EWi7zumiRrhC2r/+rUpYbfOeiHANORPmwqP5NvSBeUbWvEp3VRBtQZHYNTDNG1gbOApoTGZi0z3dSv1ySftgALkYlxmbrc=</SignatureValue></Signature></Delegate>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is
@ -37,7 +37,7 @@
</Params>
<Name>Combine</Name>
<TypeParams>
<Name>T</Name>
<Name>TEventArgs</Name>
</TypeParams>
<Return>System.EventHandler*[TEventArgs]*</Return>
</Method>
@ -58,7 +58,7 @@
</Params>
<Name>Remove</Name>
<TypeParams>
<Name>T</Name>
<Name>TEventArgs</Name>
</TypeParams>
<Return>System.EventHandler*[TEventArgs]*</Return>
</Method>

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
-->
<Delegate 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>
<Import>CS2JNet.System.Predicate</Import>
</Imports>
<Java>Predicate*[${T}]*</Java>
<Name>System.Predicate</Name>
<TypeParams>
<Name>T</Name>
</TypeParams>
<Uses />
<Inherits>
<Type>System.Object</Type>
</Inherits>
<Methods>
<Method static="true">
<Imports>
<Import>CS2JNet.System.__MultiPredicate</Import>
</Imports>
<Java>__MultiPredicate.Combine(${a},${b})</Java>
<Params>
<Param>
<Type>System.Predicate*[T]*</Type>
<Name>a</Name>
</Param>
<Param>
<Type>System.Predicate*[T]*</Type>
<Name>b</Name>
</Param>
</Params>
<Name>Combine</Name>
<TypeParams>
<Name>T</Name>
</TypeParams>
<Return>System.Predicate*[T]*</Return>
</Method>
<Method static="true">
<Imports>
<Import>CS2JNet.System.__MultiPredicate</Import>
</Imports>
<Java>__MultiPredicate.Remove(${a},${b})</Java>
<Params>
<Param>
<Type>System.Predicate*[T]*</Type>
<Name>a</Name>
</Param>
<Param>
<Type>System.Predicate*[T]*</Type>
<Name>b</Name>
</Param>
</Params>
<Name>Remove</Name>
<TypeParams>
<Name>T</Name>
</TypeParams>
<Return>System.Predicate*[T]*</Return>
</Method>
</Methods>
<Invoke>
<Java>${this:16}.Invoke(${a})</Java>
<Params>
<Param>
<Type>T</Type>
<Name>a</Name>
</Param>
</Params>
<Name>Invoke</Name>
<TypeParams />
<Return>System.Boolean</Return>
</Invoke>
<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>yz+yOlqpwafASqBPdP2mB/lVgZk=</DigestValue></Reference></SignedInfo><SignatureValue>Nv+agoqBJd5WaI7/+c3HuvQ/dt5/5j3fHCKxNm4v8TZITAC8J+AbF8DN3l3ZZC1+zmhBzRTyrMMD7EWi7zumiRrhC2r/+rUpYbfOeiHANORPmwqP5NvSBeUbWvEp3VRBtQZHYNTDNG1gbOApoTGZi0z3dSv1ySftgALkYlxmbrc=</SignatureValue></Signature></Delegate>

View File

@ -0,0 +1,30 @@
/*
Copyright 2007,2008,2009,2010 Rustici Software, LLC
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author(s):
Kevin Glynn (kevin.glynn@twigletsoftware.com)
*/
package CS2JNet.System;
import java.util.List;
public interface Action<T> {
void Invoke(T obj) throws Exception ;
List<Action<T>> GetInvocationList() throws Exception ;
}

View File

@ -0,0 +1,30 @@
/*
Copyright 2007,2008,2009,2010 Rustici Software, LLC
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author(s):
Kevin Glynn (kevin.glynn@twigletsoftware.com)
*/
package CS2JNet.System;
import java.util.List;
public interface Predicate<T> {
boolean Invoke(T obj) throws Exception ;
List<Predicate<T>> GetInvocationList() throws Exception ;
}

View File

@ -0,0 +1,84 @@
/*
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author(s):
Kevin Glynn (kevin.glynn@twigletsoftware.com)
*/
package CS2JNet.System;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import CS2JNet.JavaSupport.util.ListSupport;
/**
* @author keving
*
*/
public class __MultiAction<T> implements Action<T> {
public void Invoke(T obj) throws Exception {
List<Action<T>> copy, members = this.GetInvocationList();
synchronized (members)
{
copy = new LinkedList<Action<T>>(members);
}
for (Action<T> d : copy)
{
d.Invoke(obj);
}
}
private List<Action<T>> _invocationList = new ArrayList<Action<T>>();
public static <T>Action<T> Combine(Action<T> a, Action<T> b) throws Exception {
if (a == null)
return b;
if (b == null)
return a;
__MultiAction<T> ret = new __MultiAction<T>();
ret._invocationList = a.GetInvocationList();
ret._invocationList.addAll(b.GetInvocationList());
return ret;
}
public static <T>Action<T> Remove(Action<T> a, Action<T> b) throws Exception {
if (a == null || b == null)
return a;
List<Action<T>> aInvList = a.GetInvocationList();
List<Action<T>> newInvList = ListSupport.removeFinalStretch(aInvList, b.GetInvocationList());
if (aInvList == newInvList)
{
return a;
}
else
{
__MultiAction<T> ret = new __MultiAction<T>();
ret._invocationList = newInvList;
return ret;
}
}
public List<Action<T>> GetInvocationList() throws Exception {
return _invocationList;
}
}

View File

@ -0,0 +1,86 @@
/*
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author(s):
Kevin Glynn (kevin.glynn@twigletsoftware.com)
*/
package CS2JNet.System;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import CS2JNet.JavaSupport.util.ListSupport;
/**
* @author keving
*
*/
public class __MultiPredicate<T> implements Predicate<T> {
public boolean Invoke(T obj) throws Exception {
List<Predicate<T>> copy, members = this.GetInvocationList();
synchronized (members)
{
copy = new LinkedList<Predicate<T>>(members);
}
boolean ret = false;
for (Predicate<T> d : copy)
{
ret = d.Invoke(obj);
}
return ret;
}
private List<Predicate<T>> _invocationList = new ArrayList<Predicate<T>>();
public static <T>Predicate<T> Combine(Predicate<T> a, Predicate<T> b) throws Exception {
if (a == null)
return b;
if (b == null)
return a;
__MultiPredicate<T> ret = new __MultiPredicate<T>();
ret._invocationList = a.GetInvocationList();
ret._invocationList.addAll(b.GetInvocationList());
return ret;
}
public static <T>Predicate<T> Remove(Predicate<T> a, Predicate<T> b) throws Exception {
if (a == null || b == null)
return a;
List<Predicate<T>> aInvList = a.GetInvocationList();
List<Predicate<T>> newInvList = ListSupport.removeFinalStretch(aInvList, b.GetInvocationList());
if (aInvList == newInvList)
{
return a;
}
else
{
__MultiPredicate<T> ret = new __MultiPredicate<T>();
ret._invocationList = newInvList;
return ret;
}
}
public List<Predicate<T>> GetInvocationList() throws Exception {
return _invocationList;
}
}