Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.transistore.basic;
  
Value class that contains identifier used for accessing piece of content: basically contains optional partition id and String.
 
 public class BasicTSKey
     extends EntryKey
 {
    
Let's model external key presentation as an URI of sort.
 
     public final static String KEY_PREFIX = "tstore://";

    
And use meow char for separating optional partition from path
 
     public final static char KEY_SEPARATOR = '@';
     
     /*
     /**********************************************************************
     /* Main configuration
     /**********************************************************************
      */
    
    
Raw representation used for the underlying store
 
     private final StorableKey _rawKey;

    
Length of group id, in bytes (not necessarily characters).
 
     private final int _partitionIdLength;
    
    
Full path, including Partition id as prefix.
 
     private transient String _externalPath;
     
     /*
     /**********************************************************************
     /* Construction
     /**********************************************************************
      */
 
     protected BasicTSKey(StorableKey rawint partitionIdLength)
     {
          = raw;
          = partitionIdLength;
     }
     
     /*
     /**********************************************************************
     /* Accessors, converters
     /**********************************************************************
      */
 
     @Override
     public StorableKey asStorableKey() {
         return ;
     }
 
     @Override
     public byte[] asBytes() {
         return .asBytes();
     }
     
     /*
     /**********************************************************************
     /* Extended API
     /**********************************************************************
      */

    
Accessor for getting path part of key, not including partition id.
 
     public String getPath()
     {
         String full = getPartitionAndPath();
         if ( == 0) {
             return full;
         }
         return full.substring();
     }

    
Accessor for getting concatenation of partition id (if any) and path.
 
     public String getPartitionAndPath()
     {
         String str = ;
         if (str == null) {
            final int offset = .;
            final int length = .length() - offset;
             = str = .withRange(.offsetlength);
        }
        return str;
    }

    
Accessor for getting partition id part of key, if any; if no partition id, returns null.
    public String getPartitionId()
    {
        if ( == 0) {
            return null;
        }
        return getPartitionAndPath().substring(0, );
    }
    public byte[] getPartitionIdAsBytes()
    {
        if ( == 0) {
            return null;
        }
    }

    
Callback-based accessor for accessing part of key formed when path itself is dropped, and only client id and group id are included. Note that method can only be called when there is a group id; otherwise a java.lang.IllegalStateException will be thrown.
    public <T> T withPartitionPrefix(WithBytesCallback<T> cb)
    {
        if ( <= 0) {
            throw new IllegalStateException("Key does not have a partition id, can not call this method");
        }
        return .withRange(cb, 0, len);
    }
    
    public boolean hasPartitionId() {
        return ( > 0);
    }
    public int getPartitionIdLength() {
        return ;
    }
    
    /*
    /**********************************************************************
    /* Overridden std methods
    /**********************************************************************
     */
    
    @Override public boolean equals(Object o)
    {
        if (o == thisreturn true;
        if (o == nullreturn false;
        if (o.getClass() != getClass()) return false;
        BasicTSKey other = (BasicTSKeyo;
        return .equals(other._rawKey);
    }
    @Override public int hashCode() {
        return .hashCode();
    }
    @Override public String toString()
    {
        String path = getPartitionAndPath();
        final int pathLen = path.length();
        StringBuilder sb = new StringBuilder(10 + pathLen);
        sb.append();
        int partLen = getPartitionIdLength();
        // !!! TODO: implement escaping properly
        if (partLen == 0) {
            sb.append();
            sb.append(path);
        } else {
            sb.append(path);
            sb.insert(.length() + partLen);
        }
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X