Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. package org.dusk.cache.updated;
  2.  
  3. import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
  4.  
  5. public enum Protocol {
  6.  
  7. BUILD_877(),
  8.  
  9. BUILD_OSRS_180();
  10.  
  11. static {
  12. for (DefinitionType definitionType : DefinitionType.values()) {
  13. for (Protocol protocol : Protocol.values()) {
  14. if (definitionType.contains(protocol) && !protocol.contains(definitionType)) {
  15. throw new IllegalArgumentException(protocol + " does not support " + definitionType + ".");
  16. }
  17. }
  18. }
  19. }
  20.  
  21. static class DefinitionLookup {
  22.  
  23. private final DefinitionType type;
  24. private final int fs, folder, file;
  25.  
  26. private DefinitionLookup(DefinitionType type, int fs, int folder, int file) {
  27. this.type = type;
  28. this.fs = fs;
  29. this.folder = folder;
  30. this.file = file;
  31. }
  32.  
  33. public DefinitionLookup(DefinitionType type, int fs, int folder) {
  34. this(type, fs, folder, -1);
  35. }
  36.  
  37. public DefinitionLookup(DefinitionType type, int fs) {
  38. this(type, fs, -1, -1);
  39. }
  40.  
  41. public int getFs() {
  42. return fs;
  43. }
  44.  
  45. public int getFolder() {
  46. return folder;
  47. }
  48.  
  49. public int getFile() {
  50. return file;
  51. }
  52. }
  53.  
  54. private final Object2ObjectOpenHashMap<DefinitionType, DefinitionLookup> map;
  55.  
  56. Protocol(DefinitionLookup... lookups) {
  57. this.map = new Object2ObjectOpenHashMap<>();
  58. for (DefinitionLookup lookup : lookups) {
  59. map.put(lookup.type, lookup);
  60. }
  61. }
  62.  
  63. public boolean contains(DefinitionType type) {
  64. return map.containsKey(type);
  65. }
  66.  
  67. public DefinitionLookup lookup(DefinitionType type) {
  68. return map.get(type);
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement