diff --git a/docs/spring/cs4b476e90-89a4-11ee-9a0f-acde48001122.java b/docs/spring/cs4b476e90-89a4-11ee-9a0f-acde48001122.java new file mode 100644 index 00000000..923695ef --- /dev/null +++ b/docs/spring/cs4b476e90-89a4-11ee-9a0f-acde48001122.java @@ -0,0 +1,24 @@ +/** + * Copyright 2009-2015 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ibatis.parsing; + +/** + * @author Clinton Begin + */ +public interface TokenHandler { + String handleToken(String content); +} + diff --git a/docs/spring/cs4b6e69fa-89a4-11ee-9a0f-acde48001122.java b/docs/spring/cs4b6e69fa-89a4-11ee-9a0f-acde48001122.java new file mode 100644 index 00000000..e9e11a7b --- /dev/null +++ b/docs/spring/cs4b6e69fa-89a4-11ee-9a0f-acde48001122.java @@ -0,0 +1,65 @@ +package com.huifer.data.queue; + +/** + *

Title : RoundRobinQueue

+ *

Description : 循环队列

+ * + * @author huifer + * @date 2019-04-22 + */ +public class RoundRobinQueue { + + private Object[] queue; + private int queueSize; + // 头指针 + private int front; + // 尾指针 + private int rear; + + + public RoundRobinQueue(int queueSize) { + this.queueSize = queueSize; + this.front = 0; + this.rear = 0; + this.queue = new Object[queueSize]; + } + + public static void main(String[] args) { + RoundRobinQueue r = new RoundRobinQueue(3); + r.enqueue("元素1"); + r.enqueue("元素2"); + // 队列满 + r.enqueue("元素3"); + Object dequeue = r.dequeue(); + System.out.println(dequeue.equals("元素1")); + } + + + /** + * 是否满队列 + */ + public boolean isFull() { + return (rear + 1) % queue.length == front; + } + + public boolean enqueue(Object obj) { + if (isFull()) { + return false; + } + queue[rear] = obj; + rear = (rear + 1) % queue.length; + return true; + } + + + public Object dequeue() { + if (rear == front) { + return null; + } + Object obj = queue[front]; + front = (front + 1) % queue.length; + return obj; + } + + +} diff --git a/docs/spring/cs4b954cd2-89a4-11ee-9a0f-acde48001122.java b/docs/spring/cs4b954cd2-89a4-11ee-9a0f-acde48001122.java new file mode 100644 index 00000000..e756d708 --- /dev/null +++ b/docs/spring/cs4b954cd2-89a4-11ee-9a0f-acde48001122.java @@ -0,0 +1,70 @@ +package com.huifer.idgen.my.service.conv; + +import com.huifer.idgen.my.service.bean.Id; +import com.huifer.idgen.my.service.bean.IdMeta; +import com.huifer.idgen.my.service.bean.enums.IdType; +import com.huifer.idgen.my.service.factory.IdMetaFactory; + +/** + * @author: wang + * @description: + */ +public class IdConverterImpl implements IdConverter { + + private IdMeta idMeta; + + public IdConverterImpl(IdType idType) { + this(IdMetaFactory.getIdMeta(idType)); + } + + public IdConverterImpl(IdMeta idMeta) { + this.idMeta = idMeta; + } + + + @Override + public long converter(Id id) { + return doConverter(id, this.idMeta); + } + + @Override + public Id converter(long id) { + return doConvert(id, idMeta); + } + + /** + * 根据id生产,根据id元数据生产一个long类型的id + * + * @param id + * @param idMeta + * @return + */ + protected long doConverter(Id id, IdMeta idMeta) { + long res = 0; + res |= id.getMachine(); + res |= id.getSeq() << idMeta.getMachineBits(); + res |= id.getTime() << idMeta.getTimeBitsStartPos(); + res |= id.getGenMethod() << idMeta.getGenMethodBitsStartPos(); + res |= id.getType() << idMeta.getTypeBitsStartPos(); + res |= id.getVersion() << idMeta.getVersionBitsStartPos(); + return res; + } + + /** + * 根据long类型id,根据id元数据返回这个id的意义 + * + * @param id + * @param idMeta + * @return + */ + protected Id doConvert(long id, IdMeta idMeta) { + Id res = new Id(); + res.setMachine(id & idMeta.getMachineBitsMask()); + res.setSeq((id >>> idMeta.getMachineBits()) & idMeta.getSeqBitsMask()); + res.setTime((id >>> idMeta.getTimeBitsStartPos()) & idMeta.getTimeBitsMask()); + res.setGenMethod((id >>> idMeta.getGenMethodBitsStartPos()) & idMeta.getGenMethodBitsMask()); + res.setType((id >>> idMeta.getTypeBitsStartPos()) & idMeta.getTypeBitsMask()); + res.setVersion((id >>> idMeta.getVersionBitsStartPos()) & idMeta.getVersionBitsMask()); + return res; + } +} \ No newline at end of file diff --git a/docs/spring/cs4bcacb5a-89a4-11ee-9a0f-acde48001122.java b/docs/spring/cs4bcacb5a-89a4-11ee-9a0f-acde48001122.java new file mode 100644 index 00000000..922ec56a --- /dev/null +++ b/docs/spring/cs4bcacb5a-89a4-11ee-9a0f-acde48001122.java @@ -0,0 +1,12 @@ +package com.huifer.design.singleton.nw; + + +public class SimpleSingletonTest { + public static void main(String[] args) { + Thread t1 = new Thread(new ExecutorThread()); + Thread t2 = new Thread(new ExecutorThread()); + t1.start(); + t2.start(); + System.out.println("结束"); + } +} \ No newline at end of file diff --git a/docs/spring/cs4bf4ae70-89a4-11ee-9a0f-acde48001122.java b/docs/spring/cs4bf4ae70-89a4-11ee-9a0f-acde48001122.java new file mode 100644 index 00000000..96a1f336 --- /dev/null +++ b/docs/spring/cs4bf4ae70-89a4-11ee-9a0f-acde48001122.java @@ -0,0 +1,35 @@ +package com.huifer.design.proxy.cglib; + +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +import java.lang.reflect.Method; + +/** + *

Title : CGLIBZhiLian

+ *

Description :

+ * + * @author huifer + * @date 2019-05-17 + */ +public class CGLIBZhiLian { + + public Object getInstance(Class clazz) throws Exception { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(clazz); + + enhancer.setCallback(new MethodInterceptor() { + @Override + public Object intercept(Object o, Method method, Object[] args, + MethodProxy methodProxy) throws Throwable { + System.out.println("CGLIB 代理智联"); + Object o1 = methodProxy.invokeSuper(o, args); + return o1; + } + }); + + return enhancer.create(); + + } +}