Java Code Examples for java.util.Hashtable.remove()

The following are Jave code examples for showing how to use remove() of the java.util.Hashtable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: javaide   File: GetSizeOfHashtableExample.java   View Source Code Vote up 6 votes
public static void main(String[] args) {

    //create Hashtable object
    Hashtable ht = new Hashtable();

    /*
      To get the size of Hashtable use
      int size() method of Hashtable class. It returns the number of key values
      pairs stored in Hashtable object.
    */
    System.out.println("Size of Hashtable : " + ht.size());

    //add key value pairs to Hashtable using put method
    ht.put("1", "One");
    ht.put("2", "Two");
    ht.put("3", "Three");
    System.out.println("Size of Hashtable after addition : " + ht.size());

    //remove one element from Hashtable using remove method
    Object obj = ht.remove("2");
    System.out.println("Size of Hashtable after removal : " + ht.size());
  }
 
Example 2
Project: OpenJSharp   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * Write #includes for boxed IDLEntity references.
 * @param refHash Hashtable loaded with referenced types
 * @param p The output stream.
 */
protected void writeIDLEntityIncludes(
                                      Hashtable refHash,
                                      IndentingWriter p )
    throws IOException {
    Enumeration refEnum = refHash.elements();
    while ( refEnum.hasMoreElements() ) {
        Type t = (Type)refEnum.nextElement();
        if ( t.isCompound() ) {
            CompoundType ct = (CompoundType)t;
            if ( ct.isIDLEntity() ) {                          //select IDLEntities
                writeInclude( ct,0,!isThrown,p );
                refHash.remove( ct.getQualifiedName() );     //avoid another #include
            }
        }
    }
}
 
Example 3
Project: openjdk-jdk10   File: SCDynamicStoreConfig.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
private static Hashtable<String, Object> convertNativeConfig(
        Hashtable<String, Object> stanzaTable) throws IOException {
    // convert SCDynamicStore realm structure to Java realm structure
    Hashtable<String, ?> realms =
            (Hashtable<String, ?>) stanzaTable.get("realms");
    if (realms == null || realms.isEmpty()) {
        throw new IOException(
                "SCDynamicStore contains an empty Kerberos setting");
    }
    stanzaTable.remove("realms");
    Hashtable<String, Object> realmsTable = convertRealmConfigs(realms);
    stanzaTable.put("realms", realmsTable);
    WrapAllStringInVector(stanzaTable);
    if (DEBUG) System.out.println("stanzaTable : " + stanzaTable);
    return stanzaTable;
}
 
Example 4
Project: ChronoBike   File: CObjectCatalog.java   View Source Code Vote up 6 votes
private void RemoveObjectFromHashTable(Hashtable tab, Object obj)
{
	Enumeration e = tab.keys();
	try
	{
		Object k = e.nextElement() ;
		while (k != null)
		{
			Object o = tab.get(k) ;
			if (o == obj)
			{
				tab.remove(k) ;
			}
			k = e.nextElement() ;
		}
	}
	catch (NoSuchElementException ex)
	{
	}
}
 
Example 5
Project: openjdk-jdk10   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * Write #includes for boxed IDLEntity references.
 * @param refHash Hashtable loaded with referenced types
 * @param p The output stream.
 */
protected void writeIDLEntityIncludes(
                                      Hashtable refHash,
                                      IndentingWriter p )
    throws IOException {
    Enumeration refEnum = refHash.elements();
    while ( refEnum.hasMoreElements() ) {
        Type t = (Type)refEnum.nextElement();
        if ( t.isCompound() ) {
            CompoundType ct = (CompoundType)t;
            if ( ct.isIDLEntity() ) {                          //select IDLEntities
                writeInclude( ct,0,!isThrown,p );
                refHash.remove( ct.getQualifiedName() );     //avoid another #include
            }
        }
    }
}
 
