1 19 20 package org.netbeans.modules.j2ee.deployment.profiler.api; 21 22 import java.util.Arrays ; 23 import java.util.List ; 24 import org.netbeans.api.java.platform.JavaPlatform; 25 import org.openide.filesystems.FileObject; 26 import org.openide.filesystems.FileUtil; 27 28 33 public final class ProfilerServerSettings { 34 35 private JavaPlatform javaPlatform; 36 private String [] jvmArgs; 37 private String [] env; 38 39 48 public ProfilerServerSettings(JavaPlatform javaPlatform, String [] jvmArgs, String [] env) { 49 if (javaPlatform == null) { 50 throw new NullPointerException ("The javaPlatform argument must not be null."); } 52 if (jvmArgs == null) { 53 throw new NullPointerException ("The jvmArgs argument must not be null."); } 55 if (env == null) { 56 throw new NullPointerException ("The env argument must not be null."); } 58 this.javaPlatform = javaPlatform; 59 this.jvmArgs = jvmArgs; 60 this.env = env; 61 } 62 63 68 public JavaPlatform getJavaPlatform() { 69 return javaPlatform; 70 } 71 72 78 public String [] getJvmArgs() { 79 return jvmArgs; 80 } 81 82 88 public String [] getEnv() { 89 return env; 90 } 91 92 100 public boolean equals(Object o) { 101 if (o == this) { 102 return true; 103 } 104 if (!(o instanceof ProfilerServerSettings)) { 105 return false; 106 } 107 ProfilerServerSettings other = (ProfilerServerSettings)o; 108 FileObject javaHome = (FileObject)javaPlatform.getInstallFolders().iterator().next(); 109 FileObject otherJavaHome = (FileObject)other.javaPlatform.getInstallFolders().iterator().next(); 110 if (!FileUtil.toFile(javaHome).equals(FileUtil.toFile(otherJavaHome))) { 111 return false; 112 } 113 if (jvmArgs.length != other.jvmArgs.length) { 114 return false; 115 } 116 List jvmArgsList = Arrays.asList(jvmArgs); 117 for (int i = 0; i < other.jvmArgs.length; i++) { 118 if (!jvmArgsList.contains(other.jvmArgs[i])) { 119 return false; 120 } 121 } 122 if (env.length != other.env.length) { 123 return false; 124 } 125 List envList = Arrays.asList(env); 126 for (int i = 0; i < other.env.length; i++) { 127 if (!envList.contains(other.env[i])) { 128 return false; 129 } 130 } 131 return true; 132 } 133 134 public int hashCode() { 135 int result = 17; 136 FileObject javaHome = (FileObject)javaPlatform.getInstallFolders().iterator().next(); 137 result = 37 * result + FileUtil.toFile(javaHome).hashCode(); 138 String [] jvmArgsTmp = (String [])jvmArgs.clone(); 139 Arrays.sort(jvmArgsTmp); 140 for (int i = 0; i < jvmArgsTmp.length; i++) { 141 result = 37 * result + jvmArgsTmp[i].hashCode(); 142 } 143 String [] envTmp = (String [])env.clone(); 144 Arrays.sort(envTmp); 145 for (int i = 0; i < envTmp.length; i++) { 146 result = 37 * result + envTmp[i].hashCode(); 147 } 148 return result; 149 } 150 151 public String toString() { 152 StringBuffer buffer = new StringBuffer (); 153 buffer.append("ProfilerServerSettings [\n"); buffer.append(" javaPlatform: " + javaPlatform.getDisplayName() + "\n"); buffer.append(" jvmarg: "); for (int i = 0; i < jvmArgs.length; i++) { 157 buffer.append(jvmArgs[i] + " "); } 159 buffer.append("\n"); buffer.append(" env: "); for (int i = 0; i < env.length; i++) { 162 buffer.append(env[i] + " "); } 164 buffer.append("]"); return buffer.toString(); 166 } 167 } 168 | Popular Tags |