Skip to content

Instantly share code, notes, and snippets.

View tylertreat's full-sized avatar

Tyler Treat tylertreat

View GitHub Profile
public class FooEntity {
private ValueHolder relatedEntity;
public BarEntity getRelatedEntity() {
return (BarEntity) relatedEntity.getValue();
}
}
public class FooEntity {
enum Status { GHOST, LOADING, LOADED };
private Status status;
private long id;
private BarEntity relatedEntity;
public FooEntity(long id) {
this.id = id;
public class FooEntity {
private BarEntity relatedEntity;
public BarEntity getRelatedEntity() {
if (relatedEntity == null)
relatedEntity = new BarEntity(); // Alternatively, this might be a database call
return relatedEntity;
}
private void addChildContexts(XmlApplicationContext parent) {
for (Module module : Module.values()) {
if (ModuleUtils.hasModule(module))
parent.addChildContext(module.initialize(parent));
}
}
public enum Module {
ORM(ORM_MARKER_CLASS, ORM_CONTEXT_CLASS),
AOP(AOP_MARKER_CLASS, AOP_CONTEXT_CLASS),
WEB(WEB_MARKER_CLASS, WEB_CONTEXT_CLASS);
// ...
public InfinitumContext initialize(InfinitumContext parent) {
try {
public static boolean hasModule(Module module) {
return hasClass(module.getMarkerClass());
}
private static boolean hasClass(String name) {
try {
Thread.currentThread().getContextClassLoader().loadClass(name);
return true;
} catch (ClassNotFoundException e) {
return false;
$ find . -name "*.java" -print0 | xargs -0 sed -i -e '/This file is part of Infinitum Framework./,/along with Infinitum Framework/c\
* 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.\
$ sed -i -e '/Replace everything from this line/,/To this line/c\
With this line' file.txt
$ find . -name "*.java" -print0 | xargs -0 sed -i 's/foo/bar/g'
/*
* Copyright (c) 2012 Tyler Treat
*
* 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