1. package org.jr.util;
  2. /**
  3. * Copyright: Copyright (c) 2002-2004
  4. * Company: JavaResearch(http://www.javaresearch.org)
  5. * 最后更新日期:2003年3月26日
  6. * @author Cherami
  7. */
  8. import java.util.*;
  9. /**
  10. * 此类中封装一些常用的TreeSet操作方法。
  11. * 所有方法都是静态方法,不需要生成此类的实例,
  12. * 为避免生成此类的实例,构造方法被申明为private类型的。
  13. * @since 0.5
  14. */
  15. public class TreeSetUtil {
  16. /**
  17. * 私有构造方法,防止类的实例化,因为工具类不需要实例化。
  18. */
  19. private TreeSetUtil() {
  20. }
  21. /**
  22. * 将数组转换为TreeSet。
  23. * @param array 数组
  24. * @return 转换后的TreeSet,如果数组为null则返回null
  25. * @since 0.5
  26. */
  27. public static TreeSet ArrayToTreeSet(Object[] array) {
  28. if (array != null) {
  29. TreeSet treeSet = new TreeSet();
  30. for (int i = 0; i < array.length; i++) {
  31. treeSet.add(array[i]);
  32. }
  33. return treeSet;
  34. }
  35. else {
  36. return null;
  37. }
  38. }
  39. }