Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions group24/1148285693/learning2017/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ logs
*.bak
.directory
.DS_Store


Test.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package me.lzb.common.utils;

/**
* Created by lzbfe on 2017/4/29.
* @author LZB
*/
public class AppUtils {

/**
* 获取一个数的位数
*
* @param i
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package me.lzb.common.utils;

/**
* Created by LZB on 2017/4/14.
* @author LZB
*/
public class ByteUtils {

public static String byteToHexString(byte[] codes ){
public static String byteToHexString(byte[] codes) {
StringBuffer buffer = new StringBuffer();
for(int i=0;i<codes.length;i++){
for (int i = 0; i < codes.length; i++) {
byte b = codes[i];
int value = b & 0xFF;
String strHex = Integer.toHexString(value);
if(strHex.length()< 2){
if (strHex.length() < 2) {
strHex = "0" + strHex;
}
buffer.append(strHex);
}
return buffer.toString();
}

public static int byteToInt(byte[] codes){
public static int byteToInt(byte[] codes) {
String s1 = byteToHexString(codes);
return Integer.valueOf(s1, 16).intValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.*;

/**
* Created by LZB on 2017/4/4.
* @author LZB
*/
public class FileUtils {

Expand All @@ -26,12 +26,13 @@ public static boolean isFileExist(String f) {

/**
* 读取文件为二进制数组
*
* @param clzFileName 文件路径
* @return 数组
* @throws IOException
*/
public static byte[] readByteCodes(String clzFileName) throws IOException {
if(!isFileExist(clzFileName)){
if (!isFileExist(clzFileName)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.lzb.common.utils;

/**
* Created by LZB on 2017/4/4.
* @author LZB
*/
public class StringUtils extends org.apache.commons.lang3.StringUtils {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,58 @@

/**
* 用双向链表实现LRU算法
* @author lzb
*
* @author lzb
*/
public class LRUPageFrame {

private static class Node {
private static class Node {

Node prev;
Node next;
int pageNum;
Node prev;
Node next;
int pageNum;

Node(Node prev, Node next, int pageNum) {
this.prev = prev;
this.next = next;
Node(Node prev, Node next, int pageNum) {
this.prev = prev;
this.next = next;
this.pageNum = pageNum;
}
}
}
}

private int capacity;
private int capacity;


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


public LRUPageFrame(int capacity) {
if(capacity < 1){
public LRUPageFrame(int capacity) {
if (capacity < 1) {
// throw new Exception("capacity boom");
}
this.capacity = capacity;

}

/**
* 获取缓存中对象
*
* @param pageNum
* @return
*/
public void access(int pageNum) {
if(capacity == 1){
first = last = new Node(null, null, pageNum);
this.capacity = capacity;

}

/**
* 获取缓存中对象
*
* @param pageNum
* @return
*/
public void access(int pageNum) {
if (capacity == 1) {
first = last = new Node(null, null, pageNum);
return;
}


if(first == null){
if (first == null) {
first = last = new Node(null, null, pageNum);
return;
}

if(first.pageNum == pageNum){
if (first.pageNum == pageNum) {
return;
}

Expand All @@ -62,12 +62,12 @@ public void access(int pageNum) {
for (int i = 0; i < capacity; i++) {
size = size + 1;
//如果发现一样的,把这个挪到最前面
if(tmp.pageNum == pageNum){
if (tmp.pageNum == pageNum) {
moveToFirst(tmp);
return;
}
//链表已经循环结束,但是个数还没满,更新last
if(tmp.next == null){
if (tmp.next == null) {
last = tmp;
break;
}
Expand All @@ -80,16 +80,16 @@ public void access(int pageNum) {
addAsFirst(f);

//已经放满,更新last
if(size >= capacity){
if (size >= capacity) {
removeLastOne();
}

}
}

/**
* 删除最后一个节点
*/
private void removeLastOne(){
private void removeLastOne() {
last = last.prev;
//使GC ROOT 不可达
last.next.prev = null;
Expand All @@ -98,17 +98,18 @@ private void removeLastOne(){

/**
* 把某节点移动到最顶部
*
* @param tmp 在链表中的任意节点
*/
private void moveToFirst(Node tmp){
if(tmp == first){
return;
private void moveToFirst(Node tmp) {
if (tmp == first) {
return;
}

if (tmp.next != null){
if (tmp.next != null) {
tmp.next.prev = tmp.prev;
tmp.prev.next = tmp.next;
}else {
} else {
tmp.prev.next = null;
//当这个节点是last的时候,更新last
last = tmp.prev;
Expand All @@ -123,47 +124,49 @@ private void moveToFirst(Node tmp){

/**
* 在顶部增加一个节点
*
* @param node node
*/
private void addAsFirst(Node node){
private void addAsFirst(Node node) {
first.prev = node;
first = node;
}



/**
* ASC
*
* @return
*/
public String toString(){
StringBuilder buffer = new StringBuilder();
Node node = first;
while(node != null){
buffer.append(node.pageNum);
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();
}
node = node.next;
if (node != null) {
buffer.append(",");
}
}
return buffer.toString();
}


/**
* DESC
*
* @return
*/
public String toStringDESC(){
public String toStringDESC() {

StringBuilder buffer = new StringBuilder();
Node node = last;
while(node != null){
while (node != null) {
buffer.append(node.pageNum);

node = node.prev;
if(node != null){
if (node != null) {
buffer.append(",");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Stack;

/**
* Created by LZB on 2017/4/20.
* @author LZB
*/
public class CalUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

/**
* 中序表达式
* Created by LZB on 2017/4/15.
*
* @author LZB
*/
public class InfixExpr {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

/**
* 中序转后序
* Created by LZB on 2017/4/20.
*
* @author LZB
*/
public class InfixToPostfix {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.lzb.basic.expr;

/**
* Created by LZB on 2017/4/20.
* @author LZB
*/
public class Node {
float number;
Expand All @@ -22,7 +22,7 @@ public boolean isLevel3() {
return calLevel == 3;
}

public boolean isNumber(){
public boolean isNumber() {
return calLevel == -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

/**
* 后缀表达式
* Created by LZB on 2017/4/20.
*
* @author LZB
*/
public class PostfixExpr {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

/**
* 前缀表达式
* Created by LZB on 2017/4/20.
*
* @author LZB
*/
public class PrefixExpr {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

/**
* 简易ArrayList
* Created by LZB on 2017/3/11.
*
* @author LZB
*/
public class ArrayList implements List {

Expand Down
Loading