OSDN Git Service

66c2c521da7f7536e4b7ae5ff1852735b63c45ba
[chemicraft/chemicraft.git] / common / pcc / chemicraft / util / ComparatorFormulaPart.java
1 package pcc.chemicraft.util;
2
3 import java.util.Comparator;
4
5 public class ComparatorFormulaPart implements Comparator<FormulaPart> {
6
7         @Override
8         public int compare(FormulaPart o1, FormulaPart o2) {
9                 int i = 0;
10                 byte[] var1Byte = o1.getAtom().getBytes();
11                 byte[] var2Byte = o2.getAtom().getBytes();
12                 while (var1Byte.length > i && var2Byte.length > i) {
13                         if (var1Byte[i] == var2Byte[i]) {
14                                 i++;
15                                 continue;
16                         }
17                         if (var1Byte[i] < var2Byte[i]) {
18                                 return -1;
19                         }
20                         if (var1Byte[i] > var2Byte[i]) {
21                                 return 1;
22                         }
23                 }
24                 return 0;
25         }
26
27 }