本文整理汇总了Java中com.thinkaurelius.titan.util.encoding.LongEncoding类的典型用法代码示例。如果您正苦于以下问题:Java LongEncoding类的具体用法?Java LongEncoding怎么用?Java LongEncoding使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LongEncoding类属于com.thinkaurelius.titan.util.encoding包,在下文中一共展示了LongEncoding类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeUniqueInstanceId
import com.thinkaurelius.titan.util.encoding.LongEncoding; //导入依赖的package包/类
private static String computeUniqueInstanceId(Configuration config) {
final String suffix;
if (config.has(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID_SUFFIX)) {
suffix = LongEncoding.encode(config.get(
GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID_SUFFIX));
} else {
suffix = ManagementFactory.getRuntimeMXBean().getName() + LongEncoding.encode(INSTANCE_COUNTER.incrementAndGet());
}
byte[] addrBytes;
try {
addrBytes = Inet4Address.getLocalHost().getAddress();
} catch (UnknownHostException e) {
throw new TitanConfigurationException("Cannot determine local host", e);
}
String uid = new String(Hex.encodeHex(addrBytes)) + suffix;
for (char c : ConfigElement.ILLEGAL_CHARS) {
uid = StringUtils.replaceChars(uid,c,'-');
}
return uid;
}
示例2: testEncoding
import com.thinkaurelius.titan.util.encoding.LongEncoding; //导入依赖的package包/类
@Test
public void testEncoding() {
final int number = 1000000;
final Random r = new Random();
long start = System.currentTimeMillis();
for (int i=0;i<number;i++) {
long l = Math.abs(r.nextLong());
if (l==Long.MIN_VALUE) continue;
assertEquals(l, LongEncoding.decode(LongEncoding.encode(l)));
}
System.out.println("Time to de/encode "+number+" longs (in ms): " + (System.currentTimeMillis()-start));
}
示例3: testCaseInsensitivity
import com.thinkaurelius.titan.util.encoding.LongEncoding; //导入依赖的package包/类
@Test
public void testCaseInsensitivity() {
Set<String> codes = Sets.newHashSet();
for (int i = 0; i < 500000; i++) {
assertTrue(codes.add(LongEncoding.encode(i).toLowerCase()));
}
}
示例4: toString
import com.thinkaurelius.titan.util.encoding.LongEncoding; //导入依赖的package包/类
@Override
public String toString() {
StringBuilder s = new StringBuilder();
s.append(LongEncoding.encode(relationId)).append(TOSTRING_DELIMITER).append(LongEncoding.encode(outVertexId))
.append(TOSTRING_DELIMITER).append(LongEncoding.encode(typeId));
if (inVertexId != 0) s.append(TOSTRING_DELIMITER).append(LongEncoding.encode(inVertexId));
return s.toString();
}
示例5: parse
import com.thinkaurelius.titan.util.encoding.LongEncoding; //导入依赖的package包/类
public static final RelationIdentifier parse(String id) {
String[] elements = id.split(TOSTRING_DELIMITER);
if (elements.length != 3 && elements.length != 4)
throw new IllegalArgumentException("Not a valid relation identifier: " + id);
try {
return new RelationIdentifier(LongEncoding.decode(elements[1]),
LongEncoding.decode(elements[2]),
LongEncoding.decode(elements[0]),
elements.length == 4 ? LongEncoding.decode(elements[3]) : 0);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid id - each token expected to be a number", e);
}
}
示例6: toString
import com.thinkaurelius.titan.util.encoding.LongEncoding; //导入依赖的package包/类
@Override
public String toString() {
StringBuilder s = new StringBuilder();
s.append(LongEncoding.encode(relationId)).append(TOSTRING_DELIMITER).append(LongEncoding.encode(outVertexId))
.append(TOSTRING_DELIMITER).append(LongEncoding.encode(typeId));
if (inVertexId!=0) s.append(TOSTRING_DELIMITER).append(LongEncoding.encode(inVertexId));
return s.toString();
}
示例7: parse
import com.thinkaurelius.titan.util.encoding.LongEncoding; //导入依赖的package包/类
public static final RelationIdentifier parse(String id) {
String[] elements = id.split(TOSTRING_DELIMITER);
if (elements.length != 3 && elements.length != 4) throw new IllegalArgumentException("Not a valid relation identifier: " + id);
try {
return new RelationIdentifier(LongEncoding.decode(elements[1]),
LongEncoding.decode(elements[2]),
LongEncoding.decode(elements[0]),
elements.length==4?LongEncoding.decode(elements[3]):0);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid id - each token expected to be a number",e);
}
}
示例8: longID2Name
import com.thinkaurelius.titan.util.encoding.LongEncoding; //导入依赖的package包/类
private static final String longID2Name(long id) {
Preconditions.checkArgument(id > 0);
return LongEncoding.encode(id);
}
示例9: name2LongID
import com.thinkaurelius.titan.util.encoding.LongEncoding; //导入依赖的package包/类
private static final long name2LongID(String name) {
return LongEncoding.decode(name);
}