// Path: bookmarks-importer/src/main/java/com/dyuproject/protostuffdb/TsKeyUtil.java
// public final class TsKeyUtil
// {
//     private TsKeyUtil() {}
//     
//     public static <T extends Entity<T>> byte[] newKey(final EntityMetadata<T> em, 
//             WriteContext context,
//             T entity)
//     {
//         byte[] key = new byte[9];
//         entity.setTs(context.fillEntityKey(key, em.kind, context.ts(em), -1));
//         return key;
//     }
// }


import static com.dyuproject.protostuffdb.SerializedValueUtil.readBAO$len;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Pattern;
import com.dyuproject.protostuff.ByteString;
import com.dyuproject.protostuff.IntSerializer;
import com.dyuproject.protostuff.LongHashSet;
import com.dyuproject.protostuffdb.DSRuntimeExceptions;
import com.dyuproject.protostuffdb.Datastore;
import com.dyuproject.protostuffdb.DateTimeUtil;
import com.dyuproject.protostuffdb.EntityMetadata;
import com.dyuproject.protostuffdb.HasKeyAndTs;
import com.dyuproject.protostuffdb.KeyUtil;
import com.dyuproject.protostuffdb.Op;
import com.dyuproject.protostuffdb.OpChain;
import com.dyuproject.protostuffdb.SerializedValueUtil;
import com.dyuproject.protostuffdb.TsKeyUtil;
import com.dyuproject.protostuffdb.ValueUtil;
import com.dyuproject.protostuffdb.Visitor;
import com.dyuproject.protostuffdb.WriteContext;
import com.dyuproject.protostuffdb.tag.TagUtil;
        final long ts = Long.parseLong(tsSec) * 1000;
        final String[] tags = tagCSV != null && !tagCSV.isEmpty() ? 
                COMMA.split(tagCSV) : DEFAULT_TAGS;
        
        int concurrentStart = 0;
        BookmarkTag bt;
        if (sorted && tagCurrentId == 0)
        {
            // insert the first auto tag
            bt = new BookmarkTag(DEFAULT_TAG);
            bt.key = newKey(ts, context.exclusiveLast, keySuffixSet, 
                    bt, BookmarkTag.EM, bt.name, concurrentStart++);
            bt.id = ++tagCurrentId;
            tagMap.put(bt.name, bt);
        }
        
        for (String tag : tags)
        {
            // normalize
            tag = tag.toLowerCase();
            
            if (TAG_PATTERN != null && !TAG_PATTERN.matcher(tag).matches())
                return tagCurrentId;
            
            bt = tagMap.get(tag);
            if (bt == null)
            {
                bt = new BookmarkTag(tag);
                bt.key = sorted ? newKey(ts, context.exclusiveLast, keySuffixSet, 
                        bt, BookmarkTag.EM, bt.name, concurrentStart++) : 
// Path: bookmarks-importer/src/main/java/com/dyuproject/protostuffdb/TsKeyUtil.java
// public final class TsKeyUtil
// {
//     private TsKeyUtil() {}
//     
//     public static <T extends Entity<T>> byte[] newKey(final EntityMetadata<T> em, 
//             WriteContext context,
//             T entity)
//     {
//         byte[] key = new byte[9];
//         entity.setTs(context.fillEntityKey(key, em.kind, context.ts(em), -1));
//         return key;
//     }
// }


// Path: bookmarks-importer/src/main/java/bookmarks/user/ImportUtil.java
import static com.dyuproject.protostuffdb.SerializedValueUtil.readBAO$len;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Pattern;
import com.dyuproject.protostuff.ByteString;
import com.dyuproject.protostuff.IntSerializer;
import com.dyuproject.protostuff.LongHashSet;
import com.dyuproject.protostuffdb.DSRuntimeExceptions;
import com.dyuproject.protostuffdb.Datastore;
import com.dyuproject.protostuffdb.DateTimeUtil;
import com.dyuproject.protostuffdb.EntityMetadata;
import com.dyuproject.protostuffdb.HasKeyAndTs;
import com.dyuproject.protostuffdb.KeyUtil;
import com.dyuproject.protostuffdb.Op;
import com.dyuproject.protostuffdb.OpChain;
import com.dyuproject.protostuffdb.SerializedValueUtil;
import com.dyuproject.protostuffdb.TsKeyUtil;
import com.dyuproject.protostuffdb.ValueUtil;
import com.dyuproject.protostuffdb.Visitor;
import com.dyuproject.protostuffdb.WriteContext;
import com.dyuproject.protostuffdb.tag.TagUtil;

        final long ts = Long.parseLong(tsSec) * 1000;
        final String[] tags = tagCSV != null && !tagCSV.isEmpty() ? 
                COMMA.split(tagCSV) : DEFAULT_TAGS;
        
        int concurrentStart = 0;
        BookmarkTag bt;
        if (sorted && tagCurrentId == 0)
        {
            // insert the first auto tag
            bt = new BookmarkTag(DEFAULT_TAG);
            bt.key = newKey(ts, context.exclusiveLast, keySuffixSet, 
                    bt, BookmarkTag.EM, bt.name, concurrentStart++);
            bt.id = ++tagCurrentId;
            tagMap.put(bt.name, bt);
        }
        
        for (String tag : tags)
        {
            // normalize
            tag = tag.toLowerCase();
            
            if (TAG_PATTERN != null && !TAG_PATTERN.matcher(tag).matches())
                return tagCurrentId;
            
            bt = tagMap.get(tag);
            if (bt == null)
            {
                bt = new BookmarkTag(tag);
                bt.key = sorted ? newKey(ts, context.exclusiveLast, keySuffixSet, 
                        bt, BookmarkTag.EM, bt.name, concurrentStart++) : 
                            TsKeyUtil.newKey(BookmarkTag.EM, context, bt);