improved cuttable string
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / string / CuttableString.java
1 package eu.svjatoslav.commons.string;
2
3 public class CuttableString {
4
5         private String value;
6
7         public CuttableString(final String value) {
8                 this.value = value;
9         }
10
11         /**
12          * Cut given amount of characters from the left of the string. Return cutted
13          * part.
14          */
15         public String cutLeft(final int cutAmount) {
16
17                 int actualCutAmount = cutAmount;
18
19                 if (actualCutAmount > value.length())
20                         actualCutAmount = value.length();
21
22                 final String result = value.substring(0, actualCutAmount);
23
24                 value = value.substring(actualCutAmount);
25
26                 return result;
27         }
28
29         public int getLength() {
30                 return value.length();
31         };
32
33         public String getValue() {
34                 return value;
35         }
36
37         public boolean isEmpty() {
38                 return value.length() == 0;
39         }
40 }