Java tutorial
//package com.java2s; //License from project: Apache License import android.support.annotation.NonNull; import java.util.UUID; public class Main { /** * check if full style or short (16bits) style UUID matches * * @param src the UUID to be compared * @param dst the UUID to be compared * @return true if the both of UUIDs matches */ public static boolean matches(@NonNull final UUID src, @NonNull final UUID dst) { if (isShortUuid(src) || isShortUuid(dst)) { // at least one instance is short style: check only 16bits long srcShortUUID = src.getMostSignificantBits() & 0x0000ffff00000000L; long dstShortUUID = dst.getMostSignificantBits() & 0x0000ffff00000000L; return srcShortUUID == dstShortUUID; } else { return src.equals(dst); } } /** * Check if the specified UUID style is short style. * * @param src the UUID * @return true if the UUID is short style */ private static boolean isShortUuid(@NonNull final UUID src) { return ((src.getMostSignificantBits() & 0xffff0000ffffffffL) == 0L) && (src.getLeastSignificantBits() == 0L); } }