-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57ab58b
commit 4917528
Showing
7 changed files
with
363 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.bsc.processor; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* | ||
* @author softphone | ||
* | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class TSType extends HashMap<String,Object> { | ||
|
||
protected TSType() { | ||
super(3); | ||
} | ||
|
||
public static TSType from( Class<?> cl, boolean export ) { | ||
return new TSType() {{ | ||
put( "value", cl); | ||
put( "export", export); | ||
}}; | ||
} | ||
|
||
public static TSType from( Class<?> cl, String alias, boolean export ) { | ||
return new TSType() {{ | ||
put( "value", cl); | ||
put( "export", export); | ||
put( "alias", alias); | ||
}}; | ||
} | ||
|
||
protected static TSType from( Class<?> cl ) { | ||
return new TSType() {{ put( "value", cl); }}; | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public Class<?> getValue() { | ||
return getClassFrom(super.get("value")); | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public boolean isExport() { | ||
return (boolean) super.getOrDefault("export", false); | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public boolean hasAlias() { | ||
final String alias = (String) super.get("alias"); | ||
return alias!=null && !alias.isEmpty(); | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public String getAlias() { | ||
return (String) super.get("alias"); | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public final String getTypeName() { | ||
return (hasAlias()) ? getAlias() : getValue().getName(); | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public final String getSimpleTypeName() { | ||
return (hasAlias()) ? getAlias() : getValue().getSimpleName(); | ||
} | ||
|
||
/** | ||
* | ||
* @param dt | ||
* @return | ||
*/ | ||
private Class<?> getClassFrom( Object dt ) { | ||
if( dt instanceof Class ) return (Class<?>)dt; | ||
|
||
try { | ||
return Class.forName(dt.toString()); | ||
} catch (ClassNotFoundException e1) { | ||
throw new RuntimeException(String.format("class not found [%s]",dt), e1); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return getValue().equals(((TSType)o).getValue()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return getValue().hashCode(); | ||
} | ||
|
||
} |
Oops, something went wrong.