Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/* Copyright (c) 2015-2016 Microsoft Corporation. This software is licensed under the MIT License.
 * See the license file delivered with this project for further information.
 */

import java.util.UUID;

public class Main {
    /**
     * Checks if the given UUID starts with the given service UUID i.e. their beginnings match.
     *
     * @param uuidToCheck The UUID to check.
     * @param serviceUuid The expected service UUID to compare against.
     * @return True, if the beginnings match. False otherwise.
     */
    public static boolean uuidStartsWithExpectedServiceUuid(UUID uuidToCheck, UUID serviceUuid) {
        boolean startsWithExpectedServiceUuid = false;

        if (uuidToCheck != null && serviceUuid != null) {
            if (serviceUuid.compareTo(uuidToCheck) == 0) {
                // The UUID is a match
                // No need to do anything
                startsWithExpectedServiceUuid = true;
            } else {
                // Get the beginning of the parsed UUID, leave out the last seven bytes (11 chars)
                String beginningOfUuidToCheck = uuidToCheck.toString().substring(0, 22);
                startsWithExpectedServiceUuid = serviceUuid.toString().startsWith(beginningOfUuidToCheck);
            }
        }

        return startsWithExpectedServiceUuid;
    }
}