/** Check if given entity is attached. */
 public static boolean isAttached(final Entity entity) {
   return EntityHelper.metadata(entity) instanceof AttachedEntityMetadata;
 }
 /** Returns attached metadata of entity. */
 public static AttachedEntityMetadata metadata(final Entity entity) {
   EntityMetadata metadata = EntityHelper.metadata(entity);
   checkState(metadata instanceof AttachedEntityMetadata, "Entity not attached");
   return (AttachedEntityMetadata) metadata;
 }