encode() {
			const spaceCharCode = StringUtils.getCharCode(' ');
			const lineBreakCharCode = StringUtils.getCharCode('\n');
			let states = Collections.singletonList(State.INITIAL_STATE);
			for (let index = 0; index < this.text.length; index++) {
				let pairCode;
				let nextChar = index + 1 < this.text.length ? this.text[index + 1] : 0;
				switch (this.text[index]) {
					case StringUtils.getCharCode('\r'):
						pairCode = nextChar === lineBreakCharCode ? 2 : 0;
						break;
					case StringUtils.getCharCode('.'):
						pairCode = nextChar === spaceCharCode ? 3 : 0;
						break;
					case StringUtils.getCharCode(','):
						pairCode = nextChar === spaceCharCode ? 4 : 0;
						break;
					case StringUtils.getCharCode(':'):
						pairCode = nextChar === spaceCharCode ? 5 : 0;
						break;
					default:
						pairCode = 0;
				}
				if (pairCode > 0) {
					// We have one of the four special PUNCT pairs.  Treat them specially.
					// Get a new set of states for the two new characters.
					states = HighLevelEncoder.updateStateListForPair(states, index, pairCode);
					index++;
				}
				else {
					// Get a new set of states for the new character.
					states = this.updateStateListForChar(states, index);
				}
			}
			// We are left with a set of states.  Find the shortest one.
			const minState = Collections.min(states, (a, b) => {
				return a.getBitCount() - b.getBitCount();
			});
			// Convert it to a bit array, and return.
			return minState.toBitArray(this.text);
		}
@return text represented by this encoder encoded as a {@link BitArray}