code: public static Uid getUid(final Calendar calendar) throws ConstraintViolationException {
          Uid uid = null;
          for (final Component c : calendar.getComponents()) {
              for (final Property foundUid : c.getProperties(Property.UID)) {
                  if (uid != null && !uid.equals(foundUid)) {
                      throw new ConstraintViolationException("More than one UID found in calendar");
                  }
                  uid = (Uid) foundUid;
              }
          }
          if (uid == null) {
              throw new ConstraintViolationException("Calendar must specify a single unique identifier (UID)");
          }
          return uid;
      }
docs: Returns a unique identifier as specified by components in the provided calendar.
  @param calendar a calendar instance
  @return the UID property
  @throws ConstraintViolationException if zero or more than one unique identifer is found in the specified calendar