-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArchiver.java
More file actions
35 lines (33 loc) · 1.13 KB
/
Archiver.java
File metadata and controls
35 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class Archiver {
public String getCompressData(String string)
{
StringBuilder builder = new StringBuilder();
int len = string.length();
if(len == 0)
return "";
//
int countOfSymblos = 1;
int currentCodePoint,prevCodePoint = string.codePointAt(0);
int offset = Character.charCount(prevCodePoint);
for(;offset < len;)
{
currentCodePoint = string.codePointAt(offset);
//work with this codepoint
if(currentCodePoint != prevCodePoint)
{
builder.appendCodePoint(prevCodePoint);
builder.append(String.valueOf(countOfSymblos));
countOfSymblos = 1;
}
else
countOfSymblos++;
//to offset on string
offset+=Character.charCount(currentCodePoint);
prevCodePoint = currentCodePoint;
}
//At the end - AGAIN
builder.appendCodePoint(prevCodePoint);
builder.append(String.valueOf(countOfSymblos));
return builder.toString();
}
}