1 Replies - 215 Views - Last Post: 06 December 2011 - 10:15 AM Rate Topic: -----

#1 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

HashSet not seen

Posted 06 December 2011 - 09:08 AM

I can not figure out why the booleans can not see the HashSet (lines 54-63) that is in bold. The strings "type, location and station" are seen but not the hashset vehic. Any help for a novice that is learning is appreciated

package display;

import org.apache.log4j.Logger;
import java.util.HashSet;
import java.util.Set;

public class PrintOut {

	public long timeSec;

	public String ID = "";
        public String data = "";
	public static String location = "";
	public static String type = "";
	public String units = "";
	public static String station = "";
        public static HashSet vehic;
        private Logger log = Logger.getRootLogger();
	
	public boolean FirstDuealerted = false;
	public boolean BoxAlarmalerted = false;
	public boolean StreetAlarmalerted= false;
	public boolean EAMalerted = false;
	public boolean EngineAmboalerted = false;
	public boolean EngineMedicalerted = false;
	public boolean AmboMedicalerted = false;
	public boolean Enginealerted = false;
	public boolean Amboalerted = false;
	public boolean Medicalerted = false;
        

	public PrintOut(String header) {
		ID = Reciever.getId(header);
		this.data+=header;
	}

	public void addPart(String dataIn) {
		this.data += dataIn;
		if (data.contains("Station:")); {
			int temp = data.indexOf("Station:");
			station = new String(data.substring(temp + 8,(temp + 8) + 2));
			//log.info("Station :" + station);
		}
		if (data.contains("Final Type:")) {
			int temp = data.indexOf("Final Type:");
			type = new String(data.substring(temp + 11,(temp +11) + 6));
			//log.info("Type :" + type);
		}
		if (data.contains("Location:"))  {
			int temp = data.indexOf("Location:");
			location = new String(data.substring(temp + 9,(temp +9) + 25));
			//log.info("Location :" + location);
		}
           [u][i][b]HashSet <String> vehic = new HashSet<String>();
                if (data.contains("PE830")){
                    vehic.add("PE830");
                     }
                if (data.contains("A830")){
                    vehic.add("A830");
                     }
                if (data.contains("MD830")){
                    vehic.add("MD830");
                     }
[/b][/i][/u]

		log.info("Units: [" + units + "]");
		log.info("Type: [" + type + "]");
		log.info("Location: [" + location + "]");
		log.info("Station: [" + station + "]");
	}
        
        public boolean alertFirstDue() {
		if (FirstDuealerted == false) {
			if ((type.contains("APTF")) || (type.contains("HOUSEF"))
					|| (type.contains("BUILDF")) || (type.contains("BUILDT")) 
					|| (type.contains("APTT")) || (type.contains("BUILDT"))
					|| (type.contains("HOUSET")) || (type.contains("TOWNHF")) 
                                        || (type.contains("TOWNHT")))  {
				if ((station =="30") && (vehic.contains("PE830"))) {
					FirstDuealerted = true;
					units = ("FIRST DUE");
					new EggTimer(45);
					return true;
				}
			}
		}

		return false;
	}
        
        public boolean alertBoxAlarm() {
		if (BoxAlarmalerted == false) {
			if ((type.contains("APTF")) || (type.contains("HOUSEF"))
					|| (type.contains("BUILDF")) || (type.contains("BUILDT")) 
					|| (type.contains("APTT")) || (type.contains("BUILDT"))
					|| (type.contains("HOUSET")) || (type.contains("TOWNHF")) 
                                        || (type.contains("TOWNHT")))  {
				if ((station !="30") && (vehic.contains("PE830"))) {
					BoxAlarmalerted = true;
					units = ("BoxAlarm");
					new EggTimer(45);
					return true;
				}
			}
		}

		return false;
	}
        
