开源零听小清新范儿十足的音乐播放器代码案例.docx
《开源零听小清新范儿十足的音乐播放器代码案例.docx》由会员分享,可在线阅读,更多相关《开源零听小清新范儿十足的音乐播放器代码案例.docx(27页珍藏版)》请在冰豆网上搜索。
开源零听小清新范儿十足的音乐播放器代码案例
angularbase64.jsmodule支持中文,AngularJS学习--服务ServiceAngularJS学习--服务Service
angular实现的form自动布局,算法的简单实现arduino距离传感器,arduino小车前进左右转代码,array_change_key_case:
返回字符串键名全,array_chunk:
将一个数组分解成包含多个一
[代码][Java]代码
packagetest;
importcanghailan.lang.Methods;
/**
*@authorcanghailan2012-03-1221:
53
*/
publicclassMethodLookupTest{
publicstaticvoidmain(String[]args)throwsException{
System.out.println(Methods.publicLookup().findMethod(
MethodLookupTest.class,
"x",
Object.class)
);//publicstaticvoidtest.MethodLookupTest.x(java.lang.Object)
System.out.println(Methods.publicLookup().findMethod(
MethodLookupTest.class,
"x",
int.class)
);//publicstaticvoidtest.MethodLookupTest.x(int)
System.out.println(Methods.publicLookup().findMethod(
MethodLookupTest.class,
"x",
Integer.class)
);//publicstaticvoidtest.MethodLookupTest.x(java.lang.Integer)
System.out.println(Methods.publicLookup().findMethod(
MethodLookupTest.class,
"x",
byte.class)
);//publicstaticvoidtest.MethodLookupTest.x(int)
System.out.println(Methods.publicLookup().findMethod(
MethodLookupTest.class,
"x",
Byte.class)
);//publicstaticvoidtest.MethodLookupTest.x(java.lang.Object)
System.out.println(Methods.publicLookup().findMethod(
MethodLookupTest.class,
"x",
String.class)
);//publicstaticvoidtest.MethodLookupTest.x(java.lang.Object)
}
//C语言实现有序集合intset结构
//C语言制作动态链接库.so文件
publicstaticvoidx(Objecto){}
publicstaticvoidx(into){}
publicstaticvoidx(Integero){}
}
[文件]Methods.java ~ 2KB (10)[9][10]
packagecanghailan.lang;
importjava.lang.reflect.InvocationTargetException;
importjava.lang.reflect.Method;
/**
*@authorcanghailan2012-01-1323:
06
*/
publicclassMethods{
privatestaticfinalMethodLookuppublicLookup=newMethodLookup(1024);
publicstaticMethodLookuppublicLookup(){
returnpublicLookup;
}
publicstaticObjectinvoke(Objectobject,Stringname,Object...params)
throwsNoSuchMethodException,InvocationTargetException,IllegalAccessException{
Methodmethod=publicLookup.findMethod(
object.getClass(),
name,
MethodLookup.getParameterTypes(params)
);
if(method!
=null){
returnmethod.invoke(object,params);
}
thrownewNoSuchMethodException(invokeToString(object.getClass(),name,params));
}
publicstaticObjectinvokeStatic(Class
>clazz,Stringname,Object...params)
throwsNoSuchMethodException,InvocationTargetException,IllegalAccessException{
Methodmethod=publicLookup.findMethod(
clazz,
name,
MethodLookup.getParameterTypes(params)
);
if(method!
=null){
returnmethod.invoke(null,params);
}
thrownewNoSuchMethodException(invokeToString(clazz,name,params));
}
privatestaticStringinvokeToString(Class
>clazz,Stringmethod,Object...params){
StringBuilderbuffer=newStringBuilder();
buffer.append(clazz.getName()).append('$');
buffer.append(method).append('(');
for(Objectparam:
params){
buffer.append(param).append(",");
}
buffer.setLength(buffer.length()-",".length());
buffer.append(')');
returnbuffer.toString();
}
}
[文件]Fields.java ~ 4KB (10)[9][10]
packagecanghailan.lang;
importjava.lang.reflect.Field;
importjava.lang.reflect.InvocationTargetException;
importjava.lang.reflect.Method;
importjava.lang.reflect.Modifier;
/**
*@authorcanghailan2012-01-1323:
06
*/
publicclassFields{
privatestaticfinalFieldLookuplookup=newFieldLookup(1024);
publicstaticFieldLookuplookup(){
returnlookup;
}
publicstaticObjectget(Objectobject,Stringfield)
throwsNoSuchMethodException,InvocationTargetException,IllegalAccessException{
Methodgetter=lookup.findGetter(object.getClass(),field);
if(getter!
=null){
returngetter.invoke(object);
}
thrownewNoSuchMethodException("Couldnotfindgetterfor"+object.getClass().getName()+"."+field);
}
publicstaticvoidset(Objectobject,Stringfield,Objectvalue)
throwsNoSuchMethodException,InvocationTargetException,IllegalAccessException{
StringBuilderbuffer=newStringBuilder("set".length()+field.length());
buffer.append("set").append(field)
.setCharAt("set".length(),Character.toUpperCase(field.charAt(0)));
Methods.invoke(object,buffer.toString(),value);
}
publicstaticObjectdirectGet(Objectobject,Stringname)
throwsNoSuchFieldException,IllegalAccessException{
Fieldfield=lookup.findField(object.getClass(),name);
if(field!
=null){
returndirectGet(object,field);
}
thrownewNoSuchFieldException(object.getClass().getName()+"."+name);
}
publicstaticObjectdirectGet(Objectobject,Fieldfield)
throwsIllegalAccessException{
if(field.isAccessible()){
returnfield.get(object);
}else{
field.setAccessible(true);
Objectvalue=field.get(object);
field.setAccessible(false);
returnvalue;
}
}
publicstaticvoiddirectSet(Objectobject,Stringname,Objectvalue)
throwsNoSuchFieldException,IllegalAccessException{
Fieldfield=lookup.findField(object.getClass(),name);
if(field!
=null){
directSet(object,field,value);
}
thrownewNoSuchFieldException(object.getClass().getName()+"."+name);
}
publicstaticvoiddirectSet(Objectobject,Fieldfield,Objectvalue)
throwsIllegalAccessException{
if(field.isAccessible()){
field.set(object,value);
}else{
field.setAccessible(true);
field.set(object,value);
field.setAccessible(false);
}
}
publicstaticvoidcopy(Objectsrc,Objectdst,String...fieldNames)
throwsNoSuchFieldException,IllegalAccessException,InvocationTargetException,NoSuchMethodException{
if(src.getClass().equals(dst.getClass())){
for(StringfieldName:
fieldNames){
Fieldfield=lookup.findField(src.getClass(),fieldName);
if(field==null){
thrownewNoSuchFieldException(src.getClass().getName()+"."+fieldName);
}
directSet(dst,field,directGet(src,field));
}
}else{
for(Stringname:
fieldNames){
set(dst,name,get(src,name));
}
}
}
publicstaticvoidcopy(Tsrc,Tdst)throwsIllegalAccessException{
for(Class
>clz=src.getClass();clz!
=null;clz=clz.getSuperclass()){
for(Fieldfield:
clz.getDeclaredFields()){
//skipstaticandfinalfield
if(Modifier.isStatic(field.getModifiers())||
Modifier.isFinal(field.getModifiers())){
continue;
}
directSet(dst,field,directGet(src,field));
}
}
}
}
[文件]MethodLookup.java ~ 12KB (10)[9][10]
packagecanghailan.lang;
importjava.lang.reflect.Method;
importjava.util.*;
/**
*@authorcanghailan2012-02-2320:
31
*/
publicclassMethodLookup
extendsCachedLookup
implementsMemberLookup{
publicstaticfinalClass
>[]EMPTY_CLASSES=newClass
>[0];
publicMethodLookup(Mapcache){
super(cache);
}
publicMethodLookup(finalintcacheSize){
super(cacheSize);
}
@Override
protectedMethodsInfodoFind(Identifierkey){
returnnewMethodsInfo(key.getClazz(),key.getName());
}
publicMethodfindMethod(Class
>clazz,Stringname,Class...actual){
MethodInfoaccept=null;
for(MethodInfomethodInfo:
find(newIdentifier(clazz,name)).getMethods(actual.length)){
intdiff=methodInfo.accept(actual);
if(diff==0){
returnmethodInfo.getMethod();
}
if(diff>0){
if(accept==null||methodInfo.isMorePrecise(accept)){
accept=methodInfo;
}
}
}
returnaccept==null?
null:
accept.getMethod();
}
/**
*
*
- null=>null
*
- object=>object.getClass()
*
*/
publicstaticClass
>[]getParameterTypes(Object...params){
if(params==null){
returnnull;
}
if(params.length==0){
returnEMPTY_CLASSES;
}
Class
>[]types=newClass
>[params.length];
for(inti=0;itypes[i]=params[i]==null?
null:
params[i].getClass();
}
returntypes;
}
staticclassMethodsInfo{
staticfinalMethodInfo[]EMPTY_METHODS=newMethodInfo[0];
finalMethodInfo[][]methods;
MethodsInfo(Class
>clazz,Stringname){
methods=generateMethodsInfo(clazz,name);
}
MethodInfo[][]generateMethodsInfo(Class
>clazz,Stringname){
intmaxParameterLength=0;
Map>methodsInfoMap=newHashMap<>();
for(Methodmethod:
clazz.getMethods()){
if(method.getName().equals(name)){
intparameterLength=method.getParameterTypes().length;
ListmethodInfoList=methodsInfoMap.get(parameterLength);
if(methodInfoList==null){
methodInfoList=newLinkedList<>();
methodsInfoMap.put(parameterLength,methodInfoList);
}
methodInfoList.add(newMethodInfo(method));
maxParameterLength=Math.max(maxParameterLength,parameterLength);
}
}
MethodInfo[][]methods=newMethodInfo[maxParameterLength+1][];
for(inti=0;iListmethodInfoList=methodsInfoMap.get(i);
if(methodInfoList==null||methodInfoList.size()==0){
methods[i]=EMPTY_METHODS;
}else{
methods[i]=methodInfoList.toArray(newMethodInfo[methodInfoList.size()]);
}
}
returnmethods;
}
MethodInfo[]getMethods(intparameterLength){
if(parameterLengthreturnmethods[parameterLength];
}
returnEMPTY_METHODS;
}
publicStringtoString(){
StringBuilderbuffer=newStringBuilder();
for(inti=0;ibuffer.append(i).append('\t')
.append(Arrays.toString(methods[i])).append('\n');
}
returnbuffer.toString();
}
}
staticclassMethodInfo{
finalMethodmethod;
ParameterTypesparameterTypes;//cache
MethodInfo(Methodmethod){
this.method=method;
}
MethodgetMethod(){
returnmethod;
}
ParameterTypesgetParamete