Example usage for java.util UUID randomUUID

List of usage examples for java.util UUID randomUUID

Introduction

In this page you can find the example usage for java.util UUID randomUUID.

Prototype

public static UUID randomUUID() 

Source Link

Document

Static factory to retrieve a type 4 (pseudo randomly generated) UUID.

Usage

From source file:Main.java

private static UUID getUuid(Context c) {
    final SharedPreferences prefs = c.getSharedPreferences(ID_PREFS_FILE, Context.MODE_PRIVATE);
    final String id = prefs.getString(ID_PREFS_DEVICE_ID, null);
    final UUID uuid;
    if (id != null) {
        uuid = UUID.fromString(id);
    } else {/*from   ww  w.ja  v  a  2 s .  c o  m*/
        final String androidId = Secure.getString(c.getContentResolver(), Secure.ANDROID_ID);
        try {
            if (!BAD_UUID.equals(androidId)) {
                uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8"));
            } else {
                final String deviceId = ((TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE))
                        .getDeviceId();
                if (deviceId != null)
                    uuid = UUID.nameUUIDFromBytes(deviceId.getBytes("utf8"));
                else
                    uuid = UUID.randomUUID();
            }
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        prefs.edit().putString(ID_PREFS_DEVICE_ID, uuid.toString()).commit();
    }
    return uuid;
}

From source file:org.cleverbus.core.common.contextcall.AbstractContextCall.java

@Nullable
@Override/*from   w  w w .  java2s.c  om*/
public <T> T makeCall(Class<?> targetType, String methodName, Class<T> responseType, Object... methodArgs) {
    // generate unique ID
    String callId = UUID.randomUUID().toString();

    // save params into registry
    ContextCallParams params = new ContextCallParams(targetType, methodName, methodArgs);

    try {
        callRegistry.addParams(callId, params);

        // call target service
        callTargetMethod(callId, targetType, methodName);

        // get response from the call
        return callRegistry.getResponse(callId, responseType);

    } finally {
        callRegistry.clearCall(callId);
    }
}

From source file:edu.pitt.resumecore.PatientVisit.java

public PatientVisit(User patient) {
    db = new MySqlDbUtilities();
    this.examID = UUID.randomUUID().toString();

    String sql = "INSERT INTO emr.patientvisitrecord ";
    sql += "(examId,patientId,complaints,notes,dateOfVisit)";
    sql += " VALUES (";
    sql += "'" + this.getExamID() + "', ";
    sql += "'" + StringUtilities.cleanMySqlInsert(patient.getUserID()) + "', ";
    sql += "'null', ";
    sql += "'null', ";
    sql += "DATE_FORMAT(NOW(),'%Y-%m-%d %h:%i:%s'));";

    db.executeQuery(sql);//w  w  w  .ja va  2s.c  om
}

From source file:de.appsolve.padelcampus.utils.LoginUtil.java

public void updateLoginCookie(HttpServletRequest request, HttpServletResponse response) {
    Player player = sessionUtil.getUser(request);
    if (player != null) {
        UUID cookieUUID = UUID.randomUUID();
        UUID cookieValue = UUID.randomUUID();
        String cookieValueHash = BCrypt.hashpw(cookieValue.toString(), BCrypt.gensalt());
        LoginCookie loginCookie = new LoginCookie();
        loginCookie.setUUID(cookieUUID.toString());
        loginCookie.setPlayerUUID(player.getUUID());
        loginCookie.setLoginCookieHash(cookieValueHash);
        loginCookie.setValidUntil(new LocalDate().plusYears(1));
        loginCookieDAO.saveOrUpdate(loginCookie);
        Cookie cookie = new Cookie(COOKIE_LOGIN_TOKEN, cookieUUID.toString() + ":" + cookieValue.toString());
        cookie.setDomain(request.getServerName());
        cookie.setMaxAge(ONE_YEAR_SECONDS);
        cookie.setPath("/");
        response.addCookie(cookie);//  w w w  . j a  v  a 2s .c o  m
    }
}

From source file:edu.umn.msi.tropix.jobs.activities.factories.TestUtils.java

static <T extends TropixObjectDescription> T init(final T activityDescription) {
    init((ActivityDescription) activityDescription);
    activityDescription.setName(UUID.randomUUID().toString());
    activityDescription.setDescription(UUID.randomUUID().toString());
    activityDescription.setCommitted(RANDOM.nextBoolean());
    try {//from  w  w  w .  j a  v a 2  s .  c o  m
        @SuppressWarnings("unchecked")
        final Map<String, Method> properties = BeanUtils.describe(activityDescription);
        for (final Map.Entry<String, Method> propertyEntry : properties.entrySet()) {
            final String property = propertyEntry.getKey();
            if (property.endsWith("Id")) {
                final Object object = REFLECTION_HELPER.getBeanProperty(activityDescription, property);
                if (object == null) {
                    REFLECTION_HELPER.setBeanProperty(activityDescription, property,
                            UUID.randomUUID().toString());
                }
            }
        }
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
    return activityDescription;
}

From source file:com.example.securelogin.domain.service.fileupload.FileUploadSharedServiceImpl.java

@Override
public String uploadTempFile(TempFile tempFile) {
    tempFile.setId(UUID.randomUUID().toString());
    tempFile.setUploadedDate(dateFactory.newTimestamp().toLocalDateTime());
    tempFileRepository.create(tempFile);
    return tempFile.getId();
}

From source file:fr.xebia.xke.metrics.service.OrderService.java

public OrderResponse placeOrder(Wine wine) {

    // TODO Exercise 7 - increment 'order.running.count'

    try {/*w  ww  .  j a  va 2s  .c  o  m*/
        WineUtils.randomException();

        OrderResponse response = new OrderResponse(wine, UUID.randomUUID().toString(),
                "http://verify.payment.com");
        WineUtils.randomSleep();
        return response;
    } finally {
        //  TODO Exercise 7 -   decrement here
    }

}

From source file:com.networknt.light.util.HashUtil.java

public static String generateUUID() {
    UUID id = UUID.randomUUID();
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(id.getMostSignificantBits());
    bb.putLong(id.getLeastSignificantBits());
    Base64 base64 = new Base64();
    return base64.encodeBase64URLSafeString(bb.array());
}

From source file:inflor.core.plots.AbstractFCChart.java

public AbstractFCChart(String priorUUID, ChartSpec spec) {
    // Create new UUID if needed.
    if (priorUUID == null) {
        uuid = UUID.randomUUID().toString();
    } else {//from  w  ww .jav a 2s .com
        uuid = priorUUID;
    }
    this.spec = spec;
}

From source file:org.gravidence.gravifon.util.BasicUtils.java

/**
 * Generates unique identifier./*from www .  ja  v a 2s . c  o m*/
 * 
 * @return unique identifier
 */
public static String generateUniqueIdentifier() {
    return UUID.randomUUID().toString();
}