Example 6
Project: openjdk-jdk10   File: LdapAttribute.java   View Source Code Vote up 5 votes
/**
 * sets the information needed to reconstruct the baseCtx if
 * we are serialized. This must be called _before_ the object is
 * serialized!!!
 */
@SuppressWarnings("unchecked") // clone()
private void setBaseCtxInfo() {
    Hashtable<String, Object> realEnv = null;
    Hashtable<String, Object> secureEnv = null;

    if (baseCtx != null) {
        realEnv = ((LdapCtx)baseCtx).envprops;
        this.baseCtxURL = ((LdapCtx)baseCtx).getURL();
    }

    if(realEnv != null && realEnv.size() > 0 ) {
        // remove any security credentials - otherwise the serialized form
        // would store them in the clear
        for (String key : realEnv.keySet()){
            if (key.indexOf("security") != -1 ) {

                //if we need to remove props, we must do it to a clone
                //of the environment. cloning is expensive, so we only do
                //it if we have to.
                if(secureEnv == null) {
                    secureEnv = (Hashtable<String, Object>)realEnv.clone();
                }
                secureEnv.remove(key);
            }
        }
    }

    // set baseCtxEnv depending on whether we removed props or not
    this.baseCtxEnv = (secureEnv == null ? realEnv : secureEnv);
}
 
Example 7
Project: incubator-netbeans   File: WorkspaceSwitchAction.java   View Source Code Vote up 5 votes
/** Frees all listeners etc from given workspace. */
void detachWorkspace(
    Workspace workspace, Hashtable workspace2Menu, Hashtable menu2Workspace, Hashtable workspace2Listener,
    JMenu menu
) {
    JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) workspace2Menu.get(workspace);
    workspace2Menu.remove(workspace);
    menu2Workspace.remove(workspace2Listener.get(workspace));
    workspace2Listener.remove(workspace);
    menu.remove(menuItem);
}
 
Example 8
Project: openjdk-systemtest   File: NioApp.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public void AmendHashTable(int p_HT_nRandomNumber, @SuppressWarnings("rawtypes") Hashtable p_HT_htHash) {
	int nKey;
	boolean blnKeyIsThere;
	Object objGetValue;

	// renaming the Random number passed to the method
	nKey = p_HT_nRandomNumber;

	// Making reading and writing to the hashtable thread safe (this is
	// not an option since I'm using the hashtable as a check
	synchronized (NioApp.class) {
		// checking the Hashtable to see if the random number is there
		blnKeyIsThere = p_HT_htHash.containsKey(" " + nKey);

		// If the random number is there then get the value associated with this
		// key, increase it by one, remove the key (and hence the value)
		// from the hashtable (this ensures that each random number only has one
		// entry in the hashtable) and then put the random number back into
		// the hashtable (as a key) with the new value. If the random number
		// is not there then add it to the hashtable as a key with value one.
		if (blnKeyIsThere) {
			objGetValue = p_HT_htHash.get(" " + nKey);
			String strGetValue = objGetValue.toString();
			int nGetValue = Integer.parseInt(strGetValue);
			int nNewValue = nGetValue + 1;
			p_HT_htHash.remove(" " + nKey);
			p_HT_htHash.put(" " + nKey, new Integer(nNewValue));
			p_HT_htHash.get(" " + nKey);
		} else {
			p_HT_htHash.put(" " + nKey, new Integer(1));
			objGetValue = p_HT_htHash.get(" " + nKey);
		}
		// end synchronized
	}
	// end method AmendHashTable
}
 
Example 9
Project: openjdk-jdk10   File: JLayeredPane.java   View Source Code Vote up 5 votes
/**
 * Removes all the components from this container.
 *
 * @since 1.5
 */
public void removeAll() {
    Component[] children = getComponents();
    Hashtable<Component, Integer> cToL = getComponentToLayer();
    for (int counter = children.length - 1; counter >= 0; counter--) {
        Component c = children[counter];
        if (c != null && !(c instanceof JComponent)) {
            cToL.remove(c);
        }
    }
    super.removeAll();
}
 
Example 10
Project: OpenJSharp   File: SCDynamicStoreConfig.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
private static Hashtable<String, Object> convertNativeConfig(
        Hashtable<String, Object> stanzaTable) {
    // convert SCDynamicStore realm structure to Java realm structure
    Hashtable<String, ?> realms =
            (Hashtable<String, ?>) stanzaTable.get("realms");
    if (realms != null) {
        stanzaTable.remove("realms");
        Hashtable<String, Object> realmsTable = convertRealmConfigs(realms);
        stanzaTable.put("realms", realmsTable);
    }
    WrapAllStringInVector(stanzaTable);
    if (DEBUG) System.out.println("stanzaTable : " + stanzaTable);
    return stanzaTable;
}
 
Example 11
Project: jdk8u-jdk   File: JLayeredPane.java   View Source Code Vote up 5 votes
/**
 * Removes all the components from this container.
 *
 * @since 1.5
 */
public void removeAll() {
    Component[] children = getComponents();
    Hashtable<Component, Integer> cToL = getComponentToLayer();
    for (int counter = children.length - 1; counter >= 0; counter--) {
        Component c = children[counter];
        if (c != null && !(c instanceof JComponent)) {
            cToL.remove(c);
        }
    }
    super.removeAll();
}
 
Example 12
Project: OpenJSharp   File: JLayeredPane.java   View Source Code Vote up 5 votes
/**
 * Removes all the components from this container.
 *
 * @since 1.5
 */
public void removeAll() {
    Component[] children = getComponents();
    Hashtable<Component, Integer> cToL = getComponentToLayer();
    for (int counter = children.length - 1; counter >= 0; counter--) {
        Component c = children[counter];
        if (c != null && !(c instanceof JComponent)) {
            cToL.remove(c);
        }
    }
    super.removeAll();
}
 
Example 13
Project: jdk8u-jdk   File: SCDynamicStoreConfig.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
private static Hashtable<String, Object> convertNativeConfig(
        Hashtable<String, Object> stanzaTable) {
    // convert SCDynamicStore realm structure to Java realm structure
    Hashtable<String, ?> realms =
            (Hashtable<String, ?>) stanzaTable.get("realms");
    if (realms != null) {
        stanzaTable.remove("realms");
        Hashtable<String, Object> realmsTable = convertRealmConfigs(realms);
        stanzaTable.put("realms", realmsTable);
    }
    WrapAllStringInVector(stanzaTable);
    if (DEBUG) System.out.println("stanzaTable : " + stanzaTable);
    return stanzaTable;
}
 
Example 14
Project: AgentWorkbench   File: BaseLoadBalancing.java   View Source Code Vote up 4 votes
/**
 * This method will start a number of remote container.
 *
 * @param numberOfContainer the number of container
 * @param remoteContainerConfig the remote container configuration
 * @param filterMainContainer true, if the Main-Container should be filter out of the result
 * 
 * @return the newly started locations
 */
protected Hashtable<String, Location> startNumberOfRemoteContainer(int numberOfContainer, boolean filterMainContainer, RemoteContainerConfig remoteContainerConfig) {
	
	Hashtable<String, Location> newContainerLocations = null;
	
	// --- Is the simulation service running ? -----------------------
	if (isLoadServiceIsRunning()==false) {
		System.out.println("Can not start remote container - LoadService is not running!");
		return null;
	}
	
	// --- Start the required number of container -------------------- 
	int startMistakes = 0;
	int startMistakesMax = 2;
	Vector<String> containerList = new Vector<String>();
	while (containerList.size()< numberOfContainer) {
	
		String newContainer = this.startRemoteContainer(remoteContainerConfig);
		if (newContainer!=null) {
			containerList.add(newContainer);	
		} else {
			startMistakes++;
		}
		if (startMistakes>=startMistakesMax) {
			break;
		}
	}
	
	// --- Get the locations of the started container ----------------
	LoadServiceHelper loadHelper;
	try {
		loadHelper = (LoadServiceHelper) myAgent.getHelper(LoadService.NAME);
		newContainerLocations = loadHelper.getContainerLocations();
		
	} catch (ServiceException e) {
		e.printStackTrace();
		return null;
	}

	// --- If wanted, filter the Main-Container out ------------------
	if (filterMainContainer == true) {
		newContainerLocations.remove(jade.core.AgentContainer.MAIN_CONTAINER_NAME);
		if (newContainerLocations.size()==0) {
			newContainerLocations = null;
		}
	}
	return newContainerLocations;
}
 
