1 /*
2  * State
3  *
4  * Authors: Lasse Collin <lasse.collin@tukaani.org>
5  *          Igor Pavlov <http://7-zip.org/>
6  *
7  * This file has been put into the public domain.
8  * You can do whatever you want with this file.
9  */
10 
11 package org.tukaani.xz.lzma;
12 
13 final class State {
14     static final int STATES = 12;
15 
16     private static final int LIT_STATES = 7;
17 
18     private static final int LIT_LIT = 0;
19     private static final int MATCH_LIT_LIT = 1;
20     private static final int REP_LIT_LIT = 2;
21     private static final int SHORTREP_LIT_LIT = 3;
22     private static final int MATCH_LIT = 4;
23     private static final int REP_LIT = 5;
24     private static final int SHORTREP_LIT = 6;
25     private static final int LIT_MATCH = 7;
26     private static final int LIT_LONGREP = 8;
27     private static final int LIT_SHORTREP = 9;
28     private static final int NONLIT_MATCH = 10;
29     private static final int NONLIT_REP = 11;
30 
31     private int state;
32 
State()33     State() {}
34 
State(State other)35     State(State other) {
36         state = other.state;
37     }
38 
reset()39     void reset() {
40         state = LIT_LIT;
41     }
42 
get()43     int get() {
44         return state;
45     }
46 
set(State other)47     void set(State other) {
48         state = other.state;
49     }
50 
updateLiteral()51     void updateLiteral() {
52         if (state <= SHORTREP_LIT_LIT)
53             state = LIT_LIT;
54         else if (state <= LIT_SHORTREP)
55             state -= 3;
56         else
57             state -= 6;
58     }
59 
updateMatch()60     void updateMatch() {
61         state = state < LIT_STATES ? LIT_MATCH : NONLIT_MATCH;
62     }
63 
64     void updateLongRep() {
65         state = state < LIT_STATES ? LIT_LONGREP : NONLIT_REP;
66     }
67 
68     void updateShortRep() {
69         state = state < LIT_STATES ? LIT_SHORTREP : NONLIT_REP;
70     }
71 
72     boolean isLiteral() {
73         return state < LIT_STATES;
74     }
75 }
76