import java.io.PrintStream;
import java.io.StringWriter;
import java.io.Writer;
+import java.util.Arrays;
/**
*
*/
public SimpleProcess(File aDirectory, String[] aCmd) {
directory = aDirectory;
- cmd = aCmd;
+ cmd = Arrays.copyOf(aCmd, aCmd.length);
}
/**
private int runImpl() throws IOException {
try {
- String fullcmd = "";
+ StringBuffer fullcmd = new StringBuffer();
for (String part : cmd) {
- fullcmd += (" " + part);
+ fullcmd.append(" " + part);
}
LOG.debug("Executing '" + fullcmd + "' in directory '" + directory +
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.persistence.hibernate;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.orm.hibernate3.HibernateTemplate;
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-
-import org.wamblee.persistence.Persistent;
-
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.orm.hibernate3.HibernateTemplate;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+import org.wamblee.persistence.Persistent;
/**
* Extension of
* List of processed persistent objects.
*
*/
- public static void processMap(Map aPersistent, Map aMerged,
+ public static <Key,Value> void processMap(Map<Key,Value> aPersistent, Map<Key,Value> aMerged,
List<ObjectElem> aProcessed) {
if (aMerged.size() != aPersistent.size()) {
throw new RuntimeException("Sizes differ " + aMerged.size() + " " +
aPersistent.size());
}
- Set keys = aMerged.keySet();
+ Set<Entry<Key,Value>> entries = aMerged.entrySet();
- for (Object key : keys) {
+ for (Entry<Key,Value> entry : entries) {
+ Key key = entry.getKey();
if (!aPersistent.containsKey(key)) {
throw new RuntimeException("Key '" + key + "' not found");
}
- Object mergedValue = aMerged.get(key);
+ Value mergedValue = entry.getValue();
Object persistentValue = aPersistent.get(key);
if (mergedValue instanceof Persistent) {
}
public boolean equals(Object aObj) {
+ if (aObj == null) {
+ return false;
+ }
+ if (!(aObj instanceof ObjectElem)) {
+ return false;
+ }
return ((ObjectElem) aObj).object == object;
}
import org.wamblee.system.core.Scope;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
public ParameterValues(String[] aNames, Class[] aTypes) {
assert aNames.length == aTypes.length;
names = aNames;
- types = aTypes;
+ types = Arrays.copyOf(aTypes, aTypes.length);
resetValues();
}
* @return Types.
*/
public Class[] getTypes() {
- return types;
+ return Arrays.copyOf(types, types.length);
}
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.system.adapters;
import org.wamblee.collections.CollectionFilter;
*
*/
public SetterConfiguration add(final String aName) {
- int oldlen = setters.size();
List<Method> methods = new ArrayList<Method>();
CollectionFilter.filter(getAllSetters(clazz, publicOnly), methods,
new Condition<Method>() {
}
if (result.size() > 1) {
- String setters = "";
+ StringBuffer setters = new StringBuffer();
for (Method method : result) {
- setters += (method.getName() + " ");
+ setters.append((method.getName() + " "));
}
throw new IllegalArgumentException(
private void checkNotStartedInterfaces() {
if (remaining.get().size() > 0) {
- String notProvided = "";
+ StringBuffer notProvided = new StringBuffer();
for (ProvidedInterface provided : remaining.get()) {
- notProvided += ("\nComponent " + getQualifiedName() +
+ notProvided.append("\nComponent " + getQualifiedName() +
" did not start interface " + provided);
}
- throw new SystemAssemblyException(notProvided);
+ throw new SystemAssemblyException(notProvided.toString());
}
}
Collections.sort(result);
- String value = "";
+ StringBuffer value = new StringBuffer();
for (String str : result) {
- value += (":" + str);
+ value.append(":" + str);
}
- return value;
+ return value.toString();
}
}
@Override
public int hashCode() {
- return required.hashCode();
+ return Arrays.hashCode(required);
}
@Override
return EVENT_TRACKER;
}
+ private static void setEventTracker(EventTracker<String> aTracker) {
+ EVENT_TRACKER = aTracker;
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
- EVENT_TRACKER = new EventTracker<String>();
+ setEventTracker(new EventTracker<String>());
scope = new DefaultScope(new ProvidedInterface[0]);
}
}
public void testConstructorConfig() {
ClassConfiguration classConfig = new ClassConfiguration(X1.class);
- ConstructorConfiguration config = classConfig.getConstructorConfig()
- .greedy();
-
ProvidedInterface provided = new DefaultProvidedInterface("arg",
String.class);
List<RequiredInterface> required = classConfig.getRequiredInterfaces();
try {
ConstructorConfiguration config = new ConstructorConfiguration(
X2.class).greedy();
+ ignoredVariable(config);
} catch (SystemAssemblyException e) {
// e.printStackTrace();
return;
fail();
}
+
+ private static void ignoredVariable(Object aObject) {
+ // for findbugs.
+ }
public void testSpecificConstructor() {
ConstructorConfiguration config = new ConstructorConfiguration(X2.class)
public void testIgnoredNonPublic() {
ConstructorConfiguration config = new ConstructorConfiguration(X3.class)
.greedy();
- List<RequiredInterface> required = config.getRequiredInterfaces();
assertEquals(0, config.getParameters().getTypes().length);
}
}
public void testAddPrivate() {
- X5 obj = new X5();
final SetterConfiguration config = new SetterConfiguration(X5.class);
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
@Override
import junit.framework.TestCase;
+import org.junit.internal.requests.IgnoredClassRunner;
import org.wamblee.general.Pair;
import org.wamblee.system.core.Component;
Component<?> comp = new Application();
Container system = new Container("top").addComponent(comp);
Container system2 = new Container("top2").addComponent(comp);
+
+ ignoredVariable(system);
+ ignoredVariable(system2);
} catch (SystemAssemblyException e) {
return;
}
fail();
}
+
+ private static void ignoredVariable(Object aObject) {
+ // for findbugs.
+ }
public void testCompositeWithExternalDependencesProvided() {
Component<?> environment = new Environment();
Scope external = new DefaultScope(new ProvidedInterface[0]);
external.publishInterface(provided, 100);
- Scope scope = container.start(external);
+ container.start(external);
}
public void testProvidedInterfaces() {
container.getRequiredInterfaces().get(1).setProvider(x);
container.getRequiredInterfaces().get(2).setProvider(y);
- Scope runtime = container.start(externalScope);
+ container.start(externalScope);
assertEquals("y-value", app.getString());
}
*/
package org.wamblee.system.core;
+import java.io.Serializable;
import java.util.Comparator;
/**
* @version $Revision$
*/
public class RequiredInterfaceComparator implements
- Comparator<RequiredInterface> {
+ Comparator<RequiredInterface>, Serializable {
+
+ private static final long serialVersionUID = 7631587103378238574L;
+
@Override
public int compare(RequiredInterface aO1, RequiredInterface aO2) {
return aO1.getName().compareTo(aO2.getName());
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.system.graph;
+import java.util.Arrays;
+
/**
*
* @author $author$
*/
public MyNode(String aName, String[] aPorts) {
super(aName);
- ports = aPorts;
+ ports = Arrays.copyOf(aPorts, aPorts.length);
}
public String[] getPorts() {
- return ports;
+ return Arrays.copyOf(ports, ports.length);
+ }
+
+ @Override
+ public boolean equals(Object aObj) {
+ if (!super.equals(aObj)) {
+ return false;
+ }
+ if (!(aObj instanceof MyNode)) {
+ return false;
+ }
+ return Arrays.equals(ports, ((MyNode) aObj).ports);
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
}
}
public void run() throws Exception {
EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(
null, null, null, null);
+ ignoredVariable(restriction);
}
}, IllegalArgumentException.class);
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
public void run() throws Exception {
EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(
null, null, "x", "y");
+ ignoredVariable(restriction);
}
}, IllegalArgumentException.class);
}
+
+ private static final void ignoredVariable(Object aObject) {
+ // for findbugs.
+ }
public void testClientServer() {
EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1",