Java BigInteger Calculate createUUID(int version, String gtin, BigInteger phar)

Here you can find the source of createUUID(int version, String gtin, BigInteger phar)

Description

The deterministic id of an ArtikelstammItem item.

License

Open Source License

Parameter

Parameter Description
cummulatedVersion a parameter
type a parameter
gtin a parameter
phar a parameter

Return

deterministic uuid of an item

Declaration

public static String createUUID(int version, String gtin,
        BigInteger phar) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013-2015 MEDEVIT.//from w w w.  j  a v  a2  s  .co m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     MEDEVIT <office@medevit.at> - initial API and implementation
 ******************************************************************************/

import java.math.BigInteger;

public class Main {
    /**
     * The deterministic id of an {@link ArtikelstammItem} item. Fixed length 25 chars. Assembled as
     * follows:<br>
     * <li>Characters 0-13: GTIN, if gtin less 14 chars, left padded with zeros <li>Characters
     * 14-20: Pharmacode, if Pharmacode less 7 chars, left padded with zeros <li>Character 21: P or
     * N, depending on {@link ArtikelstammConstants.TYPE} <li>Character 22-24: cummulatedVersion, if
     * >9999 or <0 set to 0 <br>
     * 
     * @param cummulatedVersion
     * @param type
     * @param gtin
     * @param phar
     * @return deterministic uuid of an {@link ARTIKELSTAMM} item
     */
    public static String createUUID(int version, String gtin,
            BigInteger phar) {
        return createUUID(version, gtin, phar, true);
    }

    /**
     * For importer usage, for regular usage see {@link #createUUID(int, TYPE, String, BigInteger)}
     * 
     * @param version
     * @param gtin
     * @param phar
     * @param includeVersion
     *            include the version number of the dataset
     * @return deterministic uuid of an {@link ARTIKELSTAMM} item
     */
    public static String createUUID(int version, String gtin,
            BigInteger phar, final boolean includeVersion) {
        StringBuilder sb = new StringBuilder();
        if (gtin.length() > 0) {
            sb.append(String.format("%014d", Long.parseLong(gtin)));
        } else {
            sb.append("00000000000000");
        }
        if (phar != null) {
            sb.append(String.format("%07d", phar));
        } else {
            sb.append("0000000");
        }
        if (version > 9999 || version < 0)
            version = 0;
        if (includeVersion)
            sb.append(String.format("%04d", version));
        return sb.toString();
    }
}

Related

  1. clone(BigInteger[] data)
  2. copy_into_byte_array(BigInteger bi, byte[] a)
  3. copyOf(BigInteger[] data, int newLength)
  4. copyOfRange(BigInteger[] data, int from, int to)
  5. createUnsignedBigInteger(byte[] data)
  6. cryptRSA(byte[] data, BigInteger exponent, BigInteger modulus)
  7. decodeBigInteger(String value)
  8. decodeBitListFromBigInteger(BigInteger bits)
  9. decodeFloat(BigInteger rawSign, BigInteger rawExponent, BigInteger rawMantissa, int signWidth, int exponentWidth, int mantissaWidth, int bias, MathContext mc)