📄 handle.java
字号:
/* * $Source: /home/data/cvsroot/src/jacomma/icm/type/Handle.java,v $ * $Revision: 1.6 $ * $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 java.net.InetAddress;import java.net.UnknownHostException;import java.util.List;import java.util.ArrayList;import jacomma.util.Cache;import jacomma.util.Environment;/** * TBA **/public final class Handle implements Cloneable { String target_; String name_; InetAddress home_; List loc_; String string_; String id_; Handle( String target, String name, InetAddress home, List loc, String key ) { target_ = target; name_ = name; home_ = home; loc_ = loc; string_ = key; id_ = name + "@" + home.getHostName(); } public String toString() { return string_; } public String id() { return id_; } public boolean sameAgent( Handle h ) { return name_.equals( h.getName() ) && home_.equals( h.getHome() ); } public boolean equals( Object obj ) { try { return string_.equals( obj.toString() ) && ((Handle)obj).locations().equals( loc_ ); } catch ( ClassCastException exc ) { return false; } } public int hashCode() { return string_.hashCode(); } public String getName() { return name_; } public String getTarget() { return target_; } public Handle setTarget( String tgt ) { return createHandle( tgt, name_, home_, (List)((ArrayList)loc_).clone() ); } public InetAddress getHome() { return home_; } public List locations() { return loc_; } public Object clone() { try { Handle c = (Handle)super.clone(); c.loc_ = (List)((ArrayList)loc_).clone(); return c; } catch ( CloneNotSupportedException exc ) { throw new jacomma.util.CheckedException( exc ); } } // factory methods + stuff static final Cache cache_; static final InetAddress localhost_; static final ArrayList defloc_; static { try { cache_ = new Cache(); String cs = (String)Environment.getProperty( "icm.host" ); localhost_ = ( cs == null ) ? InetAddress.getLocalHost() : InetAddress.getByName( cs ); defloc_ = new ArrayList(); defloc_.add( localhost_ ); } catch ( UnknownHostException exc ) { throw new jacomma.util.CheckedException( exc ); } } public static Handle createHandle( String name ) { return createHandle( null, name, localhost_, (List)defloc_.clone() ); } public static Handle createHandle( String name, InetAddress home ) { List l = new ArrayList(); l.add( home ); return createHandle( null, name, home, l ); } public static Handle createHandle( String target, String name ) { return createHandle( target, name, localhost_, (List)defloc_.clone() ); } public static Handle createHandle( String target, String name, InetAddress home ) { List l = new ArrayList(); l.add( home ); return createHandle( target, name, home, l ); } public static Handle createHandle( String name, InetAddress home, List loc ) { return createHandle( null, name, home, loc ); } public static Handle createHandle( String target, String name, InetAddress home, InetAddress[] loc ) { List l = new ArrayList(); for ( int i = 0; i < loc.length; i++ ) l.add( loc[i] ); return createHandle( target, name, home, l ); } public static Handle createHandle( String target, String name, InetAddress home, List loc ) { String key =( (target == null) ? "" : (target + ":") ) + name + "@" + home.getHostName(); Handle h = (Handle)cache_.get( key ); if ( h == null ) { h = (Handle)cache_.try_put( key, new Handle( target, name, home, loc, key ) ); } else if ( !h.loc_.equals( loc ) ) { h = (Handle)h.clone(); h.loc_ = loc; } return h; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -