Thread: Two Compile errors :s (Entitylist.java)

Results 1 to 4 of 4
  1. #1 Two Compile errors :s (Entitylist.java) 
    Registered Member
    Join Date
    Feb 2014
    Posts
    31
    Thanks given
    1
    Thanks received
    2
    Rep Power
    4
    These errors are after trying to fix the entitylist stack overflow, My NPC's where not respawning, i took a snippet and am getting this error, im pretty stuck on it. Im most likely over looking the error but help would be fantastic. Thanks.




    My Entitylist.java
    Code:
    package com.rs.game;
    Code:
    
    import java.util.AbstractCollection;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Set;
    
    
    
    
    
    
    
    
    
    
    public class EntityList<T extends Entity> extends AbstractCollection<T> {
        public Object[] entities;
        public Set<Integer> indicies = new HashSet<Integer>();
        public int capacity;
        private final Object lock = new Object();
        
        public EntityList(int capacity) {
            entities = new Object[capacity];
            this.capacity = capacity;
        }
    
    
    
    
        public int getEmptySlot() {
         for (int i = 1; i < entities.length; i++) {
          if (entities[i] == null) {
           return i;
          }
         }
         return -1;
        }
        
        @Override
     public boolean add(T entity) {
         synchronized(lock) {
          int slot = getEmptySlot();
          if (slot == -1) {
           return false;
          }
          add(entity, slot);
            return true;
         }
        }
    
    
    
    
        public void remove(T entity) {
         synchronized(lock) {
            entities[entity.getIndex()] = null;
            indicies.remove(entity.getIndex());
         }
        }
    
    
    
    
        @SuppressWarnings("unchecked")
        public T remove(int index) {
         synchronized(lock) {
            Object temp = entities[index];
            entities[index] = null;
            indicies.remove(index);
            return (call) temp;
         }
        }
    
    
    
    
        @SuppressWarnings("unchecked")
        public T get(int index) {
         synchronized(lock) {
          if(index >= entities.length)
           return null;
          return (call) entities[index];
         }
        }
    
    
    
    
        public void add(T entity, int index) {
            if (entities[index] != null) {
                return;
            }
            entities[index] = entity;
            entity.setIndex(index);
            indicies.add(index);
        }
    
    
    
    
        @Override
     public Iterator<T> iterator() {
         synchronized(lock) {
          return new EntityListIterator<T>(entities, indicies, this);
         }
        }
    
    
    
    
        public boolean contains(T entity) {
            return indexOf(entity) > -1;
        }
    
    
    
    
        public int indexOf(T entity) {
            for (int index : indicies) {
                if (entities[index].equals(entity)) {
                    return index;
                }
            }
            return -1;
        }
    
    
    
    
        @Override
     public int size() {
            return indicies.size();
        }
    
    }

    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Apr 2009
    Posts
    99
    Thanks given
    3
    Thanks received
    3
    Rep Power
    11
    @SuppressWarnings("unchecked")
    public T remove(int index) {
    synchronized (lock) {
    Object temp = entities[index];
    entities[index] = null;
    indicies.remove(index);
    decreaseIndex();
    return (T) temp;
    }
    }

    @SuppressWarnings("unchecked")
    public T get(int index) {
    synchronized (lock) {
    if (index >= entities.length)
    return null;
    return (T) entities[index];
    }
    }
    there you are buddy
    replace those two methods in yours, should work let me know if not
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Feb 2014
    Posts
    31
    Thanks given
    1
    Thanks received
    2
    Rep Power
    4
    Quote Originally Posted by __nazo__ View Post
    @SuppressWarnings("unchecked")
    public T remove(int index) {
    synchronized (lock) {
    Object temp = entities[index];
    entities[index] = null;
    indicies.remove(index);
    decreaseIndex();
    return (T) temp;
    }
    }

    @SuppressWarnings("unchecked")
    public T get(int index) {
    synchronized (lock) {
    if (index >= entities.length)
    return null;
    return (T) entities[index];
    }
    }
    there you are buddy
    replace those two methods in yours, should work let me know if not
    Cheers, it was more simple than i thought haha
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Apr 2009
    Posts
    99
    Thanks given
    3
    Thanks received
    3
    Rep Power
    11
    No Problem bud!
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Two Compiling Errors. (Help Please!)
    By Zigmahh in forum Help
    Replies: 2
    Last Post: 11-15-2014, 03:15 AM
  2. [667] Compiling error in commands.java
    By Andy Biersack in forum Help
    Replies: 2
    Last Post: 06-20-2014, 12:59 AM
  3. compiler error with commands.java
    By djs015 in forum Help
    Replies: 4
    Last Post: 04-07-2012, 03:23 PM
  4. [pi]two compile errors..
    By Tired in forum Help
    Replies: 4
    Last Post: 08-02-2011, 03:22 PM
  5. Java Help + Compiler Errors + highscores help
    By Silenced in forum Requests
    Replies: 6
    Last Post: 10-16-2008, 03:38 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •