SHALLOW size of the given object. <br>
If given a primitive type, the result will be incorrect.<br>
For primitive type, use {@link UnsafeUtil#shallowSizeOf(Class)}.

@param o
@return
559106
public static long shallowSizeOf(Object o) {
    Class<? extends Object> clz = o.getClass();
    if (clz.isArray()) {
      int len = Array.getLength(o);
      return regulateSize(THE_UNSAFE.arrayBaseOffset(clz) + (long) THE_UNSAFE.arrayIndexScale(clz) * len);
    }
    return shallowSizeOf(clz);
  }
136821
@Trivial
    protected synchronized int size(int bufferType) {
        if (bufferType == EXPLICIT_BUFFER) {
            return this.explicitBuffer.size();
        } else if (bufferType == SCAN_BUFFER) {
            return this.scanBuffer.size();
        } else if (bufferType == GC_BUFFER) {
            return this.garbageCollectorBuffer.size();
        }
        return 0;
    }
428397
@SuppressWarnings("null")
	public static String valueOf(@Nullable Object o) {
		return String.valueOf(String.valueOf(o));
	}
1153687
public int size() {
        switch(getType()) {
            case POINT: return 1;
            case CIRCLE: return 1;
            case BOX: return 2;
            case POLYGON: return coordinates[0].length;
            default: throw new IllegalStateException("Unrecognized type: " + getType());
        }
    }
654236
@Transformer
    public static int len(Object o) {
        if (o instanceof Collection) {
            return ((Collection)o).size();
        } else if (o instanceof Map) {
            return ((Map)o).size();
        } else if (o.getClass().isArray()) {
            return Array.getLength(o);
        } else {
            return str(o).length();
        }
    }
1362188
public static int sizeOf(int type)
    {
        switch ( type )
        {
            case MatDataTypes.miINT8:
                return miSIZE_INT8;
            case MatDataTypes.miUINT8:
                return miSIZE_UINT8;
            case MatDataTypes.miINT16:
                return miSIZE_INT16;
            case MatDataTypes.miUINT16:
                return miSIZE_UINT16;
            case MatDataTypes.miINT32:
                return miSIZE_INT32;
            case MatDataTypes.miUINT32:
                return miSIZE_UINT32;
            case MatDataTypes.miINT64:
                return miSIZE_INT64;
            case MatDataTypes.miUINT64:
                return miSIZE_UINT64;
            case MatDataTypes.miDOUBLE:
                return miSIZE_DOUBLE;
            default:
                return 1;
        }
    }
424097
protected byte[] serialize(Object o) {
    if (o == null) {
      throw new NullPointerException("Can't serialize null");
    }
    byte[] rv=null;
    ByteArrayOutputStream bos = null;
    ObjectOutputStream os = null;
    try {
      bos = new ByteArrayOutputStream();
      os = new ObjectOutputStream(bos);
      os.writeObject(o);
      os.close();
      bos.close();
      rv = bos.toByteArray();
    } catch (IOException e) {
      throw new IllegalArgumentException("Non-serializable object", e);
    } finally {
      CloseUtil.close(os);
      CloseUtil.close(bos);
    }
    return rv;
  }
749374
private boolean validateSize(Object validationObject, Annotation annotate)
    {

        if (checkNullObject(validationObject))
        {
            return true;
        }
        
        int objectSize = 0;
        int minSize = ((Size) annotate).min();
        int maxSize = ((Size) annotate).max();
        if (validationObject != null)
        {
            if (String.class.isAssignableFrom(validationObject.getClass()))
            {
                objectSize = ((String) validationObject).length();

            }
            else if (Collection.class.isAssignableFrom(validationObject.getClass()))
            {
                
                objectSize = ((Collection) validationObject).size();
            }
            else if (Map.class.isAssignableFrom(validationObject.getClass()))
            {
                objectSize = ((Map) validationObject).size();
            }
            else if (ArrayList.class.isAssignableFrom(validationObject.getClass()))
            {

                objectSize = ((ArrayList) validationObject).size();

            }
            else
            {
                throwValidationException(((Size) annotate).message());

            }
        }
        return objectSize <= maxSize && objectSize >= minSize;

    }
481432
@Override
    public int size ()
    {
        // dumb implementation. You should override.
        int size = 0;
        for (Interator it = interator(); (size < Integer.MAX_VALUE) && it.hasNext(); it.nextInt()) {
            size++;
        }
        return size;
    }
1373093
public byte[] serializeToBytes(final Serializable o) {
        byte[] bytes = null;
        try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
             final ObjectOutputStream oos = new ObjectOutputStream(baos)) {
            oos.writeObject(o);
            oos.flush();
            bytes = baos.toByteArray();
        } catch (final IOException e) {
            logger.warn("cannot Java serialize object", e);
        }
        return bytes;
    }
