Guest User

Untitled

a guest
Oct 5th, 2013
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. public static boolean machesIgnoreOrder (Object[] ... tables){
  2. if (tables == null){
  3. throw new NullPointerException();
  4. }else if (tables.length == 0){
  5. throw new IllegalArgumentException("tables length cannot equal 0");
  6. }else if (tables.length == 1){
  7. return true;
  8. }
  9.  
  10. int size = -1;
  11. List<Object>[] lists = new ArrayList[tables.length];
  12.  
  13. for (int i = 0; i < tables.length; i++){
  14. Object[] table = tables[i];
  15.  
  16. if (table == null){
  17. throw new NullPointerException();
  18. }
  19.  
  20. if (size != -1 && size != table.length){
  21. return false;
  22. }else if (size == -1){
  23. size = table.length;
  24. }
  25.  
  26. lists[i] = new ArrayList<Object>(Arrays.asList(table));
  27. }
  28.  
  29. for (int i = 0; i < size; i++){
  30. Object lookingFor = lists[0].get(i);
  31.  
  32. for (int ii = 1; ii < lists.length; ii++){
  33. boolean found = false;
  34.  
  35. for (int iii = 0; iii < lists[ii].size(); iii++){
  36. if (lists[ii].get(iii).equals(lookingFor)){
  37. lists[ii].remove(iii);
  38. found = true;
  39. break;
  40. }
  41. }
  42.  
  43. if (!found){
  44. return false;
  45. }
  46. }
  47. }
  48. return true;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment