Skip to content

Commit

Permalink
write a line into test.file
Browse files Browse the repository at this point in the history
  • Loading branch information
huifer committed Sep 10, 2023
1 parent 0a34e5e commit 4bac17a
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/spring/cs38b80aa4-4f8f-11ee-b0ab-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.huifer.design.factory.simple;

import com.huifer.design.factory.MengNiu;
import com.huifer.design.factory.Milk;
import com.huifer.design.factory.YiLi;

/**
* <p>Title : SimpleFactory </p>
* <p>Description : 牛奶的简单工厂</p>
*
* @author huifer
* @date 2019-05-15
*/
public class SimpleFactory {

public Milk getMilk(String name) {
if ("蒙牛".equals(name)) {
return new MengNiu();
} else if ("伊利".equals(name)) {
return new YiLi();
} else {
return null;
}
}

}
25 changes: 25 additions & 0 deletions docs/spring/cs38f6bace-4f8f-11ee-b0ab-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.huifer.aop.aspects.comment;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
* 描述:
* 切面类
*
* @author huifer
* @date 2019-03-04
*/
@Aspect
@Component(value = "myAspect")
public class MyAspect {


@Before(value = "execution(* *..*.*ServiceImpl.*(..))")
public void asBefor() {
System.out.println("注解形式的前置通知");
}


}
59 changes: 59 additions & 0 deletions docs/spring/cs39351b70-4f8f-11ee-b0ab-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright 2009-2015 the original author or authors.
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.executor.result;

import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.ReflectorFactory;
import org.apache.ibatis.reflection.factory.ObjectFactory;
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;

import java.util.Map;

/**
* @author Clinton Begin
*/
public class DefaultMapResultHandler<K, V> implements ResultHandler<V> {

private final Map<K, V> mappedResults;
private final String mapKey;
private final ObjectFactory objectFactory;
private final ObjectWrapperFactory objectWrapperFactory;
private final ReflectorFactory reflectorFactory;

@SuppressWarnings("unchecked")
public DefaultMapResultHandler(String mapKey, ObjectFactory objectFactory, ObjectWrapperFactory objectWrapperFactory, ReflectorFactory reflectorFactory) {
this.objectFactory = objectFactory;
this.objectWrapperFactory = objectWrapperFactory;
this.reflectorFactory = reflectorFactory;
this.mappedResults = objectFactory.create(Map.class);
this.mapKey = mapKey;
}

@Override
public void handleResult(ResultContext<? extends V> context) {
final V value = context.getResultObject();
final MetaObject mo = MetaObject.forObject(value, objectFactory, objectWrapperFactory, reflectorFactory);
// TODO is that assignment always true?
final K key = (K) mo.getValue(mapKey);
mappedResults.put(key, value);
}

public Map<K, V> getMappedResults() {
return mappedResults;
}
}
184 changes: 184 additions & 0 deletions docs/spring/cs397306b0-4f8f-11ee-b0ab-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
package com.huifer.data.tree;

import java.util.LinkedList;
import java.util.Queue;


/**
* <p>Title : TreeTools </p>
* <p>Description : 树处理工具</p>
*
* @author huifer
* @date 2019-04-28
*/
public class TreeTools {

public static void main(String[] args) {
TreeNode<Integer> tree = new TreeNode<>(1);
tree.addLeft(2);
tree.addRight(3);
tree.leftChild.addRight(4);
tree.rightChild.addRight(5);
System.out.println("节点数量");
System.out.println(TreeTools.getTreeSize(tree));
System.out.println("树的深度");
System.out.println(TreeTools.getTreeDepth(tree));
System.out.println("前序遍历");
preOrderTravel(tree);
System.out.println("中序遍历");
inorderTraversal(tree);
System.out.println("后序遍历");
postorderTraversal(tree);
System.out.println("分层遍历");
levelTravel(tree);
System.out.println("K层节点数量");
int numForKLevel = getNumForKLevel(tree, 2);
System.out.println(numForKLevel);


TreeNode<String> T2 = new TreeNode<>("A");
T2.addLeft("B");
T2.leftChild.addLeft("D");
T2.leftChild.leftChild.addLeft("G");
T2.leftChild.leftChild.addRight("H");

T2.addRight("C");
T2.rightChild.addLeft("E");
T2.rightChild.addRight("F");
T2.rightChild.leftChild.addRight("I");
System.out.println("前序遍历");
preOrderTravel(T2);
System.out.println("中序遍历");
inorderTraversal(T2);
System.out.println("后序遍历");
postorderTraversal(T2);
System.out.println("=======================");
System.out.println("层次遍历");
levelTravel(T2);
System.out.println();
System.out.println("=======================");


TreeNode<String> t3 = new TreeNode<>("A");
t3.addLeft("B");
t3.leftChild.addLeft("C");
t3.leftChild.addRight("D");
t3.addRight("E");
t3.rightChild.addLeft("F");
t3.rightChild.addRight("G");
levelTravel(t3);

}

/**
* 获取树的节点数量
*
* @param root 根节点
* @return 节点数量
*/
public static <T> int getTreeSize(TreeNode<T> root) {
if (root == null) {
return 0;
}
return getTreeSize(root.leftChild) + getTreeSize(root.rightChild) + 1;
}

/**
* 获取树的深度
*
* @param root 根节点
* @return 深度
*/
public static <T> int getTreeDepth(TreeNode<T> root) {
if (root == null) {
return 0;
}
int leftDepth = getTreeDepth(root.leftChild) + 1;
int rightDepth = getTreeDepth(root.rightChild) + 1;
return Math.max(leftDepth, rightDepth);
}


/**
* 输出结点的数据
*
* @param node 结点
*/
private static <T> void printNodeValue(TreeNode<T> node) {
System.out.println(node.data + "\t");
}

/**
* 前序遍历,注: 中序遍历 后序遍历将print位置调整即可
*/
public static <T> void preOrderTravel(TreeNode<T> root) {
if (root == null) {
return;
}
printNodeValue(root);
preOrderTravel(root.leftChild);
preOrderTravel(root.rightChild);
}

/**
* 中序遍历,注: 中序遍历 后序遍历将print位置调整即可
*/
public static <T> void inorderTraversal(TreeNode<T> root) {
if (root == null) {
return;
}
inorderTraversal(root.leftChild);
printNodeValue(root);
inorderTraversal(root.rightChild);
}

/**
* 后序遍历,注: 中序遍历 后序遍历将print位置调整即可
*/
public static <T> void postorderTraversal(TreeNode<T> root) {
if (root == null) {
return;
}
postorderTraversal(root.leftChild);
postorderTraversal(root.rightChild);
printNodeValue(root);
}


/**
* 分层遍历
*/
public static <T> void levelTravel(TreeNode<T> root) {
Queue<TreeNode<T>> queue = new LinkedList<>();
queue.offer(root);
while (!queue.isEmpty()) {
TreeNode<T> tem = queue.poll();
printNodeValue(tem);
if (tem.leftChild != null) {
queue.offer(tem.leftChild);
}
if (tem.rightChild != null) {
queue.offer(tem.rightChild);
}
}
}

/**
* 返回k层的结点个数
*/
public static <T> int getNumForKLevel(TreeNode<T> root, int k) {
if (root == null || k < 1) {
return 0;
}
if (k == 1) {
return 1;
}

int leftNum = getNumForKLevel(root.leftChild, k - 1);
int rightNum = getNumForKLevel(root.rightChild, k - 1);

return leftNum + rightNum;
}


}
1 change: 1 addition & 0 deletions docs/spring/cs39b16022-4f8f-11ee-b0ab-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.github.huifer.full.shiro.model;
10 changes: 10 additions & 0 deletions docs/spring/cs39ef1962-4f8f-11ee-b0ab-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.huifer.utils.factory;

public class AbsTransform {
private Object value;

public Object getValue() {
return value;
}

}

0 comments on commit 4bac17a

Please sign in to comment.