java.util.Hashtable#size ( )源码实例Demo

下面列出了java.util.Hashtable#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk8u   文件: IDLGenerator.java
/**
 * 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
}
 
源代码2 项目: openjdk-jdk9   文件: Permissions.java
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
    // Don't call defaultReadObject()

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

    // Get permissions
    // writeObject writes a Hashtable<Class<?>, PermissionCollection> for
    // the perms key, so this cast is safe, unless the data is corrupt.
    @SuppressWarnings("unchecked")
    Hashtable<Permission, Permission> perms =
            (Hashtable<Permission, Permission>)gfields.get("perms", null);
    permsMap = new ConcurrentHashMap<>(perms.size()*2);
    permsMap.putAll(perms);
}
 
源代码3 项目: hottub   文件: SunFontManager.java
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;
        }
    }
 
源代码4 项目: openjdk-jdk8u-backup   文件: PropertyPermission.java
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

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

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

    // Get permissions
    @SuppressWarnings("unchecked")
    Hashtable<String, PropertyPermission> permissions =
        (Hashtable<String, PropertyPermission>)gfields.get("permissions", null);
    perms = new HashMap<>(permissions.size()*2);
    perms.putAll(permissions);
}
 
源代码5 项目: TencentKona-8   文件: Permissions.java
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
    // Don't call defaultReadObject()

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

    // Get permissions
    // writeObject writes a Hashtable<Class<?>, PermissionCollection> for
    // the perms key, so this cast is safe, unless the data is corrupt.
    @SuppressWarnings("unchecked")
    Hashtable<Permission, Permission> perms =
            (Hashtable<Permission, Permission>)gfields.get("perms", null);
    permsMap = new HashMap<Permission, Permission>(perms.size()*2);
    permsMap.putAll(perms);
}
 
源代码6 项目: APDE   文件: Library.java
static public String[] packageListFromClassPath(String path, Context context) {
	Hashtable<String, Object> table = new Hashtable<>();
	String[] pieces = PApplet.split(path, File.pathSeparatorChar);
	
	for(int i = 0; i < pieces.length; i++) {
		if(pieces[i].length() == 0) continue;
		
		if(pieces[i].toLowerCase(Locale.US).endsWith(".jar") || pieces[i].toLowerCase(Locale.US).endsWith(".zip"))
			packageListFromZip(pieces[i], table, context);
		else {  // it's another type of file or directory
			File dir = new File(pieces[i]);
			if(dir.exists() && dir.isDirectory())
				packageListFromFolder(dir, null, table);
		}
	}
	int tableCount = table.size();
	String[] output = new String[tableCount];
	int index = 0;
	Enumeration<String> e = table.keys();
	while(e.hasMoreElements())
		output[index++] = (e.nextElement()).replace('/', '.');
	
	return output;
}
 
源代码7 项目: TencentKona-8   文件: SunFontManager.java
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;
        }
    }
 
源代码8 项目: jdk1.8-source-analysis   文件: BasicPermission.java
/**
 * 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 HashMap<String, Permission>(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();
        }
    }
}
 
源代码9 项目: ramus   文件: QualifierHistoryPlugin.java
@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);
}
 
源代码10 项目: Bytecoder   文件: ArrayTable.java
/**
 * 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;
}
 
源代码11 项目: algorithms-nutshell-2ed   文件: RegularNGonTest.java
public void testRegularKGon() {
	LineSweep dba = new LineSweep();
	
	int MAX = 30;
	
	// generate k-gon [http://math.berkeley.edu/~poonen/papers/ngon.pdf]
	for (int k = 4; k <= MAX; k++) {
		System.out.println (k);
		IPoint[] points = new IPoint[k];
		
		for(int i=0; i<k; i++) {
			points[i] = new TwoDPoint(FloatingPoint.value(Math.cos(2*i*Math.PI/k)),
									  FloatingPoint.value(Math.sin(2*i*Math.PI/k)));
	     }
		
		// now generate every possible pair.
		ILineSegment[] segments = new ILineSegment[k*(k-1)/2];
		int idx = 0;
		for (int i = 0; i < k-1; i++) {
			for (int j = i+1; j < k; j++) {
				segments[idx++] = new TwoDLineSegment(points[i], points[j]);
			}
		}
		
		Hashtable<IPoint, List<ILineSegment>> res = dba.intersections(segments);

		// Note that the intersections on the n-Gon in the 'count' equation above do not include the points 
		// on the edge, so we simply decrement ct by k to achieve the expected value.
		int ct = res.size() - k;
		
		System.out.println (k + "-gon has " + ct + " intersections from " + segments.length + " segments.");
		assertEquals (intersections[k], ct);
	}
}
 
源代码12 项目: jdk-1.7-annotated   文件: Permissions.java
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
    // Don't call defaultReadObject()

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

    // Get permissions
    Hashtable<Permission, Permission> perms =
            (Hashtable<Permission, Permission>)gfields.get("perms", null);
    permsMap = new HashMap<Permission, Permission>(perms.size()*2);
    permsMap.putAll(perms);
}
 
源代码13 项目: AsuraFramework   文件: JmsHelper.java
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);
    }
    
}
 
源代码14 项目: jdk8u_jdk   文件: BasicPermission.java
/**
 * 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 HashMap<String, Permission>(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();
        }
    }
}
 
源代码15 项目: openjdk-8-source   文件: BasicPermission.java
/**
 * 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 HashMap<String, Permission>(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();
        }
    }
}
 
源代码16 项目: algorithms-nutshell-2ed   文件: ComparisonMain.java
public static void testSlidingLadder(IntersectionDetection id) {
	
	TrialSuite suite = new TrialSuite();
	int NUM_TRIALS = 8;
	
	System.out.println (id.getClass());
	for (int c = 2; c <= 512; c *= 2) {
		System.out.println (c);
		// Start with ladder at (0, n) and slide one right and one down.
		ILineSegment[] segments = new ILineSegment[c];
		int idx=0;
		for (int i = segments.length-1; i >=0; i--) {
			segments[idx++] = new TwoDLineSegment(0,segments.length-i,i,0);
		}
		
		for (int k = 0; k < NUM_TRIALS; k++) {
			System.gc();
			long now = System.currentTimeMillis();
			Hashtable<IPoint, List<ILineSegment>> res = id.intersections(segments);
			long end = System.currentTimeMillis();
			//id.output(res);
			
			int n = segments.length;
			if (res.size() != n*(n-1)/2) {
				// problems!
				System.err.println ("Unexpected size returned:" + res.size() + " for " + c);
				System.exit(0);
			} 

			suite.addTrial(c, now, end);
		}
	}
	
	System.out.println (suite.computeTable());
}
 
源代码17 项目: gemfirexd-oss   文件: XactXAResourceManager.java
/**
   * This method is called to obtain a list of prepared transactions.
   * <p>
   * This call returns a complete list of global transactions which are 
   * either prepared or heuristically complete.
   * <p>
   * The XAResource interface expects a scan type interface, but our
   * implementation only returns a complete list of transactions.  So to
   * simulate the scan the following state is maintained.  If TMSTARTSCAN
   * is specified the complete list is returned.  If recover is called with
   * TMNOFLAGS is ever called a 0 length array is returned.  
   *
* @return Return a array with 0 or more Xid's which are currently in
   *         prepared or heuristically completed state.  If an error occurs
   *         during the operation, an appropriate error is thrown.
   *
   * @param flags    combination of the following flags 
   *                 XAResource.{TMSTARTRSCAN,TMENDRSCAN,TMNOFLAGS}.  
   *                 TMNOFLAGS must be used when no other flags are used.
   *
* @exception  StandardException  Standard exception policy.
   **/
  public Xid[] recover(int flags)
      throws StandardException
  {
      XAXactId[] ret_xid_list;

      if ((flags & XAResource.TMSTARTRSCAN) != 0)
      {
          Hashtable   trans_hashtable = transaction_table.getTableForXA();
          XAXactId[]  xid_list        = new XAXactId[trans_hashtable.size()];
          int         num_prepared    = 0;

          // Need to hold sync while linear searching the hash table.
          synchronized (trans_hashtable)
          {
              int i = 0;

              for (Enumeration e = trans_hashtable.elements(); 
                   e.hasMoreElements(); i++) 
              {
                  Xact xact = 
                      ((TransactionTableEntry) e.nextElement()).getXact();

                  if (xact.isPrepared())
                  {
                      GlobalTransactionId xa_id = xact.getGlobalId();

                      xid_list[i] = 
                          new XAXactId(
                              xa_id.getFormat_Id(), 
                              xa_id.getGlobalTransactionId(), 
                              xa_id.getBranchQualifier());
                      num_prepared++;
                  }
              }
          }

          // now need to squish the nulls out of the array to return. 
          ret_xid_list = new XAXactId[num_prepared];
          int ret_index = 0;
          for (int i = xid_list.length; i-- > 0; )
          {
              if (xid_list[i] != null)
                  ret_xid_list[ret_index++] = xid_list[i];
          }

          if (SanityManager.DEBUG)
          {
              SanityManager.ASSERT(ret_index == num_prepared);
          }
      }
      else
      {
          ret_xid_list = new XAXactId[0];
      }

      return(ret_xid_list);
  }
 
