Browse Source

Properly support containsKey in LazyHashtable.

Fix the wrong semantics of AntTaskTable#contains.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273834 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
e910d5184a
3 changed files with 24 additions and 7 deletions
  1. +3
    -3
      src/main/org/apache/tools/ant/Project.java
  2. +12
    -3
      src/main/org/apache/tools/ant/util/LazyHashtable.java
  3. +9
    -1
      src/testcases/org/apache/tools/ant/ProjectTest.java

+ 3
- 3
src/main/org/apache/tools/ant/Project.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -2105,8 +2105,8 @@ public class Project {
return taskClass;
}

public boolean contains( Object key ) {
return get( key ) != null;
public boolean containsKey(Object key) {
return get(key) != null;
}

}


+ 12
- 3
src/main/org/apache/tools/ant/util/LazyHashtable.java View File

@@ -61,6 +61,8 @@ import java.util.Enumeration;
*
* All operations that need access to the full list of objects
* will call initAll() first. Get and put are cheap.
*
* @since Ant 1.6
*/
public class LazyHashtable extends Hashtable {
protected boolean initAllDone=false;
@@ -96,12 +98,19 @@ public class LazyHashtable extends Hashtable {

public boolean contains( Object value ) {
initAll();
return super.contains(value );
return super.contains(value);
}

public boolean containsValue( Object value ) {
public boolean containsKey(Object value) {
initAll();
return super.contains( value );
return super.containsKey(value);
}

/**
* Delegates to {@link #contains contains}.
*/
public boolean containsValue( Object value ) {
return contains(value);
}

public Enumeration keys() {


+ 9
- 1
src/testcases/org/apache/tools/ant/ProjectTest.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -232,6 +232,14 @@ public class ProjectTest extends TestCase {
assertSame(pfih, p.getInputHandler());
}

public void testTaskDefinitionContainsKey() {
assertTrue(p.getTaskDefinitions().containsKey("echo"));
}

public void testTaskDefinitionContains() {
assertTrue(p.getTaskDefinitions().contains(org.apache.tools.ant.taskdefs.Echo.class));
}

private class DummyTaskPrivate extends Task {
public DummyTaskPrivate() {}
public void execute() {}


Loading…
Cancel
Save