GroupUtil.java

  1. package ntnu.idatt2016.v233.SmartMat.util;


  2. import java.util.UUID;


  3. /**
  4.  * This class provide some useful methods used with the group entity.
  5.  *
  6.  * @author Pedro Cardona
  7.  * @version 1.0
  8.  */
  9. public class GroupUtil {

  10.     /**
  11.      * Calculates the level of a group based on its experience points.
  12.      *
  13.      * @param exp The experience points of the group.
  14.      * @return The level of the group.
  15.      */
  16.     public static int getLevel(long exp){
  17.         return (int) (-3.0 * Math.log(10.0/ ((double)exp)));
  18.     }

  19.     /**
  20.      * Calculates the progress of the current level of a group based on its experience points.
  21.      *
  22.      * @param exp The experience points of the group.
  23.      * @return The progress of the current level of the group as a percentage.
  24.      */
  25.     public static int getProgressOfLevel(long exp) {
  26.         int currentLevel = getLevel(exp);
  27.         double expNextLevel = (10.0 / Math.pow(Math.E, (currentLevel+1) / -3.0));
  28.         double expCurrentLevel = (10.0 / Math.pow(Math.E, (currentLevel) / -3.0));
  29.         double baseNextLevel = expNextLevel - expCurrentLevel;
  30.         double basedCurrentExp= (double) exp - expCurrentLevel;
  31.         return (int) ((basedCurrentExp/ baseNextLevel )* 100.0);
  32.     }

  33.     /**
  34.      * Generates a unique six-digit code using UUID.
  35.      *
  36.      * @return A unique six-digit code.
  37.      */
  38.     public static String generateUniqueCode(){
  39.         String uuid = UUID.randomUUID().toString();
  40.         return uuid.replaceAll("-", "").substring(0, 6);
  41.     }

  42. }