📄 messageoptions.java
字号:
/* * $Source: /home/data/cvsroot/src/jacomma/icm/type/MessageOptions.java,v $ * $Revision: 1.5 $ * $Date: 2000/10/28 20:09:07 $ * * 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.icm.type;import jacomma.util.Cache;import java.util.Map;import java.util.HashMap;import java.util.Iterator;import java.util.List;/** * TBA **/public final class MessageOptions implements Cloneable { HashMap opt_; static final Map syms_; static final Map valid_; static final MessageOptions dflt_; public static final Symbol icmLeaseTime; public static final Symbol icmReplyTo; public static final Symbol icmMsgNumber; public static final Symbol icmPacketNumber; public static final Symbol icmPacketCount; static Cache cache_; public MessageOptions() { opt_ = new HashMap(); } MessageOptions( HashMap opt ) { opt_ = opt; } public Map toMap() { return opt_; } public Object set( Symbol field, Object val ) { if ( isValid( field, val ) ) return opt_.put( field, val ); else throw new IllegalArgumentException( field + ": " + val + "[" + val.getClass().getName() + "]" ); } public Object set( String field, Object val ) { Symbol sym = (Symbol)syms_.get( field ); if ( sym == null ) throw new IllegalArgumentException( "Invalid Option: " + sym ); return set( sym, val ); } public Object get( Symbol field ) { return opt_.get( field ); } public Object get( String field ) { return opt_.get( syms_.get( field ) ); } public Object clear( Symbol field ) { return opt_.remove( field ); } public Object clear( String field ) { return opt_.remove( syms_.get( field ) ); } public String toString() { return opt_.toString(); } static { cache_ = new Cache(); syms_ = new HashMap(); valid_ = new HashMap(); icmLeaseTime = new Symbol( "icmLeaseTime" ); icmReplyTo = new Symbol( "icmReplyto" ); icmMsgNumber = new Symbol( "icmMsgNumber" ); icmPacketNumber = new Symbol( "icmPacketNumber" ); icmPacketCount = new Symbol( "icmPacketCount" ); Symbol[] keys = { icmLeaseTime, icmReplyTo, icmMsgNumber, icmPacketNumber, icmPacketCount }; Class[] exp = { Integer.class, Handle.class, Integer.class, Integer.class, Integer.class }; for ( int i = 0; i < keys.length; i++ ) { syms_.put( keys[i].toString(), keys[i] ); valid_.put( keys[i], exp[i] ); } // create defaults // empty for the moment dflt_ = new MessageOptions( ); cache_.put( dflt_.opt_, dflt_ ); } public static MessageOptions createOptions( List l ) { if ( l.isEmpty() ) return defaults(); else try { Map m = new HashMap(); for( Iterator it = l.iterator(); it.hasNext(); ) { List next = (List)it.next(); m.put( next.get( 0 ), next.get( 1 ) ); } return createOptions( m ); } catch ( ClassCastException exc ) { throw new IllegalArgumentException( "Invalid Options: " + l ); } } public static MessageOptions createOptions( Map map ) { MessageOptions mopt = (map == null) ? defaults() : (MessageOptions)cache_.get( map ); if ( mopt == null ) { mopt = new MessageOptions(); for ( Iterator it = map.entrySet().iterator(); it.hasNext(); ) { Map.Entry next = (Map.Entry)it.next(); mopt.set( (Symbol)next.getKey(), next.getValue() ); } mopt = (MessageOptions)cache_.try_put( map, mopt ); } return (MessageOptions)mopt.clone(); } public static MessageOptions defaults() { return (MessageOptions)dflt_.clone(); } public static boolean isValid( Symbol field, Object obj ) { return obj.getClass().equals( valid_.get( field ) ); } public static void dump() { System.out.println( MessageOptions.class.getName() + ": Symbols" ); System.out.println( syms_ ); System.out.println( MessageOptions.class.getName() + ": Option types" ); System.out.println( valid_ ); System.out.flush(); } public Object clone() { try { MessageOptions c = (MessageOptions)super.clone(); c.opt_ = (HashMap)opt_.clone(); return c; } catch ( CloneNotSupportedException exc ) { throw new jacomma.util.CheckedException( exc ); } } public int hashCode() { return opt_.hashCode(); } public boolean equals( Object obj ) { return obj instanceof MessageOptions && opt_.equals( ((MessageOptions)obj).opt_ ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -