cachesizes.java

来自「天乙代码src_531.rar 天乙代码src_531.rar 天乙代」· Java 代码 · 共 93 行

JAVA
93
字号
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 + =
减小字号Ctrl + -
显示快捷键?