开源零听小清新范儿十足的音乐播放器代码案例Word格式.docx
《开源零听小清新范儿十足的音乐播放器代码案例Word格式.docx》由会员分享,可在线阅读,更多相关《开源零听小清新范儿十足的音乐播放器代码案例Word格式.docx(27页珍藏版)》请在冰点文库上搜索。
![开源零听小清新范儿十足的音乐播放器代码案例Word格式.docx](https://file1.bingdoc.com/fileroot1/2023-5/10/d0719971-2d43-4431-816a-e025c9d42713/d0719971-2d43-4431-816a-e025c9d427131.gif)
byte.class)
Byte.class)
String.class)
}
//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)
clazz,
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
importjava.lang.reflect.Field;
importjava.lang.reflect.Modifier;
publicclassFields{
privatestaticfinalFieldLookuplookup=newFieldLookup(1024);
publicstaticFieldLookuplookup(){
returnlookup;
publicstaticObjectget(Objectobject,Stringfield)
Methodgetter=lookup.findGetter(object.getClass(),field);
if(getter!
returngetter.invoke(object);
thrownewNoSuchMethodException("
Couldnotfindgetterfor"
+object.getClass().getName()+"
."
+field);
publicstaticvoidset(Objectobject,Stringfield,Objectvalue)
StringBuilderbuffer=newStringBuilder("
set"
.length()+field.length());
buffer.append("
).append(field)
.setCharAt("
.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!
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)
directSet(object,field,value);
publicstaticvoiddirectSet(Objectobject,Fieldfield,Objectvalue)
field.set(object,value);
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));
for(Stringname:
set(dst,name,get(src,name));
publicstatic<
T>
voidcopy(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;
[文件]MethodLookup.java
12KB
importjava.util.*;
*@authorcanghailan2012-02-2320:
31
publicclassMethodLookup
extendsCachedLookup<
MemberLookup.Identifier,MethodLookup.MethodsInfo>
implementsMemberLookup{
publicstaticfinalClass<
[]EMPTY_CLASSES=newClass<
[0];
publicMethodLookup(Map<
Identifier,MethodsInfo>
cache){
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();
/**
*<
ul>
li>
null=>
null<
/li>
object=>
object.getClass()<
/ul>
publicstaticClass<
[]getParameterTypes(Object...params){
if(params==null){
returnnull;
if(params.length==0){
returnEMPTY_CLASSES;
Class<
[]types=newClass<
[params.length];
for(inti=0;
i<
params.length;
++i){
types[i]=params[i]==null?
params[i].getClass();
returntypes;
staticclassMethodsInfo{
staticfinalMethodInfo[]EMPTY_METHODS=newMethodInfo[0];
finalMethodInfo[][]methods;
MethodsInfo(Class<
clazz,Stringname){
methods=generateMethodsInfo(clazz,name);
MethodInfo[][]generateMethodsInfo(Class<
intmaxParameterLength=0;
Map<
Integer,List<
MethodInfo>
methodsInfoMap=newHashMap<
();
for(Methodmethod:
clazz.getMethods()){
if(method.getName().equals(name)){
intparameterLength=method.getParameterTypes().length;
List<
methodInfoList=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][];
methods.length;
methodInfoList=methodsInfoMap.get(i);
if(methodInfoList==null||methodInfoList.size()==0){
methods[i]=EMPTY_METHODS;
methods[i]=methodInfoList.toArray(newMethodInfo[methodInfoList.size()]);
returnmethods;
MethodInfo[]getMethods(intparameterLength){
if(parameterLength<
methods.length){
returnmethods[parameterLength];
returnEMPTY_METHODS;
publicStringtoString(){
buffer.append(i).append('
\t'
)
.append(Arrays.toString(methods[i])).append('
\n'
staticclassMethodInfo{
finalMethodmethod;
ParameterTypesparameterTypes;
//cache
MethodInfo(Methodmethod){
this.method=method;
MethodgetMethod(){
returnmethod;
ParameterTypesgetParamete