2021-01-26

标题比较对象简单用法

package com.devfastmybatis.comporator;

import java.util.*;

public class a {
    public static void main(String[] args) {
        List<Map<String, String>> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        Map<String, String> map1 = new HashMap<>();
        Map<String, String> map2 = new HashMap<>();
        Map<String, String> map3 = new HashMap<>();
        map.put("name", "zhangsan");
        map.put("sortRule", "d");
        map1.put("name", "lisi");
        map1.put("sortRule", "a");
        map2.put("name", "wangwu");
        map2.put("sortRule", "b");
        map3.put("name", "wangwu");
        map3.put("sortRule", "a");
        list.add(map);
        list.add(map1);
        list.add(map2);
        list.add(map3);
        System.out.println("排序前:"+list);
        Collections.sort(list, new Comparator<Map<String, String>>() {
            @Override
            public int compare(Map<String, String> m1, Map<String, String> m2) {
                String m1Key = m1.get("sortRule");
                String m2Key = m2.get("sortRule");
                int i = m1Key.compareTo(m2Key);
                if(i>0){
                    return 1;
                }else if(i<0){
                    return -1;
                }else{
                    return 0;
                }
            }
        });
        System.out.println("排序后:"+list);
    }
}
package com.devfastmybatis.comporator;

public class GeRenInfo  implements Comparable<GeRenInfo>{

	private Integer sxny;//所属年月

	@Override
	public String toString() {
		return "sxny=" + sxny ;
	}

	public GeRenInfo() {
		super();
		// TODO Auto-generated constructor stub
	}

	public int getSxny() {
		return sxny;
	}
	public void setSxny(int sxny) {
		this.sxny = sxny;
	}


	public GeRenInfo(Integer sxny) {
		super();
		this.sxny = sxny;
	}

	@Override
	public int compareTo(GeRenInfo o) {
		int sxny01=this.sxny;
		int sxny02=o.sxny;
		int i=0;
		if(sxny01> sxny02){
			  			i=1;
		}else if(sxny01<sxny02){
			  			i=-1;
		}
		return i;

	}


}
package com.devfastmybatis.comporator;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class UnitShow {

	@Test
	public void unitShow() {
		//比较器
		Comparator comparator = new Comparator<GeRenInfo>() {
			@Override
			public int compare(GeRenInfo o1, GeRenInfo o2) {
				int sxny01 = o1.getSxny();
				int sxny02 = o2.getSxny();
				int i = 0;
				if (sxny01 > sxny02) {
					i = 1;
				} else if (sxny01 < sxny02) {
					i = -1;
				}
				return i;
			}
		};
//		GeRenInfo[] gryf = new GeRenInfo[]{
//				new GeRenInfo(201407),
//				new GeRenInfo(201410),
//				new GeRenInfo(201406),
//		};
		List<GeRenInfo> list = new ArrayList<GeRenInfo>();
		list.add(new GeRenInfo(201407));
		list.add(new GeRenInfo(201410));
		list.add(new GeRenInfo(201406));
		Collections.sort(list, comparator);//用比较器进行排序
		System.out.println(list);
	}
}

2.1

package com.devfastmybatis.comporator1;

import java.util.Objects;

public class Student implements Comparable<Student>{
private int code;
private String name;
public int getCode() {
	return code;
}
public void setCode(int code) {
	this.code = code;
}
public String getName() {
	return name;
}
public void setName(String name) {
	this.name = name;
}
public Student(int code, String name) {
	super();
	this.code = code;
	this.name = name;
}
public Student() {
	super();
	// TODO Auto-generated constructor stub
}
	@Override
	public int compareTo(Student o) {
		return (this.code>o.getCode())?1:-1;
	}
	@Override
	public String toString() {
		return "Student [code=" + code + ", name=" + name + "]";
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		Student student = (Student) o;
		return code == student.code &&
				Objects.equals(name, student.name);
	}

	@Override
	public int hashCode() {
		return Objects.hash(code, name);
	}

//	@Override
//	public int compareTo(Object o) {
//		return 0;
//	}
}

2.2

package com.devfastmybatis.comporator1;

import java.util.*;

import org.junit.Test;
import org.junit.platform.commons.util.StringUtils;

public class sortByName {

/**
 * 使用自然排序
 * Student必须实现Comparable接口,否则会抛出ClassCastException
 */
	@Test
public void testSortedSet3() {
    Student stu1 = new Student(1, "Little");
    Student stu2 = new Student(2, "Cyntin");
    Student stu3 = new Student(3, "Tony");
    Student stu4 = new Student(4, "Gemini");
//        System.out.println(Arrays.toString(new int[]{1,2,3}));
    SortedSet set = new TreeSet();
//    set.add(stu1);
    set.add(stu3); // 若Student没有实现Comparable接口,抛出ClassCastException
    set.add(stu4);
    set.add(stu2);
    set.add(stu4);
    set.add(new Student(12, "Little"));

    System.out.println(set.size());
    System.out.println(set);
}
/**
 * 使用比较器排序
 * Student可以只是个简单的Java类,不用实现Comparable接口
 */
@Test
public void testSortedSet4() {
    Student stu1 = new Student(1, "Little");
    Student stu2 = new Student(2, "Cyntin");
    Student stu3 = new Student(3, "Tony");
    Student stu4 = new Student(4, "Gemini");

    SortedSet set = new TreeSet(new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            if (o1 instanceof Student
                    && o2 instanceof Student) {
                Student s1 = (Student) o1;
                Student s2 = (Student) o2;
                return s1.getName().compareTo(s2.getName());
            }
            return 0;
        }

    });

    set.add(stu1);
    set.add(stu3);
    set.add(stu4);
    set.add(stu2);
    set.add(stu4);
    set.add(new Student(12, "Little"));

    System.out.println(set);
}
}

2021-03-26 20:54:33,596 - Model - INFO - Epoch 1 (1/200): 2021-03-26 20:57:40,380 - Model - INFO - Train Instance Accuracy: 0.571037 2021-03-26 20:58:16,623 - Model - INFO - Test Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Best Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Save model... 2021-03-26 20:58:16,623 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 20:58:16,698 - Model - INFO - Epoch 2 (2/200): 2021-03-26 21:01:26,685 - Model - INFO - Train Instance Accuracy: 0.727947 2021-03-26 21:02:03,642 - Model - INFO - Test Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Best Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Save model... 2021-03-26 21:02:03,643 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 21:02:03,746 - Model - INFO - Epoch 3 (3/200): 2021-03-26 21:05:15,349 - Model - INFO - Train Instance Accuracy: 0.781606 2021-03-26 21:05:51,538 - Model - INFO - Test Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,538 - Model - INFO - Best Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,539 - Model - INFO - Save model... 2021-03-26 21:05:51,539 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 我有类似于这样的一段txt文件,请你帮我写一段代码来可视化这些训练结果
02-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值