code: public static double getCosinValue(double[] vector1, double[] vector2) {
          if (vector1 == null || vector2 == null) {
              return 0;
          }
          double dotProduct = VectorUtils.dotProduct(vector1, vector2);
          double euclideanDistance = VectorUtils.vectorLen(vector1) * VectorUtils.vectorLen(vector2);
          double cosineValue = Math.abs(dotProduct / euclideanDistance);
          return cosineValue > 1.0D ? 1.0D : cosineValue;  // because of the precision error
      }
docs: cos(theta) = A . B / ||A|| ||B||