📄 messagepattern.java
字号:
/* * $Source: /home/data/cvsroot/src/jacomma/platform/core/MessagePattern.java,v $ * $Revision: 1.6 $ * $Date: 2000/10/28 20:09:08 $ * * This file is part of the jacomma framework * Copyright (c) 2000 Dimitrios Vyzovitis * mailto:dviz@egnatia.ee.auth.gr * * * * * * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA */package jacomma.platform.core;import jacomma.icm.type.Message;import jacomma.icm.type.Handle;import jacomma.util.TypeIterator;import java.util.List;import java.util.ArrayList;import java.util.Iterator;import java.util.Map;import java.io.Serializable;/** * TBA **/public final class MessagePattern implements Cloneable, Serializable { public static final String Any = "any"; public static final String All = Any + ":" + Any; static final MessagePattern anyp_; Object test_; List keys_; public MessagePattern( Object test, List keys) { test_ = test; keys_ = keys; } public List keys() { return keys_; } public boolean matches( Message msg ) { return test_.equals( msg ); } public Object clone() { try { return super.clone(); } catch ( CloneNotSupportedException exc ) { throw new jacomma.util.CheckedException( exc ); } } static final ArrayList dflt_; static { dflt_ = new ArrayList(); dflt_.add( All ); anyp_ = new MessagePattern( new Serializable() { public boolean equals( Object obj ) { return true; } }, (List)dflt_.clone() ); } public static MessagePattern anyPattern() { return anyp_; } public static MessagePattern createPattern( Object test ) { return new MessagePattern( test, (List)dflt_.clone() ); } public static MessagePattern createPattern( Class c, Object test ) { return new MessagePattern( test, makeKeys( c ) ); } public static MessagePattern createPattern( Handle from, Object test ) { return new MessagePattern( test, makeKeys( from ) ); } public static MessagePattern createPattern( Handle from, Class c, Object test ) { return new MessagePattern( test, makeKeys( from, c ) ); } public static List makeKeys( Handle from ) { List l = new ArrayList(); l.add( from.id() + ":" + Any ); l.add( All ); return l; } public static List makeKeys( Class c ) { List l = new ArrayList(); for( TypeIterator tit = new TypeIterator( c ); tit.hasNext(); l.add( Any + ":" + tit.nextType().getName() ) ); l.add( All ); return l; } public static List makeKeys( Message msg ) { return makeKeys( msg.getSender(), msg.getContent().getClass() ); } public static List makeKeys( Handle from, Class cnt ) { List l = new ArrayList(); String s = from.id(); TypeIterator tit = new TypeIterator( cnt ); while( tit.hasMoreTypes() ) { String c = tit.nextType().getName(); l.add( s + ":" + c ); l.add( Any + ":" + c ); } l.add( s + ":" + MessagePattern.Any ); l.add( All ); return l; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -