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

The following are Jave code examples for showing how to use size() 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: openjdk-jdk10   File: GetNativesForNewFlavorTest.java   View Source Code Vote up 6 votes
public void doTest() throws Exception {
    // Initialize DataFlavors and arrays used for test data
    initMappings();

    boolean passed = true;
    flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

    // Get all the native strings and preferred DataFlavor mappings
    hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
    hashSize = hash.size();

    // GetNativesForFlavor using unknown DataFlavor (verify 2-way mapping)
    //
    // If a new DataFlavor is specified, the method should establish a mapping
    // in both directions between specified DataFlavor and an encoded
    // version of its MIME type as its native.
    System.out.println("GetNativesForFlavor using new DataFlavor");

    comp1 = new Vector(Arrays.asList(test_natives_set));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));

    comp3 = new Vector(Arrays.asList(test_flavors_set));
    comp4 = new Vector(flavorMap.getFlavorsForNative(test_encoded));

    if ( !comp1.equals(comp2) || !comp3.equals(comp4) ) {
        throw new RuntimeException("\n*** After passing a new DataFlavor" +
            "\nwith getNativesForFlavor(DataFlavor flav)" +
            "\nthe mapping in both directions was not established.");
    }
    else
       System.out.println("GetNativesForFlavor using new DataFlavor: Test Passes");
}
 
Example 2
Project: AgentWorkbench   File: SimulationManager.java   View Source Code Vote up 6 votes
@Override
public void proceedAgentAnswers(Hashtable<AID, Object> agentAnswers) {

	// --- Define new display EnvironmentModel ----------------------------
	HashMap<String, Integer> localEnvModelNew = new HashMap<String, Integer>();
	AID[] agentArray = new AID[agentAnswers.size()];
	agentArray = agentAnswers.keySet().toArray(agentArray);
	for (int i = 0; i < agentArray.length; i++) {
		Integer value = (Integer) agentAnswers.get(agentArray[i]);  
		localEnvModelNew.put(agentArray[i].getLocalName(), value);
	}
	this.golModel.setGolHash(localEnvModelNew);
	
	// --- Did we've got edits from the visual representation ? -----------
	if (this.golModelEdited!=null) {
		this.golModel = this.golModelEdited;
		this.golModelEdited = null;
	}
	this.doNextSimulationStep();
	
}
 
Example 3
Project: ipack   File: PKCS12KeyStoreSpi.java   View Source Code Vote up 6 votes
public int engineSize()
{
    Hashtable tab = new Hashtable();

    Enumeration e = certs.keys();
    while (e.hasMoreElements())
    {
        tab.put(e.nextElement(), "cert");
    }

    e = keys.keys();
    while (e.hasMoreElements())
    {
        String a = (String)e.nextElement();
        if (tab.get(a) == null)
        {
            tab.put(a, "key");
        }
    }

    return tab.size();
}
 
Example 4
Project: openjdk-jdk10   File: JComponent.java   View Source Code Vote up 6 votes
/**
 * Unregisters all the previously registered
 * <code>WHEN_IN_FOCUSED_WINDOW</code> <code>KeyStroke</code> bindings.
 */
private void unregisterWithKeyboardManager() {
    @SuppressWarnings("unchecked")
    Hashtable<KeyStroke, KeyStroke> registered =
            (Hashtable<KeyStroke, KeyStroke>)getClientProperty
                            (WHEN_IN_FOCUSED_WINDOW_BINDINGS);

    if (registered != null && registered.size() > 0) {
        Enumeration<KeyStroke> keys = registered.keys();

        while (keys.hasMoreElements()) {
            KeyStroke ks = keys.nextElement();
            unregisterWithKeyboardManager(ks);
        }
    }
    putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, null);
}
 