812880
protected String getMessageCode(Object o) {
		if (o instanceof TypeResolvable) {
			String type = ((TypeResolvable) o).getType();
			if (type != null) {
				return type;
			}
		}
		return ClassUtils.getShortNameAsProperty(o.getClass());
	}
1093782
public static long sizeOf(Class clazz) {
    long maxSize = headerSize(clazz);

    while (clazz != Object.class) {
      for (Field f : clazz.getDeclaredFields()) {
        if ((f.getModifiers() & Modifier.STATIC) == 0) {
          long offset = unsafe.objectFieldOffset(f);
          if (offset > maxSize) {
            // Assume 1 byte of the field width. This is ok as it gets padded out at the end
            maxSize = offset + 1;
          }
        }
      }
      clazz = clazz.getSuperclass();
    }

    // The whole class always pads to a 8 bytes boundary, so we round up to 8 bytes.
    return roundUpTo8(maxSize);
  }
1055611
private static GMetricType getType(final Object obj) {

		// FIXME This is far from covering all cases.
		// FIXME Wasteful use of high capacity types (eg Short => INT32)

		// Direct mapping when possible
		if (obj instanceof Long || obj instanceof Integer || obj instanceof Byte || obj instanceof Short)
			return GMetricType.INT32;
		if (obj instanceof Float)
			return GMetricType.FLOAT;
		if (obj instanceof Double)
			return GMetricType.DOUBLE;

		// Convert to double or int if possible
		try {
			Double.parseDouble(obj.toString());
			return GMetricType.DOUBLE;
		} catch (NumberFormatException e) {
			// Not a double
		}
		try {
			Integer.parseInt(obj.toString());
			return GMetricType.UINT32;
		} catch (NumberFormatException e) {
			// Not an int
		}

		return GMetricType.STRING;
	}
481752
public long size()
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass,
                        "size");

        //TODO Need to include toBeDeleted.
        long listLength = size; // For return;

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass,
                       "size",
                       "returns listLength=" + listLength + "(int)");
        return listLength;
    }
596027
public static int size(Object obj) {
		if (obj == null) {
			return 0;
		}
		ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
		try {
			ObjectOutputStream out = new ObjectOutputStream(buf);
			out.writeObject(obj);
			out.flush();
			buf.close();
		} catch (IOException e) {
			return 0;
		}

		return buf.size();
	}
571883
@Override
    public int size() {
        Node h = putStack.get();
        int putStackSize = h == null ? 0 : h.size;
        return putStackSize + takeStackSize.get();
    }
1255252
private String getSizeMethodCode() {
        StringBuilder code = new StringBuilder();
        Set<Integer> orders = new HashSet<Integer>();
        // encode method
        code.append("public int size(").append(ClassHelper.getInternalName(cls.getCanonicalName()));
        code.append(" t) throws IOException {").append(LINE_BREAK);
        code.append("int size = 0").append(JAVA_LINE_BREAK);
        for (FieldInfo field : fields) {

            boolean isList = field.isList();

            // check type
            if (!isList) {
                checkType(field.getFieldType(), field.getField());
            }

            if (orders.contains(field.getOrder())) {
                throw new IllegalArgumentException("Field order '" + field.getOrder() + "' on field"
                        + field.getField().getName() + " already exsit.");
            }
            // define field
            code.append(CodedConstant.getMappedTypeDefined(field.getOrder(), field.getFieldType(),
                    getAccessByField("t", field.getField(), cls), isList, field.isMap()));
            // compute size
            code.append("if (!CodedConstant.isNull(").append(getAccessByField("t", field.getField(), cls)).append("))")
                    .append("{").append(LINE_BREAK);
            code.append("size += ");
            code.append(CodedConstant.getMappedTypeSize(field, field.getOrder(), field.getFieldType(), isList,
                    field.isMap(), debug, outputPath));
            code.append("}").append(LINE_BREAK);
            if (field.isRequired()) {
                code.append(CodedConstant.getRequiredCheck(field.getOrder(), field.getField()));
            }
        }

        code.append("return size").append(JAVA_LINE_BREAK);
        code.append("}").append(LINE_BREAK);

        return code.toString();
    }