@SuppressWarnings({ "unused", "unchecked" })
	private HashMap<String, ActionPattern> buildActionPatterns(Agent agent,
			HashMap<String, Competence> competences2,
			HashMap<String, ActionPattern> actionPatterns2) {
		
		//HashMap<String, ActionPattern> returnActionPatterns = new HashMap<String, ActionPattern>();
		HashMap<String, ActionPattern> returnActionPatterns = actionPatterns2;

		
		Object[] actionPatternArray = this.actionPatterns.keySet().toArray();
		for (int i = 0 ; i < actionPatternArray.length; i++)	{
			String actionPattern = (String) actionPatternArray[i];
			
			ArrayList<CopiableElement> elementList = new ArrayList<CopiableElement>();
			Object[] elementNames = this.actionPatterns.get(actionPattern).Third.toArray();
			for (int j = 0; j <elementNames.length -1; j++ )	{
				//deal with all but the last element
				if (elementNames[j].getClass().equals(String.class) &&  false)	{
					//senseacts not implemented
					
					//unreachable see if conditions
					log.error("Unsupported request for sense-act, will ignore");
					
				}	else if (elementNames[j].getClass().equals(TupleThree.class))	{
					//sense
					elementList.add(buildSense(agent,(TupleThree<String,String,String>)elementNames[j]));
				}	else	{
					//action
					elementList.add(getTriggerable(agent, (String)elementNames[j]));
				}
			}
			
			//last element can also be a competence
			if (elementNames[elementNames.length-1].getClass().equals(String.class) && false)	{
				//senseacts not yet implemented
					
				//unreachable see if conditions
				log.error("Unsupported request for sense-act, will ignore");
					
			}	else if (elementNames[elementNames.length-1].getClass().equals(TupleThree.class))	{
				//sense
				elementList.add(buildSense(agent,(TupleThree<String,String,String>)elementNames[elementNames.length-1]));
			}	else	{
				//action
				elementList.add(getTriggerable(agent, (String)elementNames[elementNames.length-1],competences2));
			}
			
			//elementList toArray
			CopiableElement[] elementArray = new CopiableElement[elementList.size()];
			for (int j = 0; j < elementArray.length; j++)	{
				elementArray[j] = elementList.get(j);
			}
			ActionPattern newAP = actionPatterns2.get(actionPattern);
			newAP.setElements(elementArray);
			returnActionPatterns.put(actionPattern, newAP);
			
		}
		return returnActionPatterns;
		
	}