id
stringlengths
36
36
text
stringlengths
1
1.25M
413e96d2-aa66-4179-a6d4-27ba8793c435
public class Wensleydale extends BaseCheese { String wensleydaleName() { return "This is wensleydale"; } }
53a0257c-fec6-45de-aaee-17127780ed0d
public interface Cheese { void accept(Visitor v) throws Exception; }
c26fb64b-bd15-4329-bb0f-c234fbb2684b
public void accept(Visitor v) throws Exception { v.visit(this); }
1d260097-228a-4868-b02d-b6df733dd2c0
public static void main(String[] args) throws Exception { Cheese cheese1 = new Wensleydale(); Cheese cheese2 = new Gouda(); Cheese cheese3 = new Brie(); Cheese cheese4 = new Gorgonzola(); Cheese cheese5 = new SomeOtherCheese(); Visitor v = new VisitorImpl(); cheese1.accept(v); cheese2.accept(v); cheese3.accept(v); cheese4.accept(v); cheese5.accept(v); }
74b57093-57fd-4528-ba42-4a3208f404e4
public interface AnotherCheese extends Cheese { String otherCheeseName(); }
388534ed-20ce-4523-a030-d84049550b74
public String otherCheeseName() { return "Different cheese "; }
ec33b15f-32b0-44d2-b0e1-0f742d37a08f
public class Gouda extends BaseCheese { String goudaName() { return "This is gouda"; } }
2c5295c6-54a5-4c94-b888-7ae26567242b
public Md5AvatarGenerator() { super( Hashing.md5() ); }
9c2efa1d-0a24-4c03-b155-1eb0a67ea81b
public BufferedImage generate( final String seed, final int size ) throws IOException;
b3c1d5ca-6d99-4ee5-b7b8-e00e9970765e
public HashAvatarGenerator( final HashFunction hashFunction ) { this.hashFunction = hashFunction; }
44760ca8-07fe-4469-a95d-6a78c29ab86b
@Override public final BufferedImage generate( final String seed, final int size ) throws IOException { final HashCode hashCode = this.hashFunction.hashString( seed ); return generate( hashCode, size ); }
bead3a5d-77cc-413e-bc89-14a99eb60134
protected abstract BufferedImage generate( HashCode hash, int size ) throws IOException;
5944e464-3592-44a7-9f1e-70d4e2677ec2
public static void main( String... args ) throws Exception { final int width = 80 * 19; final int height = 80 * 7; final BufferedImage image = new BufferedImage( width, height, BufferedImage.TYPE_4BYTE_ABGR ); final Graphics2D g = image.createGraphics(); combine( g, 0, loadAll( "fade", 4 ) ); combine( g, 80, loadAll( "mask", 11 ) ); combine( g, 2 * 80, loadAll( "shine", 11 ) ); combine( g, 3 * 80, loadAll( "brow", 8 ) ); combine( g, 4 * 80, loadAll( "eyes", 13 ) ); combine( g, 5 * 80, loadAll( "pupils", 11 ) ); combine( g, 6 * 80, loadAll( "mouth", 19 ) ); ImageIO.write( image, "png", new File( "./wavatar.png" ) ); }
9bf89c35-e3c1-460a-9894-d518ae4ffaa1
private static void combine( final Graphics2D g, final int y, final BufferedImage[] images ) throws Exception { for ( int i = 0; i < images.length; i++ ) { g.drawImage( images[i], null, i * 80, y ); } }
c64a0a30-dc87-4946-aeb8-af6dd02f7c14
private static BufferedImage[] loadAll( final String base, final int maxNum ) throws Exception { final BufferedImage[] list = new BufferedImage[maxNum]; for ( int i = 0; i < maxNum; i++ ) { list[i] = loadSingle( base, i + 1 ); } return list; }
b3c4f0e8-0a94-4d04-b1a1-dbb3798db36d
private static BufferedImage loadSingle( final String base, final int num ) throws Exception { final String name = String.format( base + "%d.png", num ); final File file = new File( "/Users/srs/development/workspace/identicon/monsterid/wavatars/parts/" + name ); System.out.println(file); return ImageIO.read( file ); }
e7dde92c-ac49-4592-ba5f-4a96ee2fcf4d
public WavatarGenerator() throws IOException { this.stencilImage = loadImage( "wavatar.png" ); }
00ea1942-5c79-48e5-b4c0-50439cbb2ff3
@Override protected BufferedImage generate( final HashCode hash, final int size ) throws IOException { return generate( hash.asBytes() ); }
27c5c19c-f365-4d99-8b2c-6c3435d9c2c1
protected BufferedImage generate( final byte[] hash ) throws IOException { final BufferedImage image = new BufferedImage( IMG_SIZE, IMG_SIZE, BufferedImage.TYPE_4BYTE_ABGR ); final Graphics2D graphics = image.createGraphics(); applyPart( graphics, 0, ( hash[0] & 0x8f ), 4 ); applyPart( graphics, 1, ( hash[1] & 0x8f ), 11 ); applyPart( graphics, 2, ( hash[2] & 0x8f ), 11 ); applyPart( graphics, 3, ( hash[3] & 0x8f ), 8 ); applyPart( graphics, 4, ( hash[4] & 0x8f ), 13 ); applyPart( graphics, 5, ( hash[5] & 0x8f ), 11 ); applyPart( graphics, 6, ( hash[6] & 0x8f ), 19 ); // TODO: We need to colorize the wavatars. return image; }
61520ed7-3dc7-41e1-a2ab-24d0df7e9b3e
private void applyPart( final Graphics2D graphics, final int partRow, final int hash, final int maxNum ) throws IOException { final int num = hash % maxNum; final BufferedImage overlay = getImagePart( partRow, num ); graphics.drawImage( overlay, null, 0, 0 ); }
492779ab-262a-41e7-a2fa-4ac6902b7d3d
private BufferedImage getImagePart( final int row, final int column ) throws IOException { return this.stencilImage.getSubimage( column * IMG_SIZE, row * IMG_SIZE, IMG_SIZE, IMG_SIZE ); }
eff30112-7411-447a-8f23-060d5170b99f
private BufferedImage loadImage( final String name ) throws IOException { final URL url = getClass().getResource( name ); return ImageIO.read( url ); }
d0de1e4a-e61a-4136-968f-b1240e7eeecd
public static void main( String... args ) throws Exception { ImageIO.write( new WavatarGenerator().generate( "[email protected]", 80 ), "png", new File( "./test.png" ) ); }
d35bc2a4-8c24-4ccb-a2b6-f349acc59d53
public MonsterGenerator( final boolean artistic ) throws IOException { this.artistic = artistic; if ( artistic ) { this.stencilImage = loadImage( "artistic.png" ); } else { this.stencilImage = loadImage( "simple.png" ); } }
f1652404-d406-479f-af54-4ae5af2a2adf
@Override protected BufferedImage generate( final HashCode hash, final int size ) throws IOException { return generate( hash.asBytes() ); }
be7a8203-f1a3-46fd-9ff5-2885e25a543e
protected BufferedImage generate( final byte[] hash ) throws IOException { final BufferedImage image = new BufferedImage( IMG_SIZE, IMG_SIZE, BufferedImage.TYPE_4BYTE_ABGR ); final Graphics2D graphics = image.createGraphics(); applyPart( graphics, 0, ( hash[0] & 0x8f ), 14 ); applyPart( graphics, 1, ( hash[1] & 0x8f ), 18 ); applyPart( graphics, 2, ( hash[2] & 0x8f ), 20 ); applyPart( graphics, 3, ( hash[3] & 0x8f ), 20 ); applyPart( graphics, 4, ( hash[4] & 0x8f ), 17 ); applyPart( graphics, 5, ( hash[5] & 0x8f ), 12 ); // TODO: We need to colorize the monsters when in artistic mode. return image; }
58892f46-7561-47be-8c2d-7fc92251e5d7
private void applyPart( final Graphics2D graphics, final int partRow, final int hash, final int maxNum ) throws IOException { final int num = hash % maxNum; final BufferedImage overlay = getImagePart( partRow, num ); graphics.drawImage( overlay, null, 0, 0 ); }
eb098f71-c451-4a9b-a7ff-653fd754fbe7
private BufferedImage getImagePart( final int row, final int column ) throws IOException { return this.stencilImage.getSubimage( column * IMG_SIZE, row * IMG_SIZE, IMG_SIZE, IMG_SIZE ); }
8f66b09f-8d6f-4aa6-bb89-6b7d144e1f35
private BufferedImage loadImage( final String name ) throws IOException { final URL url = getClass().getResource( name ); return ImageIO.read( url ); }
0e0aa34d-8358-4a1d-8548-44a97fb920dd
Serializable getId();
7b416217-5c70-4bf9-b43b-cc3e4527e1a3
Long count(Class<? extends Persistable> clazz);
dc564c1b-8ddf-43a2-9022-f6e37448d172
void delete(Persistable entity);
fba9f736-c2d3-43c4-981d-5376d0100621
void delete(Serializable id, Class<? extends Persistable> clazz);
ab7a1a74-6e2d-438e-915f-8b6b97f08e14
<E extends Persistable> List<E> findByExample(E exampleInstance, String[] includeProperties, PagingOrdering paging, Class<E> clazz);
57326a87-7250-4902-ab01-cdb080f285fc
<E extends Persistable> E findByNaturalKey(Object naturalKey, Class<E> clazz);
c2d414c3-b547-47f2-892d-094eef774d8a
<E extends Persistable> E findByPrimaryKey(Serializable id, Class<E> clazz);
e313e06c-5839-455e-adb1-d2a2f62ee74c
<E extends Persistable> List<E> findByProperty(String property, Object value, PagingOrdering paging, Class<E> clazz);
3bd01dc2-2277-4a09-bec3-d17717fd764c
<E extends Persistable> List<E> getAll(Class<E> clazz);
a34a5d89-a8b1-4b2e-abad-7bb38e49e575
<E extends Persistable> List<E> getPaginated(PagingOrdering paging, Class<E> clazz);
b39892d2-bf73-496c-ad7d-7bb86f1458db
boolean isPersistent(Serializable id, Class<? extends Persistable> clazz);
f524f4e8-da87-4820-a084-47ab78552faf
<E extends Persistable> E load(Serializable id, Class<E> clazz);
064c5604-6e5f-4ef3-8bb4-d08633edfa08
Serializable save(Persistable entity);
21ac6636-3520-4885-9a44-f7bc2d88e9dc
void saveOrUpdate(Persistable entity);
6a4957cd-6a05-4268-9b80-2b8dcb116a75
void update(Persistable entity);
3437adf0-afb5-475f-81f8-c0927be0958b
public OrderBy(String propertyName, boolean ascending) { this.propertyName = propertyName; this.ascending = ascending; }
6e2e7b11-b4d9-4144-a849-28f45ee449fb
public static OrderBy asc(String propertyName) { return new OrderBy(propertyName, OrderBy.ASC); }
6064445b-e6af-4434-8e65-1f08a9c2c525
public static OrderBy desc(String propertyName) { return new OrderBy(propertyName, OrderBy.DESC); }
0d561e96-d592-4a27-853e-9704b4027027
public boolean isAscending() { return ascending; }
5d9f2e30-a019-49bf-8a7a-23ee16487416
public String getPropertyName() { return propertyName; }
d99e46ae-3af9-409f-9c67-133bb5457437
@Override public String toString() { return propertyName + ' ' + (ascending ? "asc" : "desc"); }
180b6397-c3c4-48cb-8d33-71b873522e23
@Override public boolean equals(Object obj) { if (obj == null) return false; if (getClass() != obj.getClass()) return false; final OrderBy other = (OrderBy) obj; return new EqualsBuilder() .append(propertyName, other.propertyName) .append(ascending, other.ascending) .isEquals(); }
08536cb7-b4df-4f7c-8d97-d8bedb093c7f
@Override public int hashCode() { return new HashCodeBuilder(5, 83).append(propertyName).append(ascending).toHashCode(); }
09a3c5c1-9315-471b-b840-f3f61da4f518
boolean containsDAO(Class<? extends Persistable> entityClass);
f544590e-1f5e-45a5-8a05-4fb6bbd49e27
DAO getDAO(Class<? extends Persistable> entityClass);
65ab5bb8-e66d-4ebf-8728-2633be25c898
void register(DAO specificDAO);
cf67ba8d-5f96-40e2-bb2c-f53bce48023a
public PagingOrdering() { }
e1ce0ed3-254f-428a-a5e6-01e39c2d24b7
public PagingOrdering(int limit, int offset) { this.limit = limit; this.offset = offset; }
9600b027-9753-4eb5-9fdb-7d58f191a525
public PagingOrdering(int limit, int offset, OrderBy order) { this(limit, offset); ordering.add(order); }
d5c76ce7-9410-4daf-874f-f92f2f61012e
public PagingOrdering(int limit, int offset, List<OrderBy> ordering) { this.limit = limit; this.offset = offset; this.ordering = ordering; }
57c99cc3-5250-46b6-bdca-bbbf0e25737e
public PagingOrdering limit(int limit) { this.limit = limit; return this; }
4cbb4d55-0f2a-4200-9a16-64892b349b67
public PagingOrdering offset(int offset) { this.offset = offset; return this; }
2f9b3082-c050-46f2-bd71-da7e8ca2b80a
public PagingOrdering orderBy(String propertyName) { ordering.add(new OrderBy(propertyName, OrderBy.ASC)); return this; }
27ac73e7-e750-478d-a7d8-da0937b01e00
public PagingOrdering orderBy(String propertyName, boolean ascending) { ordering.add(new OrderBy(propertyName, ascending)); return this; }
26a0e1a8-a0a0-46c2-9ed9-c18cb1074ac4
public int getLimit() { return limit; }
b86e6c30-8c01-4acb-9eb1-e73b34973567
public void setLimit(int limit) { this.limit = limit; }
70b2b80d-3e60-42ba-9a91-874df111082e
public int getOffset() { return offset; }
d6062603-fbf9-448a-88fb-30aca2c38ef4
public void setOffset(int offset) { this.offset = offset; }
96d79ab2-4de3-4a0e-a0ea-0eb2390555db
public void addOrderBy(OrderBy orderBy) { ordering.add(orderBy); }
a1716a07-437d-4d15-9e49-ab1ad0cf25ce
public List<OrderBy> getOrdering() { return ordering; }
259c23ed-e845-4bcd-a6bc-9b2c6ec52dfe
public boolean hasOrdering() { return !ordering.isEmpty(); }
8ddf476c-65b2-4478-b8a1-9516b045eb34
@Override public boolean equals(Object obj) { if (obj == null) return false; if (getClass() != obj.getClass()) return false; final PagingOrdering other = (PagingOrdering) obj; return new EqualsBuilder() .append(limit, other.limit) .append(offset, other.offset) .append(ordering, other.ordering) .isEquals(); }
28a0fcf5-504e-4853-8ff7-17f85c470ddc
@Override public int hashCode() { return new HashCodeBuilder(7, 17) .append(limit) .append(offset) .append(ordering) .toHashCode(); }
d5b4ddbd-210d-40cc-afe4-3bc3901aadcf
Long count();
b134e75d-5e6a-4b4e-b090-667cda244496
void delete(E entity);
5fc62ea3-8709-440c-946a-3ca53a8d3fe0
void delete(ID id);
6bc74b0e-9b9d-458d-a940-a7603c7b213f
List<E> findByExample(E exampleInstance, String[] includeProperties, PagingOrdering paging);
26f10381-1d11-43ba-b0bb-7686e48ef9ce
E findByNaturalKey(Object naturalKey);
d0177b16-65ee-455f-be8d-aaa749b02db4
E findByPrimaryKey(ID id);
bb4cd90c-1ae2-4f6c-9ed3-c7af6430c9ad
List<E> findByProperty(String property, Object value, PagingOrdering paging);
8b07fc46-820a-4851-9403-8f9e5cad8c17
List<E> getAll();
1befd382-c7c7-44e0-8f15-1cccbe1dd532
List<E> getPaginated(PagingOrdering paging);
5d2fa1fa-a037-4129-8972-de6c2635f07e
boolean isPersistent(ID id);
650c6b89-9bb3-481f-a1fd-4d0c2eef22b4
E load(ID id);
37b5d76f-cb5a-414d-a328-63f9b3f18428
ID save(E entity);
b030afa6-83f1-4958-9d05-f0559103a84d
void saveOrUpdate(E entity);
d6f11d03-f78b-440c-9b02-0cb7aca897f0
void update(E entity);
a65ff428-5e1d-4266-b115-3257979000ce
Class<E> getEntityClass();
5107bc10-99a7-43d5-a573-389a1af99f3a
@Override public boolean containsDAO(Class<? extends Persistable> entityClass) { return registry.containsKey(entityClass); }
ff732fff-143d-4608-9e63-a1ca66582332
@Override public SpecificDAO getDAO(Class<? extends Persistable> entityClass) { return registry.get(entityClass); }
afd9c3cd-cb87-4508-96e7-98200901d9af
@Override public void register(SpecificDAO specificDAO) { LOG.info("Registering Specific DAO for entity class: {}", specificDAO.getEntityClass()); registry.put(specificDAO.getEntityClass(), specificDAO); }
866d5204-5d5c-4726-80aa-77bcb391a77a
public GenericDAODispatcher(GenericDAO genericDAO, SpecificDAORegistry registry) { this.genericDAO = genericDAO; this.registry = registry; }
bf9be367-a2ee-4a43-bd67-98597b596c42
@Override public Long count(Class<? extends Persistable> clazz) { if (registry.containsDAO(clazz)) { return registry.getDAO(clazz).count(); } else { return genericDAO.count(clazz); } }
433bdc34-8683-42e8-a6c6-08e68b7e0173
@Override public void delete(Persistable entity) { if (registry.containsDAO(entity.getClass())) { registry.getDAO(entity.getClass()).delete(entity); } else { genericDAO.delete(entity); } }
8f9bdc4f-cf37-424a-8df0-ca353b599ac5
@Override public void delete(Serializable id, Class<? extends Persistable> clazz) { if (registry.containsDAO(clazz)) { registry.getDAO(clazz).delete(id); } else { genericDAO.delete(id, clazz); } }
e0f91f83-b9e7-404a-86b7-38f3a9af9793
@Override public <E extends Persistable> List<E> findByExample(E exampleInstance, String[] includeProperties, PagingOrdering paging, Class<E> clazz) { if (registry.containsDAO(clazz)) { return registry.getDAO(clazz).findByExample(exampleInstance, includeProperties, paging); } else { return genericDAO.findByExample(exampleInstance, includeProperties, paging, clazz); } }
1a276f6d-d22c-4ab1-bce0-cdb0b9261a3f
@Override public <E extends Persistable> E findByNaturalKey(Object naturalKey, Class<E> clazz) { if (registry.containsDAO(clazz)) { return (E) registry.getDAO(clazz).findByNaturalKey(naturalKey); } else { return genericDAO.findByNaturalKey(naturalKey, clazz); } }
9bd3d2be-538d-410e-82c7-f06744ee47bf
@Override public <E extends Persistable> E findByPrimaryKey(Serializable id, Class<E> clazz) { if (registry.containsDAO(clazz)) { return (E) registry.getDAO(clazz).findByPrimaryKey(id); } else { return genericDAO.findByPrimaryKey(id, clazz); } }
737af216-d9f7-4a6a-8ea2-bfb028548e2b
@Override public <E extends Persistable> List<E> findByProperty(String property, Object value, PagingOrdering paging, Class<E> clazz) { if (registry.containsDAO(clazz)) { return registry.getDAO(clazz).findByProperty(property, value, paging); } else { return genericDAO.findByProperty(property, value, paging, clazz); } }
25dab9c6-a438-436f-8404-46f7e155c539
@Override public <E extends Persistable> List<E> getAll(Class<E> clazz) { if (registry.containsDAO(clazz)) { return registry.getDAO(clazz).getAll(); } else { return genericDAO.getAll(clazz); } }
f65553d7-c6a0-4f67-8116-407e72ffdf35
@Override public <E extends Persistable> List<E> getPaginated(PagingOrdering paging, Class<E> clazz) { if (registry.containsDAO(clazz)) { return registry.getDAO(clazz).getPaginated(paging); } else { return genericDAO.getPaginated(paging, clazz); } }