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

📄 clustertag.java

📁 一款即时通讯软件
💻 JAVA
字号:
/*
 *   License
 *
 * The contents of this file are subject to the Jabber Open Source License
 * Version 1.0 (the "License").  You may not copy or use this file, in either
 * source code or executable form, except in compliance with the License.  You
 * may obtain a copy of the License at http://www.jabber.com/license/ or at
 * http://www.opensource.org/.  
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 *   Copyrights
 *
 * Portions created by or assigned to Jabber.com, Inc. are 
 * Copyright (c) 2000 Jabber.com, Inc.  All Rights Reserved.  Contact
 * information for Jabber.com, Inc. is available at http://www.jabber.com/.
 *
 * Portions Copyright (c) 1999-2000 David Waite 
 *
 *   Acknowledgements
 * 
 * Special thanks to the Jabber Open Source Contributors for their
 * suggestions and support of Jabber.
 * 
 *   Changes
 *
 * @author  David Waite <a href="mailto:dwaite@jabber.com">
 *                      <i>&lt;dwaite@jabber.com&gt;</i></a>
 * @author  $Author: chris $
 * @version $Revision: 1.1 $
 *
 * j.komzak
 * Changed into ClusterTag
 */

package edu.ou.kmi.buddyspace.plugins.maps.xml;

/*
 * ClusterTag.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2002
 *
 *
 * Created on 30 September 2002, 11:41
 */

import java.util.Vector;
import java.util.Enumeration;
import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.Extension.*;

/**
 * <code>ClusterTag</code> contains &lt;cluster&gt tag.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */
public class ClusterTag
    extends XMLData
    implements Extension
{
    /** Vector of ItemTag and ClusterTag objects contained. */
    private Vector itemList;
    
    private String lat = null;
    private String lon = null;
    private String size = null;
    private String name = null;
    
    /**
     * Creates a new <code>ClusterTag</code> instance, based on the builder
     * state.
     *
     * @param builder an <code>ClusterTagBuilder</code> value
     * @exception InstantiationException if malformed or insufficient data is
     * in the builder.
     */
    public ClusterTag(ClusterTagBuilder builder)
        throws InstantiationException
    {
        itemList = (Vector) builder.getItemsAndClusters().clone();
        lat = builder.getLat();
        lon = builder.getLon();
        size = builder.getSize();
        name = builder.getName();
    }

    /**
     * returns an enumeration of items and clusters contained within this
     * object.
     *
     * @return an <code>Enumeration</code> value
     */
    public Enumeration itemsAndClusters()
    {
        return itemList.elements();
    }


    /**
     * <code>appendItem</code> converts this packet to XML. 
     * It then appends it to a StringBuffer.
     *
     * @param retval The <code>StringBuffer</code> to append to
     */
    public void appendItem(StringBuffer retval)
    {
	retval.append("<cluster " + "lat=\"" + lat +
                          "\" lon=\"" + lon +
                          "\" size=\"" + size + "\"");
        
        if (name != null) {
            retval.append(" name=\"");
            escapeString(retval, name);
            retval.append("\"");
        }
        
        if (!(itemsAndClusters().hasMoreElements())) {
            retval.append("/>\n");
            return;
        }
        
        retval.append(">\n");
        
        Enumeration items = itemsAndClusters();
        while (items.hasMoreElements())
            ((XMLData)items.nextElement()).appendItem(retval);
        
        retval.append("</cluster>\n");
    }
    
    /** Returns latitude attribute */
    public String getLat() {
        return lat;
    }
    
    /** Returns longitude attribute */
    public String getLon() {
        return lon;
    }
    
    /** Returns size attribute */
    public String getSize() {
        return size;
    }
    
    /** Returns name attribute */
    public String getName() {
        return name;
    }
    
    /** Sets name attribute */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     * Sets lat attribute.
     */
    public void setLatFloat(float lat)
    {
        this.lat = Float.toString(lat);
    }
    
    /**
     * Sets lon attribute.
     */
    public void setLonFloat(float lon)
    {
        this.lon = Float.toString(lon);
    }
    
    /** Returns items and clusters attribute */
    public Enumeration getItemsAndClusters() {
        return itemList.elements();
    }

    public void addItem(ItemTag item) {
        if (itemList != null)
            itemList.add(item);
    }
    
    /** Returns latitude attribute in float format */
    public float getLatFloat() {
        try {
            String str = getLat();
            float f = Float.parseFloat(str);
            return f;
        } catch (NumberFormatException e) {
            return 0;
        }
    }
    
    /** Returns longitude attribute in float format */
    public float getLonFloat() {
        try {
            String str = getLon();
            float f = Float.parseFloat(str);
            return f;
        } catch (NumberFormatException e) {
            return 0;
        }
    }
    
    /** Returns size attribute in float format */
    public float getSizeFloat() {
        try {
            String str = getSize();
            float f = Float.parseFloat(str);
            return f;
        } catch (NumberFormatException e) {
            return 0;
        }
    }
    
}

⌨️ 快捷键说明

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