Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Collection;

public class Main {
    public static void decodeFromString(final Collection<Long> values, final String q, int maxLen) {
        values.clear();
        if (q == null) {
            return;
        }

        int qlen = q.length();
        if (qlen <= 1) {
            return;
        }
        long n = 0;
        int shift = 0;
        for (int i = 0; i < qlen; i++) {
            char c = q.charAt(i);
            if (c == ';') {
                if (maxLen > 0 && n >= maxLen) {
                    // bogus history data
                    values.clear();
                    break;
                }
                values.add(n);
                n = 0;
                shift = 0;
            } else {
                if (c >= '0' && c <= '9') {
                    n += ((c - '0') << shift);
                } else if (c >= 'a' && c <= 'f') {
                    n += ((10 + c - 'a') << shift);
                } else {
                    // bogus history data
                    values.clear();
                    break;
                }
                shift += 4;
            }
        }
    }
}