Example 5
Project: featurea   File: SourceFileAttribPane.java   View Source Code Vote up 6 votes
private void extractConstPoolInfo() {
    int iMaxPoolLen = constPool.getPoolInfoCount();
    int iIndex;
    hashUTF = new Hashtable();

    for (iIndex = 0; iIndex < iMaxPoolLen; iIndex++) {
        ConstantPoolInfo thisInfo = (ConstantPoolInfo) constPool.getPoolInfo(iIndex + 1);
        if (ConstantPoolInfo.CONSTANT_Utf8 == thisInfo.iTag) {
            hashUTF.put(thisInfo.sUTFStr, new Integer(iIndex + 1));
        }
    }

    Enumeration allKeys;
    strUTF = new String[hashUTF.size()];
    allKeys = hashUTF.keys();
    for (iIndex = 0; allKeys.hasMoreElements(); iIndex++) {
        strUTF[iIndex] = (String) allKeys.nextElement();
    }
}
 
Example 6
Project: openjdk-jdk10   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * Determine if IDL should be generated for a referenced type.
 * Do not generate IDL for a CORBA Object reference. It gets mapped
 * to the original IDL or to Object (if exactly org.omg.CORBA.Object)
 * Generate (boxed) IDL for an IDL Entity unless it is an IDL user
 * exception, a ValueBase, an AbstractBase (or a CORBA Object).
 * Do not generate IDL for Implementation classes..unless they inherit
 * from multiple distinct remote interfaces
 * @param t The type to check.
 * @return true or false
 */
protected boolean isIDLGeneratedFor(
                             CompoundType t ) {
    if ( t.isCORBAObject() ) return false;
    if ( t.isIDLEntity() )
        if ( t.isBoxed() ) return true;
        else if ( "org.omg.CORBA.portable.IDLEntity"
                  .equals( t.getQualifiedName() ) ) return true;
        else if ( t.isCORBAUserException() ) return true;
        else return false;
    Hashtable inhHash = new Hashtable();
    getInterfaces( t,inhHash );
    if ( t.getTypeCode() == TYPE_IMPLEMENTATION )
        if ( inhHash.size() < 2 ) return false;         //no multiple inheritance
        else return true;
    return true;                                   //generate IDL for this type
}
 
Example 7
Project: OpenJSharp   File: SunFontManager.java   View Source Code Vote up 6 votes
public Font[] getCreatedFonts() {

        Hashtable<String,Font2D> nameTable;
        if (fontsAreRegistered) {
            nameTable = createdByFullName;
        } else if (fontsAreRegisteredPerAppContext) {
            AppContext appContext = AppContext.getAppContext();
            nameTable =
                (Hashtable<String,Font2D>)appContext.get(regFullNameKey);
        } else {
            return null;
        }

        Locale l = getSystemStartupLocale();
        synchronized (nameTable) {
            Font[] fonts = new Font[nameTable.size()];
            int i=0;
            for (Font2D font2D : nameTable.values()) {
                fonts[i++] = new Font(font2D.getFontName(l), Font.PLAIN, 1);
            }
            return fonts;
        }
    }
 
Example 8
Project: openjdk-jdk10   File: GUIBrowser.java   View Source Code Vote up 5 votes
private void addPropertiesTab() {
    if (compNode instanceof ComponentNode) {
        Hashtable<String, Object> props = ((ContainerNode) compNode).getProperties();
        if (props.size() > 0) {
            JTable propTable = new JTable(new MyModel(props));
            propTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
            tbd.add(PROPERTIES_TAB, new JScrollPane(propTable));
            /*
            propTable.addMouseListener(new MouseListener() {
                public void mouseClicked(MouseEvent e) {
                    new ComponentBrowser(getOwnr(),
                            getSelectedNode()).
                            show();
                }
                public void mouseExited(MouseEvent e) {
                }
                public void mouseEntered(MouseEvent e) {
                }
                public void mousePressed(MouseEvent e) {
                }
                public void mouseReleased(MouseEvent e) {
                }
            });
             */
        }
    }
}
 
