Skip to content

Commit

Permalink
Merge pull request #56 from cmhello88/master
Browse files Browse the repository at this point in the history
删掉多余的test文件
  • Loading branch information
nusubmarine01 authored May 8, 2017
2 parents 92577e9 + 71d5050 commit f7162ba
Show file tree
Hide file tree
Showing 45 changed files with 2,308 additions and 2 deletions.
4 changes: 2 additions & 2 deletions group03/345943980/download-0335/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.coderising.jvm.loader;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

public class ClassFileLoader {

private List<String> clzPaths = new ArrayList<String>();

public byte[] readBinaryCode(String className) {
className = className.replace(".", File.separator) + ".class";
for (String path : clzPaths) {
String clzFileName = path + File.separator + className;
byte[] codes = this.loadClassFile(clzFileName);
if (codes != null) {
return codes;
}
}
return null;
}

private byte[] loadClassFile(String clzFileName){
try {
return IOUtils.toByteArray(new FileInputStream(clzFileName));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

public void addClassPath(String path) {
clzPaths.add(path);
}

public String getClassPath() {
return StringUtils.join(clzPaths, ";");
}

public String getClassPath_V1() {
StringBuffer sb = new StringBuffer();
/*
* for (int i = 0; i < clzPaths.size(); i++)
{
if (i == clzPaths.size() - 1) {
sb.append(clzPaths.get(i));
break;
}
sb.append(clzPaths.get(i));
sb.append(";");
*
* }
*/
for (int i = 0; i < clzPaths.size(); i++) {
sb.append(clzPaths.get(i));
if (i < clzPaths.size() - 1) {
sb.append(";");
}
}
return sb.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.coding.basic.linklist;

/**
*
* @author chenming E-mail:[email protected]
* @version 创建时间:2017年4月10日 上午12:35:03
*/
public class CmLRUPageFrame {

private static class Node {
Node prev;
Node next;
int pageNum;

Node() {
}
}

private int capacity;

private Node first;// 链表头
private Node last;// 链表尾

public CmLRUPageFrame(int capacity) {
this.capacity = capacity;

}

/**
* 获取缓存中对象
*
* @param pageNum
*/
public void access(int pageNum) {
Node node = first;
Node foundNode = null;
while(node!=null){
if(node.pageNum==pageNum){
foundNode = node;
}
node = node.next;
}

//在该队列中存在, 则提到队列头
if(foundNode!=null){

}else{

}



}

@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
Node node = first;
while (node != null) {
buffer.append(node.pageNum);
node = node.next;
if (node != null) {
buffer.append(";");
}
}
return buffer.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package com.coding.basic.linklist;


/**
* 实现一个简单的LRU算法,即是 Least Recently Used 近期最少使用算法
* 作用:需要维护一个页面中的栈,并且需要把某一个页面从栈中提到栈顶,用硬件实现的话,开销比较大,注意:实际上并不是一个真正的栈
* @author Administrator
*
*/
public class LRUPageFrame {

private static class Node {

Node prev;
Node next;
int pageNum;

Node() {
}
}

private int capacity;

private int currentSize;
private Node first;// 链表头
private Node last;// 链表尾


public LRUPageFrame(int capacity) {
this.currentSize = 0;
this.capacity = capacity;

}

/**
* 获取缓存中对象
*
* @param key
* @return
*/
public void access(int pageNum) {

Node node = find(pageNum);
//在该队列中存在, 则提到队列头
if (node != null) {

moveExistingNodeToHead(node);

} else{

node = new Node();
node.pageNum = pageNum;

// 缓存容器是否已经超过大小.
if (currentSize >= capacity) {
removeLast();

}

addNewNodetoHead(node);




}
}

private void addNewNodetoHead(Node node) {

if(isEmpty()){

node.prev = null;
node.next = null;
first = node;
last = node;

} else{
node.prev = null;
node.next = first;
first.prev = node;
first = node;
}
this.currentSize ++;
}

private Node find(int data){

Node node = first;
while(node != null){
if(node.pageNum == data){
return node;
}
node = node.next;
}
return null;

}


/**
* 删除链表尾部节点 表示 删除最少使用的缓存对象
*/
private void removeLast() {
Node prev = last.prev;
prev.next = null;
last.prev = null;
last = prev;
this.currentSize --;
}

/**
* 移动到链表头,表示这个节点是最新使用过的
*
* @param node
*/
private void moveExistingNodeToHead(Node node) {

if (node == first) {

return;
}
else if(node == last){
//当前节点是链表尾, 需要放到链表头
Node prevNode = node.prev;
prevNode.next = null;
last.prev = null;
last = prevNode;

} else{
//node 在链表的中间, 把node 的前后节点连接起来
Node prevNode = node.prev;
prevNode.next = node.next;

Node nextNode = node.next;
nextNode.prev = prevNode;


}

node.prev = null;
node.next = first;
first.prev = node;
first = node;

}
private boolean isEmpty(){
return (first == null) && (last == null);
}

public String toString(){
StringBuilder buffer = new StringBuilder();
Node node = first;
while(node != null){
buffer.append(node.pageNum);

node = node.next;
if(node != null){
buffer.append(",");
}
}
return buffer.toString();
}
}
Loading

0 comments on commit f7162ba

Please sign in to comment.