Example 15
Project: openjdk-jdk10   File: JMenuItemOperator.java   View Source Code Vote up 4 votes
@Override
public Hashtable<String, Object> getDump() {
    Hashtable<String, Object> result = super.getDump();
    result.remove(AbstractButtonOperator.IS_SELECTED_DPROP);
    return result;
}
 
Example 16
Project: unitimes   File: StudentImport.java   View Source Code Vote up 4 votes
protected Student updateStudentInfo(Element element, String externalId, Hashtable<String, Student> students, Session session, Set<Long> updatedStudents) {
   	String fName = element.attributeValue("firstName", "Name");
   	String mName = element.attributeValue("middleName");
   	String lName = element.attributeValue("lastName", "Unknown");
   	String email = element.attributeValue("email");

   	Student student = students.remove(externalId);
   	if (student == null) {
   		student = new Student();
           student.setSession(session);
           student.setExternalUniqueId(externalId);
           student.setFreeTimeCategory(0);
           student.setSchedulePreference(0);
           student.setClassEnrollments(new HashSet<StudentClassEnrollment>());
           student.setCourseDemands(new HashSet<CourseDemand>());
           student.setFirstName(fName);
           student.setMiddleName(mName);
           student.setLastName(lName);
           student.setEmail(email);
           student.setAreaClasfMajors(new HashSet<StudentAreaClassificationMajor>());
           student.setAreaClasfMinors(new HashSet<StudentAreaClassificationMinor>());
           student.setGroups(new HashSet<StudentGroup>());
           student.setAccomodations(new HashSet<StudentAccomodation>());
   	} else {
       	if (!eq(fName, student.getFirstName())) {
       		student.setFirstName(fName);
       		updatedStudents.add(student.getUniqueId());
       	}
       	if (!eq(mName, student.getMiddleName())) {
       		student.setMiddleName(mName);
       		updatedStudents.add(student.getUniqueId());
       	}
       	if (!eq(lName, student.getLastName())) {
       		student.setLastName(lName);
       		updatedStudents.add(student.getUniqueId());
       	}
       	if (!eq(email, student.getEmail())) {
       		student.setEmail(email);
       		updatedStudents.add(student.getUniqueId());
       	}
   	}
   	
   	return student;
}
 
