For memorandum.
Java
DeepCopy DeepCopy by java.util.Arrays
int[] copySrc = new int[5];
Arrays.fill(copySrc, 0);
int[] copyDst = Arrays.copyOf(copySrc, copySrc.length);
DeepCopy by org.apache.commons.lang3.SerializationUtils # clone
public Object deepCopy(Serializable state) {
return SerializationUtils.clone(state);
}
I don't know how to use it effectively. It seems to be useful for solving AtCoder Regular Contest 028 --B --Special Award.
PriorityQueue<Integer> pQueue = new PriorityQueue<Integer>();
pQueue.offer(i); //add to
pQueue.peek(i); //Get (do not remove from queue)
pQueue.poll(i); //Get (remove from queue)
// commons-lang
System.out.println(ToStringBuilder.reflectionToString(new Hoge()));
// hoge$Hoge@cafb56[id=1,value=hoge,strValues={aaa,bbb,ccc},items=[ddd, eee, fff]]
public class Clazz implements Serializable {
private static final long serialVersionUID = 1L;
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}
public class Hoge implements Serializable {
private static final long serialVersionUID = 1L;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
}
Use Enum. That's right ~
if ( Arrays.asList("Cat", "Dog", "Pig").contains(hoge) ) {
// Do somthings.
}
List<String> list = new ArrayList<>(Arrays.asList("Cat", "Dog", "Pig"));
//File name sort in ascending order
List<File> csvFileList = new ArrayList<File>();
csvFileList.add( new File("###") );
csvFileList.add( new File("BBB") );
csvFileList.add( new File("111") );
csvFileList.add( new File("AAA") );
Collections.sort( csvFileList, new Comparator<File>(){
@Override
public int compare( File o1, File o2 ) {
return StringUtils.compare( o1.getName(), o2.getName() );
}
});
IterableUtils.forEach( csvFileList, new Closure<File>(){
@Override
public void execute( File file ) {
System.out.println( ReflectionToStringBuilder.toString( file ) );
}
});
Spring
@Autowired
ResourceLoader resourceLoader;
final Resource resource = resourceLoader.getResource("classpath:path/to/file");
Recommended Posts