List of usage examples for java.util UUID UUID
public UUID(long mostSigBits, long leastSigBits)
From source file:com.github.seqware.queryengine.util.SGID.java
/** {@inheritDoc} */ @Override//from ww w . j a va2 s .c o m public void read(Kryo kryo, Input input) { long leastSig = input.readLong(); long mostSig = input.readLong(); String key = input.readString(); uuid = new UUID(mostSig, leastSig); backendTimestamp = new Date(input.readLong()); friendlyRowKey = key; }
From source file:com.joyent.manta.util.MantaUtilsTest.java
public void lastItemInPathIsCorrectFileWithTrailingSeparator() { final String expected = new UUID(24, 48).toString(); final String path = String.format("/foo/bar/%s/", expected); final String actual = MantaUtils.lastItemInPath(path); Assert.assertEquals(actual, expected); }
From source file:io.selendroid.standalone.server.model.SelendroidStandaloneDriverTest.java
private void createTestSession(SelendroidConfiguration conf, SelendroidCapabilities caps) throws Exception { // Setting up driver with test app and device stub SelendroidStandaloneDriver driver = getSelendroidStandaloneDriver(); driver.initApplicationsUnderTest(conf); DeviceStore store = new DeviceStore(EMULATOR_PORT, getDeviceManager()); DeviceForTest emulator = new DeviceForTest(DeviceTargetPlatform.ANDROID16); Random random = new Random(); final UUID definedSessionId = new UUID(random.nextLong(), random.nextLong()); emulator.testSessionListener = new TestSessionListener(definedSessionId.toString(), "test") { @Override/*w w w. j a v a 2s . c o m*/ public SelendroidResponse executeSelendroidRequest(Properties params) { return null; } }; store.addDeviceToStore(emulator); driver.setDeviceStore(store); // testing new session creation caps.setPlatformVersion(DeviceTargetPlatform.ANDROID16); try { String sessionId = driver.createNewTestSession(new JSONObject(caps.asMap()), 0); Assert.assertNotNull(UUID.fromString(sessionId)); } finally { // this will also stop the http server emulator.stop(); } }
From source file:osh.busdriver.MieleGatewayBusDriver.java
@Override public void run() { while (true) { synchronized (mieleGatewayDispatcher) { try { // wait for new data mieleGatewayDispatcher.wait(); } catch (InterruptedException e) { getGlobalLogger().logError("should not happen", e); break; }/*from w w w .j a v a 2 s .c o m*/ long timestamp = getTimer().getUnixTime(); if (mieleGatewayDispatcher.getDeviceData().isEmpty()) { // an error has occurred for (UUID uuid : deviceProperties.keySet()) { BusDeviceStatusDetails bs = new BusDeviceStatusDetails(uuid, timestamp); bs.setState(ConnectionStatus.ERROR); getDriverRegistry().setStateOfSender(BusDeviceStatusDetails.class, bs); } } for (MieleDeviceHomeBusData dev : mieleGatewayDispatcher.getDeviceData()) { // build UUID long uuidHigh = UUIDGenerationHelper.getMieleUUIDHigherPart(dev.getUid()); long uuidLow; try { uuidLow = UUIDGenerationHelper.getHomeApplianceUUIDLowerPart((short) dev.getDeviceClass(), mieleGatewayAddr); } catch (Exception e) { getGlobalLogger().logError("should not happen: UUID generation failed", e); continue; } final UUID devUUID = new UUID(uuidHigh, uuidLow); // register UUID as command receiver to the registry if (!deviceProperties.containsKey(devUUID)) { // device already known? IEventReceiver eventReceiver = new IEventReceiver() { @Override public Object getSyncObject() { return MieleGatewayBusDriver.this; } @Override public void onQueueEventReceived(EventExchange event) throws OSHException { MieleGatewayBusDriver.this.onQueueEventReceived(event); } @Override public UUID getUUID() { return devUUID; } }; // register device try { getDriverRegistry().register(StartDeviceRequest.class, eventReceiver); getDriverRegistry().register(StopDeviceRequest.class, eventReceiver); getDriverRegistry().register(SwitchRequest.class, eventReceiver); deviceProperties.put(devUUID, new HashMap<String, String>()); } catch (OSHException e) { // nop. happens. getGlobalLogger().logError("should not happen", e); } } // check if all data is available BusDeviceStatusDetails bs = new BusDeviceStatusDetails(devUUID, timestamp); if (dev.getDeviceDetails() == null) { bs.setState(ConnectionStatus.ERROR); getDriverRegistry().setStateOfSender(BusDeviceStatusDetails.class, bs); continue; } else { bs.setState(ConnectionStatus.ATTACHED); getDriverRegistry().setStateOfSender(BusDeviceStatusDetails.class, bs); } // create program details GenericApplianceProgramDriverDetails programdetails = new GenericApplianceProgramDriverDetails( devUUID, timestamp); programdetails.setLoadProfiles(null); programdetails.setProgramName(dev.getDeviceDetails().getProgramName()); programdetails.setPhaseName(dev.getDeviceDetails().getPhaseName()); // create Miele specific details // duration MieleApplianceDriverDetails mieledetails = new MieleApplianceDriverDetails(devUUID, timestamp); if (dev.getDuration() != null) mieledetails.setExpectedProgramDuration(dev.getDuration().duration() * 60); else mieledetails.setExpectedProgramDuration(-1); // remaining time if (dev.getRemainingTime() != null) mieledetails.setProgramRemainingTime(dev.getRemainingTime().duration() * 60); else mieledetails.setProgramRemainingTime(-1); // start time if (dev.getStartTime() != null) { Calendar cal = Calendar.getInstance(); long nowInMillies = getTimer().getUnixTime() * 1000L; cal.setTimeInMillis(nowInMillies); cal.setTimeZone(getTimer().getHostTimeZone()); cal.set(Calendar.HOUR_OF_DAY, dev.getStartTime().hour()); cal.set(Calendar.MINUTE, dev.getStartTime().minute()); cal.set(Calendar.SECOND, 0); if (cal.getTimeInMillis() <= nowInMillies) cal.add(Calendar.DAY_OF_YEAR, 1); mieledetails.setStartTime(cal.getTimeInMillis() / 1000L); } else mieledetails.setStartTime(-1); // set state of the UUID try { getDriverRegistry().setStateOfSender(GenericApplianceDriverDetails.class, createApplianceDetails(devUUID, timestamp, dev)); getDriverRegistry().setStateOfSender(StartTimeDetails.class, createStartTimeDetails(devUUID, timestamp, dev)); getDriverRegistry().setStateOfSender(GenericApplianceProgramDriverDetails.class, programdetails); getDriverRegistry().setStateOfSender(MieleApplianceDriverDetails.class, mieledetails); } catch (OSHException e1) { bs.setState(ConnectionStatus.ERROR); getDriverRegistry().setStateOfSender(BusDeviceStatusDetails.class, bs); getGlobalLogger().logError(e1); } // extract additional information for invoking commands String detailsUrl = dev.getDetailsUrl(); // extract type and id from details url if (detailsUrl != null) { Map<String, String> devProps = deviceProperties.get(devUUID); try { URIBuilder uri = new URIBuilder(detailsUrl); for (NameValuePair pair : uri.getQueryParams()) { if ("type".equals(pair.getName()) || "id".equals(pair.getName())) { devProps.put(pair.getName(), pair.getValue()); } } } catch (URISyntaxException e) { // nop. shit happens. getGlobalLogger().logError("should not happen", e); } } } } } }
From source file:info.archinnov.achilles.entity.metadata.PropertyMetaTest.java
@Test public void should_serialize_as_json() throws Exception { SimpleTranscoder transcoder = new SimpleTranscoder(objectMapper); PropertyMeta pm = new PropertyMeta(); pm.setType(SIMPLE);/* w ww.j a v a 2 s.c o m*/ pm.setTranscoder(transcoder); assertThat(pm.forceEncodeToJSON(new UUID(10, 10))).isEqualTo("\"00000000-0000-000a-0000-00000000000a\""); }
From source file:info.archinnov.achilles.it.TestDSLEntityWithClusterings.java
@Test public void should_dsl_select_slice_with_asymetric_tuples_same_partition() throws Exception { //Given/*from ww w . j a v a 2 s . c om*/ final Map<String, Object> values = new HashMap<>(); final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); values.put("id1", id); values.put("id2", id); values.put("id3", id); values.put("id4", id); values.put("id5", id); final UUID uuid1 = new UUID(0L, 0L); final UUID uuid2 = new UUID(0L, 1L); values.put("uuid1", uuid1); values.put("uuid2", uuid1); values.put("uuid3", uuid1); values.put("uuid4", uuid2); values.put("uuid5", uuid2); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); final Date date2 = dateFormat.parse("2015-10-02 00:00:00 GMT"); final Date date3 = dateFormat.parse("2015-10-03 00:00:00 GMT"); values.put("date1", "'2015-10-01 00:00:00+0000'"); values.put("date2", "'2015-10-02 00:00:00+0000'"); values.put("date3", "'2015-10-03 00:00:00+0000'"); values.put("date4", "'2015-10-04 00:00:00+0000'"); values.put("date5", "'2015-10-05 00:00:00+0000'"); scriptExecutor.executeScriptTemplate("EntityWithClusteringColumns/insert_many_rows.cql", values); /* Data are ordered as: uuid1, date3, uuid1, date2, uuid1, date1, uuid2, date5, uuid2, date4 because date is ORDERED BY DESC natively but (uuid,date) > (uuid1, date2) AND uuid < uuid2 should return uuid1, date3 */ //When final List<EntityWithClusteringColumns> list = manager.dsl().select().uuid().date().value().fromBaseTable() .where().id_Eq(id).uuid_And_date_Gt_And_uuid_Lt(uuid1, date2, uuid2).getList(); //Then assertThat(list).hasSize(1); assertThat(list.get(0).getUuid()).isEqualTo(uuid1); assertThat(list.get(0).getDate()).isEqualTo(date3); assertThat(list.get(0).getValue()).isEqualTo("val3"); }
From source file:net.e2.bw.idreg.db2ldif.Db2Ldif.java
/** * Generate LDIF for all users/* w ww .j a v a 2 s .c om*/ * @param db the database * @param ldif the LDIF file to append to */ @SuppressWarnings("all") private void importUsers(TeamworkDB db, StringBuilder ldif, Map<String, String> userNames) { long t0 = System.currentTimeMillis(); String sql = loadResourceText("/users.sql"); Connection conn = null; PreparedStatement stmt = null; try { conn = db.getConnection(); stmt = conn.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); int index = 0; while (rs.next()) { String userName = TeamworkDB.getString(rs, "userName"); String entryUUID = TeamworkDB.getString(rs, "userId"); String userFirstName = TeamworkDB.getString(rs, "userFirstName"); String userLastName = TeamworkDB.getString(rs, "userLastName"); String userEmail = TeamworkDB.getString(rs, "userEmail"); String companyId = TeamworkDB.getString(rs, "companyName"); String userImage = TeamworkDB.getString(rs, "userImage"); // Normalize user and company names userName = userName.replace('.', '_'); companyId = companyId(companyId); // Make sure the name is unique if (userNames.containsValue(userName)) { int suffix = 2; while (userNames.containsValue(userName + suffix)) { suffix++; } userName = userName + suffix; } userNames.put(entryUUID, userName); ldif.append("dn: uid=").append(userName).append(",").append(peopleDN).append(NL); ldif.append("objectclass: top").append(NL); ldif.append("objectclass: organizationalPerson").append(NL); ldif.append("objectclass: inetOrgPerson").append(NL); ldif.append("objectclass: maritimeResource").append(NL); ldif.append("ou: people").append(NL); ldif.append("mrn: ").append("urn:mrn:mc:user:").append(companyId).append(":").append(userName) .append(NL); ldif.append("uid: ").append(userName).append(NL); ldif.append("cn: ").append(userFirstName).append(" ").append(userLastName).append(NL); ldif.append("givenName: ").append(userFirstName).append(NL); ldif.append("sn: ").append(userLastName).append(NL); ldif.append("mail: ").append(userEmail).append(NL); ldif.append("userpassword:: ").append("e1NTSEF9QTM3TkF4K0l1Z25UZS8vTHJPbWFOczdZeGVNSk4xeVQ=") .append(NL); ldif.append("entryUUID: ").append(new UUID(Long.parseLong(entryUUID), 0L).toString()).append(NL); if (includePhotos) { byte[] jpg = fetchJPEG(userImage); if (jpg != null) { wrapLine(ldif, "jpegPhoto:: ", Base64.getEncoder().encodeToString(jpg)); } } ldif.append(NL); index++; } rs.close(); System.out.println(String.format("Fetched %d users in %d ms", index, System.currentTimeMillis() - t0)); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (stmt != null) stmt.close(); } catch (Exception ex) { } try { if (conn != null) conn.close(); } catch (Exception ex) { } } }
From source file:es.mdelapenya.uned.master.is.ubicomp.sensors.activities.location.BaseGeoLocatedActivity.java
private String getUniqueDeviceId() { TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); final String deviceId = telephonyManager.getDeviceId(); final String simSerialNumber = telephonyManager.getSimSerialNumber(); final String androidId = android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); UUID deviceUuid = new UUID(androidId.hashCode(), ((long) deviceId.hashCode() << 32) | simSerialNumber.hashCode()); return deviceUuid.toString(); }
From source file:com.strategicgains.docussandra.controller.QueryControllerTest.java
/** * Tests that the POST /{databases}/{table}/query endpoint properly runs a * query with limits./*ww w. ja va 2 s . c o m*/ */ @Test public void postQueryTestWithLimitSameAsResponse() { Query q = new Query(); q.setWhere("field1 = 'this is my data'"); q.setTable("mytable"); //act given().header("limit", "34").header("offset", "0").body("{\"where\":\"" + q.getWhere() + "\"}").expect() .statusCode(200) //.header("Location", startsWith(RestAssured.basePath + "/")) .body("", notNullValue()).body("id", notNullValue()) .body("id[0]", equalTo(new UUID(Long.MAX_VALUE - 33, 1l).toString())) .body("object[0]", notNullValue()) .body("object[0]", containsString("this is some more random data32")).when().post(""); }
From source file:org.hillview.dataset.remoting.HillviewServer.java
private UUID getId(Command command) { return new UUID(command.getHighId(), command.getLowId()); }