Example 17
Project: OpenJSharp   File: ReachableObjects.java   View Source Code Vote up 4 votes
public ReachableObjects(JavaHeapObject root,
                        final ReachableExcludes excludes) {
    this.root = root;

    final Hashtable<JavaHeapObject, JavaHeapObject> bag = new Hashtable<JavaHeapObject, JavaHeapObject>();
    final Hashtable<String, String> fieldsExcluded = new Hashtable<String, String>();  //Bag<String>
    final Hashtable<String, String> fieldsUsed = new Hashtable<String, String>();   // Bag<String>
    JavaHeapObjectVisitor visitor = new AbstractJavaHeapObjectVisitor() {
        public void visit(JavaHeapObject t) {
            // Size is zero for things like integer fields
            if (t != null && t.getSize() > 0 && bag.get(t) == null) {
                bag.put(t, t);
                t.visitReferencedObjects(this);
            }
        }

        public boolean mightExclude() {
            return excludes != null;
        }

        public boolean exclude(JavaClass clazz, JavaField f) {
            if (excludes == null) {
                return false;
            }
            String nm = clazz.getName() + "." + f.getName();
            if (excludes.isExcluded(nm)) {
                fieldsExcluded.put(nm, nm);
                return true;
            } else {
                fieldsUsed.put(nm, nm);
                return false;
            }
        }
    };
    // Put the closure of root and all objects reachable from root into
    // bag (depth first), but don't include root:
    visitor.visit(root);
    bag.remove(root);

    // Now grab the elements into a vector, and sort it in decreasing size
    JavaThing[] things = new JavaThing[bag.size()];
    int i = 0;
    for (Enumeration e = bag.elements(); e.hasMoreElements(); ) {
        things[i++] = (JavaThing) e.nextElement();
    }
    ArraySorter.sort(things, new Comparer() {
        public int compare(Object lhs, Object rhs) {
            JavaThing left = (JavaThing) lhs;
            JavaThing right = (JavaThing) rhs;
            int diff = right.getSize() - left.getSize();
            if (diff != 0) {
                return diff;
            }
            return left.compareTo(right);
        }
    });
    this.reachables = things;

    this.totalSize = root.getSize();
    for (i = 0; i < things.length; i++) {
        this.totalSize += things[i].getSize();
    }

    excludedFields = getElements(fieldsExcluded);
    usedFields = getElements(fieldsUsed);
}
 
Example 18
Project: OpenJSharp   File: JComponent.java   View Source Code Vote up 4 votes
/**
 * Registers any bound <code>WHEN_IN_FOCUSED_WINDOW</code> actions with
 * the <code>KeyboardManager</code>. If <code>onlyIfNew</code>
 * is true only actions that haven't been registered are pushed
 * to the <code>KeyboardManager</code>;
 * otherwise all actions are pushed to the <code>KeyboardManager</code>.
 *
 * @param onlyIfNew  if true, only actions that haven't been registered
 *          are pushed to the <code>KeyboardManager</code>
 */
private void registerWithKeyboardManager(boolean onlyIfNew) {
    InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW, false);
    KeyStroke[] strokes;
    Hashtable<KeyStroke, KeyStroke> registered =
            (Hashtable<KeyStroke, KeyStroke>)getClientProperty
                            (WHEN_IN_FOCUSED_WINDOW_BINDINGS);

    if (inputMap != null) {
        // Push any new KeyStrokes to the KeyboardManager.
        strokes = inputMap.allKeys();
        if (strokes != null) {
            for (int counter = strokes.length - 1; counter >= 0;
                 counter--) {
                if (!onlyIfNew || registered == null ||
                    registered.get(strokes[counter]) == null) {
                    registerWithKeyboardManager(strokes[counter]);
                }
                if (registered != null) {
                    registered.remove(strokes[counter]);
                }
            }
        }
    }
    else {
        strokes = null;
    }
    // Remove any old ones.
    if (registered != null && registered.size() > 0) {
        Enumeration<KeyStroke> keys = registered.keys();

        while (keys.hasMoreElements()) {
            KeyStroke ks = keys.nextElement();
            unregisterWithKeyboardManager(ks);
        }
        registered.clear();
    }
    // Updated the registered Hashtable.
    if (strokes != null && strokes.length > 0) {
        if (registered == null) {
            registered = new Hashtable<KeyStroke, KeyStroke>(strokes.length);
            putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, registered);
        }
        for (int counter = strokes.length - 1; counter >= 0; counter--) {
            registered.put(strokes[counter], strokes[counter]);
        }
    }
    else {
        putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, null);
    }
}
 
Example 19
Project: openjdk-jdk10   File: ReachableObjects.java   View Source Code Vote up 4 votes
public ReachableObjects(JavaHeapObject root,
                        final ReachableExcludes excludes) {
    this.root = root;

    final Hashtable<JavaHeapObject, JavaHeapObject> bag = new Hashtable<JavaHeapObject, JavaHeapObject>();
    final Hashtable<String, String> fieldsExcluded = new Hashtable<String, String>();  //Bag<String>
    final Hashtable<String, String> fieldsUsed = new Hashtable<String, String>();   // Bag<String>
    JavaHeapObjectVisitor visitor = new AbstractJavaHeapObjectVisitor() {
        public void visit(JavaHeapObject t) {
            // Size is zero for things like integer fields
            if (t != null && t.getSize() > 0 && bag.get(t) == null) {
                bag.put(t, t);
                t.visitReferencedObjects(this);
            }
        }

        public boolean mightExclude() {
            return excludes != null;
        }

        public boolean exclude(JavaClass clazz, JavaField f) {
            if (excludes == null) {
                return false;
            }
            String nm = clazz.getName() + "." + f.getName();
            if (excludes.isExcluded(nm)) {
                fieldsExcluded.put(nm, nm);
                return true;
            } else {
                fieldsUsed.put(nm, nm);
                return false;
            }
        }
    };
    // Put the closure of root and all objects reachable from root into
    // bag (depth first), but don't include root:
    visitor.visit(root);
    bag.remove(root);

    // Now grab the elements into a vector, and sort it in decreasing size
    JavaThing[] things = new JavaThing[bag.size()];
    int i = 0;
    for (Enumeration<JavaHeapObject> e = bag.elements(); e.hasMoreElements(); ) {
        things[i++] = (JavaThing) e.nextElement();
    }
    ArraySorter.sort(things, new Comparer() {
        public int compare(Object lhs, Object rhs) {
            JavaThing left = (JavaThing) lhs;
            JavaThing right = (JavaThing) rhs;
            long diff = right.getSize() - left.getSize();
            if (diff != 0) {
                return Long.signum(diff);
            }
            return left.compareTo(right);
        }
    });
    this.reachables = things;

    this.totalSize = root.getSize();
    for (i = 0; i < things.length; i++) {
        this.totalSize += things[i].getSize();
    }

    excludedFields = getElements(fieldsExcluded);
    usedFields = getElements(fieldsUsed);
}
 
Example 20
Project: parabuild-ci   File: AntFetch.java   View Source Code Vote up 4 votes
/**
 * Add the references explicitly defined as nested elements to the new
 * project. Also copy over all references that don't override existing
 * references in the new project if inheritrefs has been requested.
 *
 * @exception BuildException  Description of the Exception
 */
private void addReferences() throws BuildException {
   Hashtable thisReferences = (Hashtable)getProject().getReferences().clone();
   Hashtable newReferences = newProject.getReferences();
   Enumeration e;
   if ( references.size() > 0 ) {
      for ( e = references.elements(); e.hasMoreElements();  ) {
         Reference ref = (Reference)e.nextElement();
         String refid = ref.getRefId();
         if ( refid == null ) {
            throw new BuildException( "the refid attribute is required"
                   + " for reference elements" );
         }
         if ( !thisReferences.containsKey( refid ) ) {
            log( "Parent project doesn't contain any reference '"
                   + refid + "'",
                  Project.MSG_WARN );
            continue;
         }

         thisReferences.remove( refid );
         String toRefid = ref.getToRefid();
         if ( toRefid == null ) {
            toRefid = refid;
         }
         copyReference( refid, toRefid );
      }
   }

   // Now add all references that are not defined in the
   // subproject, if inheritRefs is true
   if ( inheritRefs ) {
      for ( e = thisReferences.keys(); e.hasMoreElements();  ) {
         String key = (String)e.nextElement();
         if ( newReferences.containsKey( key ) ) {
            continue;
         }
         copyReference( key, key );
      }
   }
}