Example 9
Project: OpenDA   File: NonMissingStochObserverExchangeItem.java   View Source Code Vote up 5 votes
public NonMissingStochObserverExchangeItem(IPrevExchangeItem ioExchangeItem, double missingValue){
    this.ioExchangeItem = ioExchangeItem;
    Hashtable<Integer,Double> eiValues = new Hashtable<Integer,Double>();
    Hashtable<Integer,Double> eiTimes = new Hashtable<Integer,Double>();
    boolean isMissing = false;
    int iNonMissing = 0;
    double[] orgValues = ioExchangeItem.getValuesAsDoubles();
    double[] orgTimes = ioExchangeItem.getTimes();
    //TODO: determine the 'most' appropriate value of epsilon
    if (orgTimes.length != orgValues.length) {
        throw new RuntimeException("org.openda.observers.NonMissingStochObserverExchangeItem: Inconsistent #times/#values of original exchange item.");
    }
    if(orgTimes!=null){
    double epsilon = 1.E-5;
    if (orgValues!=null && orgTimes!=null) {
    	for (int iValues=0; iValues<orgValues.length; iValues++){
    		if ((Double.isNaN(orgValues[iValues]) || Math.abs(orgValues[iValues]-missingValue)<epsilon)){
    			isMissing = true;
    		} else {
    			eiValues.put(iNonMissing,orgValues[iValues]);
    			eiTimes.put(iNonMissing,orgTimes[iValues]);
    			iNonMissing++;
    		}
    	}
    }
    }
    if (isMissing){
        double[] newValues = new double[eiValues.size()];
        double[] newTimes = new double[eiValues.size()];
        for (int iNewValues=0; iNewValues<newValues.length; iNewValues++){
            newValues[iNewValues] = eiValues.get(iNewValues);
            newTimes[iNewValues] = eiTimes.get(iNewValues);
        }
        this.values = newValues;
        this.times = newTimes;
    } else {
        values = this.ioExchangeItem.getValuesAsDoubles();
        times = this.ioExchangeItem.getTimes();
    }
}
 
Example 10
Project: jdk8u-jdk   File: ArrayTable.java   View Source Code Vote up 5 votes
/**
 * Returns the keys of the table, or <code>null</code> if there
 * are currently no bindings.
 * @param keys  array of keys
 * @return an array of bindings
 */
public Object[] getKeys(Object[] keys) {
    if (table == null) {
        return null;
    }
    if (isArray()) {
        Object[] array = (Object[])table;
        if (keys == null) {
            keys = new Object[array.length / 2];
        }
        for (int i = 0, index = 0 ;i < array.length-1 ; i+=2,
                 index++) {
            keys[index] = array[i];
        }
    } else {
        Hashtable<?,?> tmp = (Hashtable)table;
        Enumeration<?> enum_ = tmp.keys();
        int counter = tmp.size();
        if (keys == null) {
            keys = new Object[counter];
        }
        while (counter > 0) {
            keys[--counter] = enum_.nextElement();
        }
    }
    return keys;
}
 
Example 11
Project: jdk8u-jdk   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 12
Project: jdk8u-jdk   File: SwitchData.java   View Source Code Vote up 5 votes
/**
 * Create a new enumeration from the hashtable.  Each key in the
 * hash table will be an Integer, with the value being a label.  The
 * enumeration returns the keys in sorted order.
 */
SwitchDataEnumeration(Hashtable<Integer,Label> tab) {
    table = new Integer[tab.size()];
    int i = 0;
    for (Enumeration<Integer> e = tab.keys() ; e.hasMoreElements() ; ) {
        table[i++] = e.nextElement();
    }
    Arrays.sort(table);
    current_index = 0;
}
 
Example 13
Project: ramus   File: QualifierHistoryPlugin.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public void windowClosed(GUIFramework framework, Element element,
                         Attribute attribute) {
    Hashtable<Element, Hashtable<Attribute, HistoryDialog>> h = (Hashtable<Element, Hashtable<Attribute, HistoryDialog>>) framework
            .get("HistoryDialogs");
    Hashtable<Attribute, HistoryDialog> h1 = h.get(element);
    h1.remove(attribute);
    if (h1.size() == 0)
        h.remove(element);
}
 
Example 14
Project: openjdk-jdk10   File: BasicPermission.java   View Source Code Vote up 5 votes
/**
 * readObject is called to restore the state of the
 * BasicPermissionCollection from a stream.
 */
