public Result
public class Tuple implements Serializable {
public final T1 a;
public final T2 b;
public Tuple(T1 a, T2 b) {
this.a = a;
this.b = b;
}
}
public class TwoTuple {
private final A first;
private final B second;
public TwoTuple(A a, B b) {
this.first = a;
this.second = b;
}
public A getFirst() {
return this.first;
}
public B getSecond() {
return this.second;
}
}
public class ThreeTuple extends TwoTuple {
private final C third;
public ThreeTuple(A a, B b, C c) {
super(a, b);
this.third = c;
}
public C getThird() {
return this.third;
}
}
public class FourTuple extends ThreeTuple {
private final D fourth;
public FourTuple(A a, B b, C c, D d) {
super(a, b, c);
this.fourth = d;
}
public D getFourth() {
return this.fourth;
}
}
public final class TupleUtil {
private TupleUtil() {
}
public static TwoTuple tuple(A a, B b) {
return new TwoTuple(a, b);
}
public static ThreeTuple tuple(A a, B b, C c) {
return new ThreeTuple(a, b, c);
}
public static FourTuple tuple(A a, B b, C c, D d) {
return new FourTuple(a, b, c, d);
}
}
(1)调用示例:
1.tuple设置出参:
private static TwoTuple, Rectangle> getImages(List urls) throws Exception {
List list = new ArrayList();
float urx = 1191;
float ury = 1684;
for (String url : urls) {
Image image = Image.getInstance(url);
image.scalePercent(100);
image.setBorder(1);
image.setBorderWidth(10);
image.setBorderColor(Color.WHITE);
if(urx < image.getWidth() || ury < image.getHeight()) {
image.scalePercent(getPercent(image.getHeight(), image.getWidth()));
}
list.add(image);
}
return TupleUtil.tuple(list, new Rectangle(urx, ury));
}
2.接口调用方
public static Tuple queryDisInfo(String disId) {
final Object logsId = LogUtils.initLogsId();
final String desc = "远程获取分销商信息queryDisInfo方法:";
LogUtils.error(logger, logsId, desc + "入参:", disId);
Tuple dis = null;
try {
Result>
result = (Result>)RemoteClientUtils.getDefaultClient().executeToObject(QUERY_DIS_INFO,disId);
if(result.getStatus()== RemoteCommConstant.REMOTE_SUCCES_STATUS){
dis= result.getRe();
}else{
LogUtils.error(logger, logsId, desc + "失败原因:", result.getMsg());
}
} catch (Exception e) {
LogUtils.error(logger, logsId, desc + "异常信息:", e);
}
return dis;
}
public interface TestService {
enum UserInfoProperty {
ROOM,CELLPHONE,Name
}
public EnumMap getUserInfoByName(String name);
}
实现:
public class TestServiceImpl implements TestService {
@Override
public EnumMap getUserInfoByName(String name) {
EnumMap retMap = new EnumMap(UserInfoProperty.class);
retMap.put(UserInfoProperty.ROOM,"0003");
retMap.put(UserInfoProperty.CELLPHONE,"00004");
retMap.put(UserInfoProperty.Name,name);
return retMap;
}
}
调用:
public class App
{
public static void main( String[] args )
{
TestService testService = new TestServiceImpl();
String name = "testName";
EnumMap userInfo = testService.getUserInfoByName(name);
userInfo.entrySet().iterator();
System.out.println(userInfo.get(TestService.UserInfoProperty.Name));
System.out.println(userInfo.get(TestService.UserInfoProperty.ROOM));
System.out.println(userInfo.get(TestService.UserInfoProperty.CELLPHONE));
}
}