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

📄 locales.java

📁 为了下东西 随便发了个 datamining 的源代码
💻 JAVA
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program 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 General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * Created on 2006/09/02
 *
 * @Author: Xiaojun Chen
 * $Revision$ 1.0
 *
 */

package eti.bi.common.Locale;

import java.util.ArrayList;
import java.util.Iterator;

public class Locales {
	
	private ArrayList<locale> locales = new ArrayList<locale>();
	private int current=-1;
	/**	flag to show if needing reload locale	*/
	private boolean needreload;
	
	public boolean AddLocale(locale a_locale){
		if(a_locale==null){
			return false;
		}
		
		if(!a_locale.isvalid()){
			return false;
		}
		
		locales.add(a_locale);
		
		if(current==-1){
			current = 0;
			needreload = true;
		}
		
		return true;
	}
	
	public boolean AddLocaleCurrent(locale a_locale){
		if(a_locale==null){
			return false;
		}
		
		if(!a_locale.isvalid()){
			return false;
		}
		
		locales.add(a_locale);
		current = locales.size()-1;
		needreload = true;
		return true;
	}
	
	public boolean AddLocale(locale a_locale, int index){
		if(a_locale==null){
			return false;
		}
		
		if(!a_locale.isvalid()){
			return false;
		}
		
		if(index<0||index>locales.size()){
			return false;
		}
		
		locales.add(index, a_locale);
		if(current>=index) {
			current++;
		}
		
		return true;
	}
	
	public boolean updateLocale(int index, locale locale){
		if(locale==null){
			return false;
		}
		
		if(!locale.isvalid()){
			return false;
		}
		
		if(index<0||index>=locales.size()){
			return false;
		}
		
		locales.remove(index);
		locales.add(index, locale);
		if(current==index) {
			needreload = true;
		}
		return true;
	}
	
	public boolean deleteLocale(int index){
		if(index<0||index>=locales.size()){
			return false;
		}
		
		locales.remove(index);
		if(index==current) {
			needreload = true;
		}
		if(index<current){
			current--;
		}
		else if(index==current) {
			current++;
		}
		
		if(current>=locales.size()) {
			current--;
		}
		
		if(locales.size()==0){
			current = -1;
		}
		
		return true;
	}
	
	public void resetChangeMonitor() {
		needreload = false;
	}
	
	public boolean needreload() {
		return needreload;
	}
	
	public locale CurrentLocale(){
		if(current<0) {
			return null;
		}
		return locales.get(current);
	}
	
	public int CurrentlocalesIndex(){
		return current;
	}
	
	public int size(){
		if(locales==null){
			return 0;
		}
		return locales.size();
	}
	
	public String[] getLocalesNames(){
		if(size()==0){
			return new String[0];
		}
		
		String[] names = new String[size()];
		for(int i=0;i<locales.size();i++){
			names[i] = ((locale)locales.get(i)).getName();
		}
		
		return names;
	}
	
	public String[][] getLocalesNameLocale() {
		if(size()==0){
			return new String[0][0];
		}
		
		String[][] NameLocale = new String[size()][2];
		for(int i=0;i<locales.size();i++){
			NameLocale[i][0] = ((locale)locales.get(i)).getName();
			NameLocale[i][1] = ((locale)locales.get(i)).getLocaleStrng();
		}
		
		return NameLocale;
	}
	
	public locale getLocale(int index){
		if(locales==null){
			return null;
		}
		if(index<0||index>locales.size()){
			return null;
		}
		
		return locales.get(index);
	}
	
	public boolean hasLocale(locale locale) {
		if(locale==null||locales==null) {
			return false;
		}
		
		Iterator<locale> itr = locales.iterator();
		
		locale lo;
		while(itr.hasNext()){
			lo = itr.next();
			if(lo.equal(locale)){
				return true;
			}
		}
		
		return false;
	}
	
	public boolean SwitchCurrentlocale(int current){
		if(current<size()){
			this.current = current;
			return true;
		}
		return false;
	}
	
	public String getCurrentName(){
		return CurrentLocale().getName();
	}
	
	/**
	 * @param aName name of locale
	 * @return return <code>true<code> if a locale package with the specific name exists, else <code>false<code> 
	 * */
	public boolean existsLocales(String aName) {
		if(size()==0){
			return false;
		}
		int size = locales.size();
		for(int i=0;i<size;i++) {
			if(locales.get(i).getName().equals(aName)) {
				return true;
			}
		}
		return false;
	}
	
	public String toXML(){
		StringBuffer sb = new StringBuffer();
		sb.append("<definition version=\"1.0\">"+"\n");
		if(locales==null||locales.size()==0){
			sb.append("</definition>"+"\n");
			return sb.toString();
		}
		
		int length = locales.size();
		for(int i=0;i<current;i++){
			sb.append(((locale)locales.get(i)).toXML()+"\n");
		}
		sb.append(((locale)locales.get(current)).toXMLCurrentWorkspace()+"\n");
		for(int i=current+1;i<length;i++){
			sb.append(((locale)locales.get(i)).toXML()+"\n");
		}
		
		sb.append("</definition>"+"\n");
		
		return sb.toString();
	}
}

⌨️ 快捷键说明

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