< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/SymbolHash.java

Print this page


   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.util;
  23 


 174      * Return key/value pairs of all entries in the map
 175      */
 176     public Object[] getEntries() {
 177         Object[] entries = new Object[fNum << 1];
 178         for (int i=0, j=0; i<fTableSize && j<fNum << 1; i++) {
 179             for (Entry entry = fBuckets[i]; entry != null; entry = entry.next) {
 180                 entries[j] = entry.key;
 181                 entries[++j] = entry.value;
 182                 j++;
 183             }
 184         }
 185         return entries;
 186     }
 187 
 188     /**
 189      * Make a clone of this object.
 190      */
 191     public SymbolHash makeClone() {
 192         SymbolHash newTable = new SymbolHash(fTableSize);
 193         newTable.fNum = fNum;
 194         newTable.fHashMultipliers = fHashMultipliers != null ? (int[]) fHashMultipliers.clone() : null;
 195         for (int i = 0; i < fTableSize; i++) {
 196             if (fBuckets[i] != null) {
 197                 newTable.fBuckets[i] = fBuckets[i].makeClone();
 198             }
 199         }
 200         return newTable;
 201     }
 202 
 203     /**
 204      * Remove all key/value association. This tries to save a bit of GC'ing
 205      * by at least keeping the fBuckets array around.
 206      */
 207     public void clear() {
 208         for (int i=0; i<fTableSize; i++) {
 209             fBuckets[i] = null;
 210         }
 211         fNum = 0;
 212         fHashMultipliers = null;
 213     } // clear():  void
 214 


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Nov 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.util;
  23 


 174      * Return key/value pairs of all entries in the map
 175      */
 176     public Object[] getEntries() {
 177         Object[] entries = new Object[fNum << 1];
 178         for (int i=0, j=0; i<fTableSize && j<fNum << 1; i++) {
 179             for (Entry entry = fBuckets[i]; entry != null; entry = entry.next) {
 180                 entries[j] = entry.key;
 181                 entries[++j] = entry.value;
 182                 j++;
 183             }
 184         }
 185         return entries;
 186     }
 187 
 188     /**
 189      * Make a clone of this object.
 190      */
 191     public SymbolHash makeClone() {
 192         SymbolHash newTable = new SymbolHash(fTableSize);
 193         newTable.fNum = fNum;
 194         newTable.fHashMultipliers = fHashMultipliers != null ? fHashMultipliers.clone() : null;
 195         for (int i = 0; i < fTableSize; i++) {
 196             if (fBuckets[i] != null) {
 197                 newTable.fBuckets[i] = fBuckets[i].makeClone();
 198             }
 199         }
 200         return newTable;
 201     }
 202 
 203     /**
 204      * Remove all key/value association. This tries to save a bit of GC'ing
 205      * by at least keeping the fBuckets array around.
 206      */
 207     public void clear() {
 208         for (int i=0; i<fTableSize; i++) {
 209             fBuckets[i] = null;
 210         }
 211         fNum = 0;
 212         fHashMultipliers = null;
 213     } // clear():  void
 214 


< prev index next >