⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uniformarrayencoder.java

📁 Java Communicating Agents是一个用于开发网络反应式信息agent的框架
💻 JAVA
字号:
/* * $Source: /home/data/cvsroot/src/jacomma/icm/io/imp/UniformArrayEncoder.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.io.imp;import jacomma.icm.io.EncObject;import jacomma.icm.io.EncObjectType;import jacomma.icm.io.ObjectEncoder;import jacomma.icm.io.EncObjectSignature;/** * TBA **/public class UniformArrayEncoder extends EncoderTemplate {	public UniformArrayEncoder() {		all_ = null;		some_ = null;	}		public boolean canHandle( Class c ) { 		return false;  // specialized encoder	}	public boolean canHandleSome( Class c ) {		return c.isArray();	}		public boolean canHandle( Object obj ) {		if ( canHandle( obj.getClass() ) ) {			// Check uniform			Object[] array = (Object[])obj;			boolean can = true;			if ( array.length > 0 ) {				Class c = array[0].getClass();				for ( int i = 1; i < array.length; i++ )					if ( !c.equals( array[i].getClass() ) ) {						can = false;						break;					}			}						return can;		} else 			return false;	}	public EncObject encode( Object obj, Object hint, boolean s ) {		// hint: An encoder that can handle the elements of the array		Object[] array = (Object[])obj;		EncObject[] elements =  null;		CacheKey key = new CacheKey( obj, hint );				if ( (elements = (EncObject[])cache_.get( obj )) == null ) {			elements = new EncObject[array.length];						if ( array.length > 0 ) {				ObjectEncoder enc = (ObjectEncoder)hint;				if ( enc == null )					enc = Registry.instance.getEncoder( array[0] );				for ( int i = 0; i < array.length; i++ )					elements[i] = enc.encode( array[i] );			}						elements = (EncObject[])cache_.try_put( key, elements );		}				// Have a meta-encoder produce the final result		EncObject eo = Registry.instance.getEncoder( elements ).encode( elements  );		return s ? sign( eo ) : eo;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -