📄 dependencies.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/8/7
*
* @Author: Xiaojun Chen
* $Revision$ 1.0
*
*/
package eti.bi.alphaminer.core.Plugin;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import eti.bi.common.System.SysConfig;
public class Dependencies {
/** the owner */
private String name;
/** the list of plugin dependencies */
private List<Dependency> dependencies;
private String needAlphaminerVersion;
/** Create a new plugin dependency. */
public Dependencies(String name, String dependencies, String needAlphaminerVersion) {
this.name = name;
this.dependencies = new LinkedList<Dependency>();
collect(dependencies);
this.needAlphaminerVersion = needAlphaminerVersion;
}
/** collect all dependent plugin */
private void collect(String dependencies){
if(dependencies==null){
return;
}
String[] singleDependencies = dependencies.trim().split("#");
if(singleDependencies==null){
return;
}
String name,version,denpency;
int index1,index2;
for(int i=0;i<singleDependencies.length;i++){
denpency = singleDependencies[i].trim();
if(denpency.length()>0){
index1 = denpency.indexOf("[");
if(index1>0){
name = denpency.substring(0, index1);
index2 = denpency.indexOf("]", index1);
if(index2>index1){
version = denpency.substring(index1, index2);
}
else if(index2<0){
version = denpency.substring(index1);
}
else{
continue;
}
}
else if(index1<0){
name = denpency;
version = "0";
}
else{
//no name, just throw
continue;
}
this.dependencies.add(new Dependency(name,version));
}
}
}
/**
* @param plugins the found plugins
* @return Return true if all depencies are found in plugins
* */
public boolean checkDependency(List<Plugin> plugins){
if(!needAlphaminerVersion.equals(SysConfig.getAlphaminerVersion())){
if(Double.parseDouble(needAlphaminerVersion)>Double.parseDouble(SysConfig.getAlphaminerVersion())){
return false;
}
}
if(plugins==null){
return false;
}
PluginDescription pluginDescription;
Plugin plugin;
Dependency dependency;
int i,j,size1=dependencies.size(),size2=plugins.size();
boolean sat;
for(i=0;i<size1;i++){
dependency = dependencies.get(i);
sat = false;
for(j=0;j<size2;j++){
plugin = plugins.get(i);
pluginDescription = plugin.getPluginDescription();
if(pluginDescription.equal(dependency)){
sat=true;
break;
}
}
System.err.println("Can't load plugin: "+name);
if(sat==false){
return false;
}
}
return true;
}
/**
* @see java.lang.Object#toString()
* */
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Denpency:\n");
Iterator<Dependency> iterator = dependencies.iterator();
Dependency dependency;
while(iterator.hasNext()){
dependency = iterator.next();
sb.append("Name: "+dependency.name+"\t"+"Version: "+dependency.version);
}
return sb.toString();
}
}
class Dependency{
String name;
String version;
public Dependency(String name, String version){
this.name = name;
this.version = version;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -