OSDN Git Service

いろいろした
[chemicraft/chemicraft.git] / common / pcc / chemicraft / util / ComparatorFormulaPart.java
1 package pcc.chemicraft.util;
2
3 import java.util.Comparator;
4
5 /**
6  * 元素情報を比較します。
7  * @author mozipi
8  */
9 public class ComparatorFormulaPart implements Comparator<FormulaPart> {
10
11         @Override
12         public int compare(FormulaPart o1, FormulaPart o2) {
13                 int i = 0;
14                 byte[] var1Byte = o1.getAtom().getBytes();
15                 byte[] var2Byte = o2.getAtom().getBytes();
16                 while (var1Byte.length > i && var2Byte.length > i) {
17                         if (var1Byte[i] == var2Byte[i]) {
18                                 i++;
19                                 continue;
20                         }
21                         if (var1Byte[i] < var2Byte[i]) {
22                                 return -1;
23                         }
24                         if (var1Byte[i] > var2Byte[i]) {
25                                 return 1;
26                         }
27                 }
28                 return 0;
29         }
30
31 }