源代码18 项目: dragonwell8_jdk   文件: ReachableObjects.java
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);
}
 
源代码19 项目: openjdk-systemtest   文件: NioApp.java
public void Compare(String p_CFHT_strFilename, Hashtable<Object, Integer> p_CFHT_htHashTable) {
	try {
		int nRecordNumber = 0;
		int nCount = 1;
		int nBufferLength = 12;
		int nKey;
		long lGetValue;
		long lCount;
		boolean blnKeyIsThere;
		Object objGetValue;
		Hashtable<Object, Integer> htHashTable = p_CFHT_htHashTable;

		System.out.println("I am comparing the file with the hashtable");
		// Get a channel for the file and provide a place
		// in memory to put the bytes with a buffer
		File f = new File(p_CFHT_strFilename);
		FileInputStream fis = new FileInputStream(f);
		FileChannel fc = fis.getChannel();
		ByteBuffer bb = java.nio.ByteBuffer.allocate(nBufferLength);

		// while we are not at the end of the file
		while (nCount != 0 && nCount != -1) {

			// Starting at byte number (nRecordNumber*nBufferLength)
			// read the next nBufferLength bytes from the file into
			// buffer bb and rewind to the beginning of the buffer
			nCount = fc.read(bb, nRecordNumber * nBufferLength);
			bb.rewind();

			// If we are not at the end of the file
			if (nCount != -1 && nCount != 0) {
				// Read the first 4 bytes and then the next 8 bytes and
				// print the results to the screen.
				nKey = bb.getInt();
				lCount = bb.getLong();

				// Checking the Hashtable to see if the random number is there
				blnKeyIsThere = htHashTable.containsKey(" " + nKey);

				// If the random number is there then get the value
				// associated with this
				// key. Compare this value with the occurences value in the
				// file. If they are
				// the same then increase the nMatches count, if they are
				// different print their
				// values to the screen and increase the differences count.
				// In each case
				// remove the key from the hashtable. If the random number
				// is not there
				// then print this to the screen also.
				if (blnKeyIsThere) {
					objGetValue = htHashTable.get(" " + nKey);
					lGetValue = Long.parseLong(objGetValue.toString());
					if (lCount == lGetValue) {
						nMatches++;
						htHashTable.remove(" " + nKey);
					} else {
						nOccurenceDiffs++;
						htHashTable.remove(" " + nKey);
					}
				} else {
					nNotInHashTable++;
				}
			}

			// clear the buffer and increment the nRecordNumber (this will
			// ensure the next 12 bytes are read into the buffer.
			bb.clear();
			nRecordNumber++;

		}

		// close the FileInputStream (this consequently closes the
		// FileChannel
		fis.close();

		// Check to see if there are any keys left in the hashtable. If
		// there aren't
		// then print all the results to the screen, if there are then
		// calculate how
		// many keys are left in the hashtable and print all the results to
		// the screen.
		if (htHashTable.isEmpty()) {
			nTotalDiffs = nOccurenceDiffs + nNotInHashTable;
		} else {
			nNotInFile = htHashTable.size();
			nTotalDiffs = nOccurenceDiffs + nNotInHashTable + nNotInFile;
		}
	} catch (IOException e) {
		System.out.println("Error occured in ComparingFileHashTable class: " + e);
	}
}
 
源代码20 项目: gemfirexd-oss   文件: HashtableWrapper.java
public void validate( Region region, Info info ) {
  Hashtable obj = (Hashtable) CacheUtil.get( region, info.getName() );
  if ( obj.size() != info.getUpdates() )
    throw new DLockTestException( "Object data is invalid for " + info.getName() +
                                     " with expected count " + info.getUpdates() + ": " + obj );
}