jp.co.ntts.vhut.util.VhutUtil.java Source code

Java tutorial

Introduction

Here is the source code for jp.co.ntts.vhut.util.VhutUtil.java

Source

/*
 * Copyright 2011 NTT Software Corporation.
 * All Rights Reserved.
 */
package jp.co.ntts.vhut.util;

import org.apache.commons.lang.StringUtils;

/**
 * Vhut??????.
 *
 * @version 1.0.0
 * @author NTT Software Corporation.
 *
 * <!--
 * $Date: 2011-11-28 19:50:40 +0900 (, 28 11 2011) $
 * $Revision: 949 $
 * $Author: NTT Software Corporation. $
 * -->
 */
public class VhutUtil {

    private VhutUtil() {
    }

    /**
     * VM???????.
     * @param prefix 
     * @param seed ?????
     * @return ??
     */
    public static String createVmName(String prefix, long seed) {
        return createElementName(prefix, seed);
    }

    /**
     * ???????.
     * @param prefix 
     * @param seed ?????
     * @return ??
     */
    public static String createTemplateName(String prefix, long seed) {
        return createElementName(prefix, seed);
    }

    /**
     * ????????.
     * @param prefix 
     * @param seed ?????
     * @return ??
     */
    public static String createNetworkAdapterName(long seed) {
        return createElementName("nwa", seed);
    }

    /**
     * ????????.
     * @param prefix 
     * @param seed ?????
     * @return ??
     */
    public static String createNetworkAdapterTemplateName(long seed) {
        return createElementName("nwat", seed);
    }

    /**
     * Vhut????????.
     * @param prefix 
     * @param seed ?????
     * @return ??
     */
    public static String createElementName(String prefix, long seed) {
        String hex = VhutLongConversionUtil.toHexString(seed, 16);
        return String.format("%s_%s", prefix, hex.substring(hex.length() - 8));
    }

    /**
     * Vhut????????????.
     * @param prefix 
     * @param privateId ?ID
     * @return ?
     */
    public static String createServicePrefix(String prefix, long privateId) {
        String privateIdString = new Long(privateId).toString();
        if (privateIdString.length() > 2) {
            privateIdString = privateIdString.substring(privateIdString.length() - 3);
        }
        String id = StringUtils.leftPad(privateIdString, 3, "0");
        return String.format("%s%s", prefix, id);
    }

    /**
     * ????????.
     * @param prefix ??
     * @param vlan VLAN?
     * @return ??
     */
    public static String createNetworkName(String prefix, short vlan) {
        String id = StringUtils.leftPad(Short.toString(vlan), 4, "0");
        return String.format("%s%s", prefix, id);
    }

    /**
     * ???????????.
     * @param name ?
     * @param prefix 
     * @return ??
     */
    public static boolean hasPrefix(String name, String prefix) {
        if (name == null || prefix == null)
            return false;
        if (name.length() < prefix.length())
            return false;
        return name.substring(0, prefix.length()).equals(prefix);
    }

}

/**
 * =====================================================================
 * 
 *    Copyright 2011 NTT Sofware Corporation
 * 
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 * 
 *        http://www.apache.org/licenses/LICENSE-2.0
 * 
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 * 
 * =====================================================================
 */