Code example for Property

Methods: getName

0
	 * Method getGetterSignature. 
	 * 
	 * @return String 
	 */ 
	public String getGetterSignature(Property p) {
		String prefix = c2j.getJavaTypeName( p, false).equals( "boolean" ) ? "is" : "get";
		return prefix + beanCapitalize( p.getName() );
	} 
 
	/** 
	 * @param p 
	 * @return foo -> Foo, FOo -> FOo 
	 */ 
	public String getPropertyName(Property p) {
		return beanCapitalize( p.getName() );
	} 
 
 
	// get the "opposite" collectionnae for a property. Currently a "hack" that just uses the same naming algorithm as in reveng, will fail on more general models! 
	public String getCollectionNameFor(Property property) {
		String str = getPropertyName(property);
		return ReverseEngineeringStrategyUtil.simplePluralize(str);
	} 
	 
	 
	/** 
	 * foo -> Foo 
	 * FOo -> FOo 
	 */ 
	static public String beanCapitalize(String fieldname) {
		if ( fieldname == null || fieldname.length() == 0 ) {
			return fieldname;
		} 
 
		if ( fieldname.length() > 1 && Character.isUpperCase( fieldname.charAt( 1 ) ) ) {
			return fieldname;
		} 
		char chars[] = fieldname.toCharArray();
		chars[0] = Character.toUpperCase( chars[0] );
		return new String( chars );
	} 
 
 
	public boolean isComponent(Property property) {
		Value value = property.getValue();
		if ( value != null && value instanceof Component ) {
			return true; 
		} 
		else { 
			return false; 
		} 
	} 
 
	public String generateHashCode(Property property, String result, String thisName, boolean jdk5) {
		StringBuffer buf = new StringBuffer();
		if ( c2j.getMetaAsBool( property, "use-in-equals" ) ) {
			String javaTypeName = c2j.getJavaTypeName( property, jdk5, this );
			boolean isPrimitive = c2j.isPrimitive( javaTypeName );
			if ( isPrimitive ) {
				buf.append( result )
				.append( " = 37 * " )
				.append( result )
				.append( " + " );
				String thisValue = thisName + "." + getGetterSignature( property ) + "()";
				if("char".equals(javaTypeName)||"int".equals(javaTypeName)||"short".equals(javaTypeName)||"byte".equals(javaTypeName)) {
					buf.append( thisValue );
				} else if("boolean".equals(javaTypeName)) {
					buf.append("(" + thisValue + "?1:0)");
				} else { 
					buf.append( "(int) ");
					buf.append( thisValue );
				} 
				buf.append(";");
			} 
			else { 
				if(javaTypeName.endsWith("[]")) {
					if(jdk5) {
						buf.append( result )
						.append( " = 37 * " )
						.append( result )
						.append( " + " );
						buf.append( "( " )
						.append( getGetterSignature( property ) )
						.append( "() == null ? 0 : " + importType("java.util.Arrays") + ".hashCode(" )
						.append( thisName )
						.append( "." )
						.append( getGetterSignature( property ) )
						.append( "())" )
						.append( " )" )
						.append(";");						
					} 
					else { 
						buf.append(internalGenerateArrayHashcode(property, javaTypeName, result, thisName));
					} 
				} else { 
					buf.append( result )
					.append( " = 37 * " )
					.append( result )
					.append( " + " );
					buf.append( "( " )
					.append( getGetterSignature( property ) )
					.append( "() == null ? 0 : " )
					.append( thisName )
					.append( "." )
					.append( getGetterSignature( property ) )
					.append( "()" )
					.append( ".hashCode()" )
					.append( " )" )
					.append(";");
				} 
			} 
		} 
		return buf.toString();
	} 
 
 
	private String internalGenerateArrayHashcode(Property property, String javaTypeName, String result, String thisName)
	{ 
		StringBuffer buf = new StringBuffer();
 
		String propertyHashVarName = property.getName() + "Hashcode";
		String propertyArrayName = property.getName() + "Property";
 
//		int propertyHash = 0; 
		buf.append( "int ")
		.append( propertyHashVarName )
		.append( " = 0;\n" );