Пример #1
0
        /**
         * Gets the smaller area code map storage strategy according to the provided area code map. It
         * actually uses (outputs the data to a stream) both strategies and retains the best one which
         * make this method quite expensive.
         */
        // @VisibleForTesting
        public AreaCodeMapStorageStrategy getSmallerMapStorage(SortedDictionary <int, String> areaCodeMap)
        {
            AreaCodeMapStorageStrategy flyweightMapStorage = createFlyweightMapStorage();
            int sizeOfFlyweightMapStorage = getSizeOfAreaCodeMapStorage(flyweightMapStorage, areaCodeMap);

            AreaCodeMapStorageStrategy defaultMapStorage = createDefaultMapStorage();
            int sizeOfDefaultMapStorage = getSizeOfAreaCodeMapStorage(defaultMapStorage, areaCodeMap);

            return(sizeOfFlyweightMapStorage < sizeOfDefaultMapStorage
                ? flyweightMapStorage : defaultMapStorage);
        }
Пример #2
0
 /**
  * Creates an {@link AreaCodeMap} initialized with {@code sortedAreaCodeMap}.  Note that the
  * underlying implementation of this method is expensive thus should not be called by
  * time-critical applications.
  *
  * @param sortedAreaCodeMap  a map from phone number prefixes to descriptions of corresponding
  *     geographical areas, sorted in ascending order of the phone number prefixes as integers.
  */
 public void readAreaCodeMap(SortedDictionary<int, String> sortedAreaCodeMap)
 {
     areaCodeMapStorage = getSmallerMapStorage(sortedAreaCodeMap);
 }
Пример #3
0
 /**
  * Gets the size of the provided area code map storage. The map storage passed-in will be filled
  * as a result.
  */
 private static int getSizeOfAreaCodeMapStorage(AreaCodeMapStorageStrategy mapStorage,
     SortedDictionary<int, String> areaCodeMap)
 {
     mapStorage.readFromSortedMap(areaCodeMap);
     return mapStorage.getStorageSize();
 }
Пример #4
0
 /**
  * Creates an {@link AreaCodeMap} initialized with {@code sortedAreaCodeMap}.  Note that the
  * underlying implementation of this method is expensive thus should not be called by
  * time-critical applications.
  *
  * @param sortedAreaCodeMap  a map from phone number prefixes to descriptions of corresponding
  *     geographical areas, sorted in ascending order of the phone number prefixes as integers.
  */
 public void readAreaCodeMap(SortedDictionary <int, String> sortedAreaCodeMap)
 {
     areaCodeMapStorage = getSmallerMapStorage(sortedAreaCodeMap);
 }
Пример #5
0
 /**
  * Gets the size of the provided area code map storage. The map storage passed-in will be filled
  * as a result.
  */
 private static int getSizeOfAreaCodeMapStorage(AreaCodeMapStorageStrategy mapStorage,
                                                SortedDictionary <int, String> areaCodeMap)
 {
     mapStorage.readFromSortedMap(areaCodeMap);
     return(mapStorage.getStorageSize());
 }