private void readObject(java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get permissions
    // writeObject writes a Hashtable<String, Permission> for the
    // permissions key, so this cast is safe, unless the data is corrupt.
    @SuppressWarnings("unchecked")
    Hashtable<String, Permission> permissions =
            (Hashtable<String, Permission>)gfields.get("permissions", null);
    perms = new ConcurrentHashMap<>(permissions.size()*2);
    perms.putAll(permissions);

    // Get all_allowed
    all_allowed = gfields.get("all_allowed", false);

    // Get permClass
    permClass = (Class<?>) gfields.get("permClass", null);

    if (permClass == null) {
        // set permClass
        Enumeration<Permission> e = permissions.elements();
        if (e.hasMoreElements()) {
            Permission p = e.nextElement();
            permClass = p.getClass();
        }
    }
}
 
Example 15
Project: asura   File: JmsHelper.java   View Source Code Vote up 5 votes
public static InitialContext getInitialContext(final JobDataMap jobDataMap) throws NamingException
{
    
    Hashtable params = new Hashtable(2);
    
    String initialContextFactory =
        jobDataMap.getString(INITIAL_CONTEXT_FACTORY);

    if (initialContextFactory != null) {
        params.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
    }
    
    String providerUrl = jobDataMap.getString(PROVIDER_URL);
    if (providerUrl != null) {
        params.put(Context.PROVIDER_URL, providerUrl);
    }

    String principal = jobDataMap.getString(PRINCIPAL);
    if ( principal != null ) {
        params.put( Context.SECURITY_PRINCIPAL, principal );
    }

    String credentials = jobDataMap.getString(CREDENTIALS);
    if ( credentials != null ) {
        params.put( Context.SECURITY_CREDENTIALS, credentials );
    }

    if (params.size() == 0) {
        return new InitialContext();
    } else {
        return new InitialContext(params);
    }
    
}
 
Example 16
Project: asura   File: EJBInvokerJob.java   View Source Code Vote up 5 votes
private InitialContext getInitialContext(JobDataMap jobDataMap)
    throws NamingException {
    Hashtable params = new Hashtable(2);
    
    String initialContextFactory =
        jobDataMap.getString(INITIAL_CONTEXT_FACTORY);
    if (initialContextFactory != null) {
        params.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
    }
    
    String providerUrl = jobDataMap.getString(PROVIDER_URL);
    if (providerUrl != null) {
        params.put(Context.PROVIDER_URL, providerUrl);
    }

    String principal = jobDataMap.getString(PRINCIPAL);
    if ( principal != null ) {
        params.put( Context.SECURITY_PRINCIPAL, principal );
    }

    String credentials = jobDataMap.getString(CREDENTIALS);
    if ( credentials != null ) {
        params.put( Context.SECURITY_CREDENTIALS, credentials );
    }

    return (params.size() == 0) ? new InitialContext() : new InitialContext(params);
}
 
Example 17
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 18
Project: jdk8u-jdk   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: lams   File: JndiHelper.java   View Source Code Vote up 4 votes
public static InitialContext getInitialContext(Properties props) throws NamingException {
	final Hashtable hash = extractJndiProperties( props );
	return hash.size() == 0 ? new InitialContext() : new InitialContext( hash );
}
 
Example 20
Project: unitimes   File: ToolBox.java   View Source Code Vote up 4 votes
/**
 * Return true if two Hashtables are different
 * @param a
 * @param b
 * @return boolean
 */
public static boolean diff(Hashtable a, Hashtable b) {

	if (a == null) {
		return (b == null ? false : true);
	}
	if (b == null) {
		return true;
	}
	if (a.size() != b.size()) {
		Debug.log("  diff: size");
		return true;
	}
	for (Enumeration e = a.keys(); e.hasMoreElements();) {
		Object keya = e.nextElement();
		Object keyb = null;

		if (!b.containsKey(keya)) { // hashCode differs but try to find it
			for (Enumeration eb = b.keys();
				keyb == null && eb.hasMoreElements();
				) {
				Object key = eb.nextElement();

				if (key.equals(keya)) {
					keyb = key;
				}
			}
		} else {
			keyb = keya;
		}
		if (keyb == null) {
			Debug.log("  diff: key " + keya);
			return true;
		}
		Object oa = a.get(keya);
		Object ob = b.get(keyb);

		if (!oa.equals(ob)) {
			Debug.log("  diff: " + oa + " with " + ob);
			return true;
		}
	}
	return false;
}