	public boolean alertStreetAlarm() {
		if (StreetAlarmalerted == false) {
                                if ((type.contains("APTG")) || (type.contains("HOUSEG"))
					|| (type.contains("BUILDG")) || (type.contains("COLAPS"))
					|| (type.contains("CONFSP")) || (type.contains("PLANE"))
					|| (type.contains("RTASK")) || (type.contains("STREET"))
					|| (type.contains("TOWNHG")) && (vehic.contains("PE830"))){
				StreetAlarmalerted = true;
				new EggTimer(45);
				if (FirstDuealerted == false) {
					units = ("streetalarm");
				}
				return true;
			}
		}
		return false;
	}

	
    public boolean alertEAM() {
		if (EAMalerted == false) {
			if ((vehic.contains("A830")) && (vehic.contains("MD830")) && (vehic.contains("PE830"))) {
				EAMalerted = true;
				new EggTimer(45);
				if (FirstDuealerted == false) {
					units = ("engineambomedic");
				}
				return true;
			}
		}
		return false;
	}

      public boolean alertEngineAmbo() {
		if (EngineAmboalerted == false) {
			if ((vehic.contains("PE830")) && (vehic.contains("A830")) && EAMalerted == false) {
				if (FirstDuealerted == false) {
				EngineAmboalerted = true;
				log.info("Engine Ambo ALERTED!");
				new EggTimer(45);
				units = ("engineambo");
				}
				return true;
			}
		}
		return false;
	}

    public boolean alertEngineMedic() {
		if (EngineMedicalerted == false) {
			if ((vehic.contains("PE830")) && (vehic.contains("MD830"))&& EAMalerted == false){
				if ((FirstDuealerted == false)) {
				EngineMedicalerted = true;
				new EggTimer(45);
				units = ("enginemedic");
				}
				return true;
			}
		}
		return false;
	}

    	public boolean alertAmboMedic() {
		if (AmboMedicalerted == false) {
			if ((vehic.contains("A830 "))&&(vehic.contains("MD830")) && EAMalerted == false) {
				if ((FirstDuealerted == false)) {
                                AmboMedicalerted = true;
				log.info("Ambo Medic ALERTED!");
				new EggTimer(180);
				
					units = ("ambomedic");
				}
				return true;
			}
		}
		return false;
	}

	public boolean alertEngine() {
		if (Enginealerted == false) {
			if ((vehic.contains("PE830"))&& BoxAlarmalerted == false && StreetAlarmalerted == false && EAMalerted == false && EngineAmboalerted == false && EngineMedicalerted == false) {
				if ((FirstDuealerted == false)) {
				Enginealerted = true;
				new EggTimer(180);
				units = ("Engine");
				}
				return true;
                                
			}
		}
		return false;
	}
	public boolean alertAmbo() {
		if (Amboalerted == false) {
			if ((vehic.contains("A830")) && EAMalerted == false && EngineAmboalerted == false && AmboMedicalerted == false) {
				if ((FirstDuealerted == false)) {
				Amboalerted = true;
				log.info("A846 ALERTED!");
				new EggTimer(45);
				units = ("ambo");
				}
				return true;
			}
		}
		return false;
	}

        public boolean alertMedic() {
		if (Medicalerted == false) {
			if ((vehic.contains("MD830")) && EAMalerted == false && EngineMedicalerted == false && AmboMedicalerted == false) {
				if (FirstDuealerted == false) {
				Medicalerted = true;
				log.info("MD846 ALERTED!");
				new EggTimer(45);
				units = ("MEDIC");
				}
				return true;
			}
		}
		return false;
	}


	
	public String toString() {
		return (ID + location + station);
	}

	public int hashCode() {
		return toString().hashCode();
	}

    void replace(String data) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: HashSet not seen

#2 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8037
  • View blog
  • Posts: 13,754
  • Joined: 19-March 11

Re: HashSet not seen

Posted 06 December 2011 - 10:15 AM

Since the HashSet is a local declaration, it disappears when the method exits. This is why you can't refer to it elsewhere.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1