⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cachesizes.java

📁 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar
💻 JAVA
字号:
package com.laoer.bbscs.util;

import java.util.*;

/**
 * <p>Title: 天乙社区V5.0</p>
 * <p>Description: BBS-CS天乙社区V5.0</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: laoer.com</p>
 * @author 龚天乙
 * @version 5.0
 */

public class CacheSizes {

  public static int sizeOfObject() {
    return 4;
  }

  public static int sizeOfString(String string) {
    if (string == null) {
      return 0;
    }
    return 4 + string.length() * 2;
  }

  public static int sizeOfInt() {
    return 4;
  }

  public static int sizeOfChar() {
    return 2;
  }

  public static int sizeOfBoolean() {
    return 1;
  }

  public static int sizeOfLong() {
    return 8;
  }

  public static int sizeOfDouble() {
    return 8;
  }

  public static int sizeOfDate() {
    return 12;
  }

  public static int sizeOfProperties(Properties properties) {
    if (properties == null) {
      return 0;
    }
    //Base properties object
    int size = 36;
    //Add in size of each property
    Enumeration enum = properties.elements();
    while (enum.hasMoreElements()) {
      String prop = (String) enum.nextElement();
      size += sizeOfString(prop);
    }
    //Add in property names
    enum = properties.propertyNames();
    while (enum.hasMoreElements()) {
      String prop = (String) enum.nextElement();
      size += sizeOfString(prop);
    }
    return size;
  }

  public static int sizeOfMap(Map map) {
    if (map == null) {
      return 0;
    }
    //Base map object -- should be something around this size.
    int size = 36;
    //Add in size of each value
    Iterator iter = map.values().iterator();
    while (iter.hasNext()) {
      String value = (String) iter.next();
      size += sizeOfString(value);
    }
    //Add in each key
    iter = map.keySet().iterator();
    while (iter.hasNext()) {
      String key = (String) iter.next();
      size += sizeOfString(key);
    }
    return size;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -