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

📄 workspaces.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 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/7/11
 *
 * @Author: Xiaojun Chen
 * $Revision$ 1.0
 *
 */
package eti.bi.alphaminer.core.workspace;

import java.util.ArrayList;

public class Workspaces {
	private ArrayList<Workspace> Workspaces = new ArrayList<Workspace>();
	private int current=-1;
	
	public boolean AddWorkspace(Workspace workspace){
		if(workspace==null){
			return false;
		}
		
		if(!workspace.isvalid()){
			return false;
		}
		
		Workspaces.add(workspace);
		
		if(current==-1){
			current = 0;
		}
		
		return true;
	}
	
	public boolean AddWorkspace(Workspace workspace, int index){
		if(workspace==null){
			return false;
		}
		
		if(!workspace.isvalid()){
			return false;
		}
		
		if(index<0||index>Workspaces.size()){
			return false;
		}
		
		Workspaces.add(index,workspace);
		//modify the current workspace index
		if(index<=current){
			current++;
		}
		else if(current==-1){
			current = 0;
		}
		
		return true;
	}
	
	public boolean AddWorkspaceCurrent(Workspace workspace){
		if(workspace==null){
			return false;
		}
		
		if(!workspace.isvalid()){
			return false;
		}
		
		Workspaces.add(workspace);
		current = Workspaces.size()-1;
		return true;
	}
	
	public boolean updateWorkspace(int index, Workspace workspace){
		if(workspace==null){
			return false;
		}
		
		if(!workspace.isvalid()){
			return false;
		}
		
		if(index<0||index>=Workspaces.size()){
			return false;
		}
		
		Workspaces.remove(index);
		Workspaces.add(index, workspace);
		
		return true;
	}
	
	public boolean deleteWorkspace(int index){
		if(index<0||index>=Workspaces.size()){
			return false;
		}
		
		Workspaces.remove(index);
		if(index<current){
			current--;
		}
		
		if(Workspaces.size()==0){
			current = -1;
		}
		
		return true;
	}
	
	public Workspace CurrentWorkspace(){
		return Workspaces.get(current);
	}
	
	public int CurrentWorkspaceIndex(){
		return current;
	}
	
	public int size(){
		if(Workspaces==null){
			return 0;
		}
		return Workspaces.size();
	}
	
	public String[] getWorkspacesNames(){
		if(size()==0){
			return new String[0];
		}
		
		String[] names = new String[size()];
		for(int i=0;i<Workspaces.size();i++){
			names[i] = ((Workspace)Workspaces.get(i)).getName();
		}
		
		return names;
	}
	
	public Workspace getWorkspace(int index){
		if(Workspaces==null){
			return null;
		}
		if(index<0||index>Workspaces.size()){
			return null;
		}
		
		return Workspaces.get(index);
	}
	
	public boolean SwitchCurrentWorkspace(int current){
		if(current<size()){
			this.current = current;
			return true;
		}
		return false;
	}
	
	public String getCurrentName(){
		return CurrentWorkspace().getName();
	}
	
	public String toXML(){
		StringBuffer sb = new StringBuffer();
		sb.append("<definition version=\"1.0\">"+"\n");
		if(Workspaces==null||Workspaces.size()==0){
			sb.append("</definition>"+"\n");
			return sb.toString();
		}
		
		int length = Workspaces.size();
		for(int i=0;i<current;i++){
			sb.append(((Workspace)Workspaces.get(i)).toXML()+"\n");
		}
		sb.append(((Workspace)Workspaces.get(current)).toXMLCurrentWorkspace()+"\n");
		for(int i=current+1;i<length;i++){
			sb.append(((Workspace)Workspaces.get(i)).toXML()+"\n");
		}
		
		sb.append("</definition>"+"\n");
		
		return sb.toString();
	}
}

⌨️ 快捷键说明

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