code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public void add(Orientation orientation, String group)
{
final Collection<String> groups = constraints.get(orientation);
groups.add(group);
} | java |
public static Collection<TileGroup> imports(Media groupsConfig)
{
Check.notNull(groupsConfig);
final Xml nodeGroups = new Xml(groupsConfig);
final Collection<Xml> children = nodeGroups.getChildren(NODE_GROUP);
final Collection<TileGroup> groups = new ArrayList<>(children.siz... | java |
public static void exports(Media groupsConfig, Iterable<TileGroup> groups)
{
Check.notNull(groupsConfig);
Check.notNull(groups);
final Xml nodeGroups = new Xml(NODE_GROUPS);
nodeGroups.writeString(Constant.XML_HEADER, Constant.ENGINE_WEBSITE);
for (final TileGroup g... | java |
private static TileGroup importGroup(Xml nodeGroup)
{
final Collection<Xml> children = nodeGroup.getChildren(TileConfig.NODE_TILE);
final Collection<TileRef> tiles = new ArrayList<>(children.size());
for (final Xml nodeTileRef : children)
{
final TileRef tileRef =... | java |
private static void exportGroup(Xml nodeGroups, TileGroup group)
{
final Xml nodeGroup = nodeGroups.createChild(NODE_GROUP);
nodeGroup.writeString(ATT_GROUP_NAME, group.getName());
nodeGroup.writeString(ATT_GROUP_TYPE, group.getType().name());
for (final TileRef tileRef : grou... | java |
public final void setScreenWidth(int screenWidth)
{
final int wi = (int) Math.ceil(screenWidth / (double) sprite.getWidth()) + 1;
w = wi;
} | java |
private void kick()
{
if (!connected)
{
return;
}
messagesIn.clear();
messagesOut.clear();
try
{
out.close();
}
catch (final IOException exception)
{
Verbose.exception(exception, "Error on closing out... | java |
private String readString() throws IOException
{
final int size = in.readByte();
if (size > 0)
{
final byte[] name = new byte[size];
if (in.read(name) != -1)
{
return new String(name, NetworkMessage.CHARSET);
}
}
... | java |
private void updateMessage(byte messageSystemId) throws IOException
{
switch (messageSystemId)
{
case NetworkMessageSystemId.CONNECTING:
updateConnecting();
break;
case NetworkMessageSystemId.CONNECTED:
updateConnected();
... | java |
private void updateConnecting() throws IOException
{
if (clientId == -1)
{
// Receive id
clientId = in.readByte();
// Send the name
out.writeByte(NetworkMessageSystemId.CONNECTING);
out.writeByte(clientId);
final byte[] data = c... | java |
private void updateConnected() throws IOException
{
byte cid = in.readByte();
// Ensure the client id is the same
if (cid != clientId)
{
return;
}
for (final ConnectionListener listener : listeners)
{
listener.notifyConnectionEstablishe... | java |
private void updateOtherClientConnected() throws IOException
{
final byte cid = in.readByte();
final String cname = readString();
for (final ConnectionListener listener : listeners)
{
listener.notifyClientConnected(Byte.valueOf(cid), cname);
}
} | java |
private void updateOtherClientDisconnected() throws IOException
{
final byte cid = in.readByte();
final String cname = readString();
for (final ConnectionListener listener : listeners)
{
listener.notifyClientDisconnected(Byte.valueOf(cid), cname);
}
} | java |
private void sendMessage(NetworkMessage message)
{
try (ByteArrayOutputStream encode = message.encode())
{
final byte[] encoded = encode.toByteArray();
// Message header
out.writeByte(NetworkMessageSystemId.USER_MESSAGE);
out.writeByte(message.getClien... | java |
public static List<File> getDirectories(File path)
{
Check.notNull(path);
return Optional.ofNullable(path.listFiles())
.map(files -> Arrays.asList(files)
.stream()
.filter(File::isDirectory)... | java |
public static String getPathSeparator(String separator, String... path)
{
Check.notNull(separator);
Check.notNull(path);
final StringBuilder fullPath = new StringBuilder(path.length);
for (int i = 0; i < path.length; i++)
{
if (i == path.length - 1)
{... | java |
public static CollisionConstraint imports(Xml node)
{
Check.notNull(node);
final CollisionConstraint constraint = new CollisionConstraint();
if (node.hasChild(NODE_CONSTRAINT))
{
for (final Xml current : node.getChildren(NODE_CONSTRAINT))
{
... | java |
public static void exports(Xml root, CollisionConstraint constraint)
{
Check.notNull(root);
Check.notNull(constraint);
for (final Entry<Orientation, Collection<String>> entry : constraint.getConstraints().entrySet())
{
final Orientation orientation = entry.getKey(... | java |
private void remove(Integer layer, Refreshable refreshable)
{
final Collection<Refreshable> refreshables = getLayer(layer);
refreshables.remove(refreshable);
if (refreshables.isEmpty())
{
indexs.remove(layer);
}
} | java |
public static CollisionFormulaConfig imports(Media config)
{
final Xml root = new Xml(config);
final Map<String, CollisionFormula> collisions = new HashMap<>(0);
for (final Xml node : root.getChildren(NODE_FORMULA))
{
final String name = node.readString(ATT_NAME);... | java |
public static void exports(Xml root, CollisionFormula formula)
{
Check.notNull(root);
Check.notNull(formula);
final Xml node = root.createChild(NODE_FORMULA);
node.writeString(ATT_NAME, formula.getName());
CollisionRangeConfig.exports(node, formula.getRange());
... | java |
public static CollisionFormula createCollision(Xml node)
{
Check.notNull(node);
final String name = node.readString(ATT_NAME);
final CollisionRange range = CollisionRangeConfig.imports(node.getChild(CollisionRangeConfig.NODE_RANGE));
final CollisionFunction function = Collisio... | java |
public static void remove(Xml root, String formula)
{
Check.notNull(root);
Check.notNull(formula);
for (final Xml node : root.getChildren(NODE_FORMULA))
{
if (node.readString(ATT_NAME).equals(formula))
{
root.removeChild(node);
... | java |
public static boolean has(Xml root, String formula)
{
Check.notNull(root);
Check.notNull(formula);
for (final Xml node : root.getChildren(NODE_FORMULA))
{
if (node.readString(ATT_NAME).equals(formula))
{
return true;
}
... | java |
public double getInputValue(Axis input, double x, double y)
{
final double v;
switch (input)
{
case X:
v = Math.floor(x - tile.getX());
break;
case Y:
v = Math.floor(y - tile.getY());
break;
d... | java |
private Double getCollisionX(CollisionRange range, CollisionFunction function, double x, double y, int offsetX)
{
final double yOnTile = getInputValue(Axis.Y, x, y);
if (UtilMath.isBetween(yOnTile, range.getMinY(), range.getMaxY()))
{
final double xOnTile = getInputValue(Axis.X, ... | java |
int[] getScaledData(int[] srcImage)
{
final int[] dstImage = new int[srcImage.length * SCALE * SCALE];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
process(srcImage, dstImage, x, y);
}
}
... | java |
private void setDestPixel(int[] dstImage, int x, int y, int p)
{
dstImage[x + y * width * SCALE] = p;
} | java |
private int getSourcePixel(int[] srcImage, int x, int y)
{
int x1 = Math.max(0, x);
x1 = Math.min(width - 1, x1);
int y1 = Math.max(0, y);
y1 = Math.min(height - 1, y1);
return srcImage[x1 + y1 * width];
} | java |
private void process(int[] srcImage, int[] dstImage, int x, int y)
{
final int b = getSourcePixel(srcImage, x, y - 1);
final int d = getSourcePixel(srcImage, x - 1, y);
final int e = getSourcePixel(srcImage, x, y);
final int f = getSourcePixel(srcImage, x + 1, y);
final... | java |
public static Animation createAnimation(XmlReader node)
{
Check.notNull(node);
final String name = node.readString(ANIMATION_NAME);
final int start = node.readInteger(ANIMATION_START);
final int end = node.readInteger(ANIMATION_END);
final double speed = node.readDoub... | java |
public static void exports(Xml root, Animation animation)
{
Check.notNull(root);
Check.notNull(animation);
final Xml node = root.createChild(ANIMATION);
node.writeString(ANIMATION_NAME, animation.getName());
node.writeInteger(ANIMATION_START, animation.getFirst());
... | java |
public Animation getAnimation(String name)
{
final Animation animation = animations.get(name);
if (animation == null)
{
throw new LionEngineException(ERROR_NOT_FOUND + name);
}
return animation;
} | java |
public void update(Viewer viewer)
{
x = (int) viewer.getX();
y = (int) viewer.getY() - viewer.getViewY();
height = viewer.getHeight();
} | java |
public static final synchronized void terminate()
{
if (started)
{
engine.close();
started = false;
Verbose.info(ENGINE_TERMINATED);
engine.postClose();
engine = null;
}
} | java |
private static void appendDate(StringBuilder message)
{
final String date = DATE_TIME_FORMAT.format(Calendar.getInstance().getTime());
message.append(date);
message.append(Constant.SPACE);
} | java |
private static void appendLevel(StringBuilder message, LogRecord event)
{
final String logLevel = event.getLevel().getName();
for (int i = logLevel.length(); i < LOG_LEVEL_LENGTH; i++)
{
message.append(Constant.SPACE);
}
message.append(logLevel).append(Cons... | java |
private static void appendFunction(StringBuilder message, LogRecord event)
{
final String clazz = event.getSourceClassName();
if (clazz != null)
{
message.append(IN).append(clazz);
}
final String function = event.getSourceMethodName();
if (functi... | java |
private static void appendThrown(StringBuilder message, LogRecord event)
{
final Throwable thrown = event.getThrown();
if (thrown != null)
{
final StringWriter sw = new StringWriter();
thrown.printStackTrace(new PrintWriter(sw));
message.append(sw);... | java |
public static Optional<Coord> intersection(Line l1, Line l2)
{
Check.notNull(l1);
Check.notNull(l2);
final double x1 = l1.getX1();
final double x2 = l1.getX2();
final double y1 = l1.getY1();
final double y2 = l1.getY2();
final double x3 = l2.getX1(... | java |
public static Area createArea(double x, double y, double width, double height)
{
return new AreaImpl(x, y, width, height);
} | java |
public static boolean same(Localizable a, Localizable b)
{
return Double.compare(a.getX(), b.getX()) == 0 && Double.compare(a.getY(), b.getY()) == 0;
} | java |
private static List<Field> getServiceFields(Object object)
{
final List<Field> toInject = new ArrayList<>();
Class<?> clazz = object.getClass();
while (clazz != null)
{
final Field[] fields = clazz.getDeclaredFields();
final int length = fields.length;
... | java |
private void fillServices(Object object)
{
final List<Field> fields = getServiceFields(object);
final int length = fields.size();
for (int i = 0; i < length; i++)
{
final Field field = fields.get(i);
UtilReflection.setAccessible(field, true);
... | java |
public static String normalizeExtension(String file, String extension)
{
Check.notNull(file);
Check.notNull(extension);
final int length = file.length() + Constant.DOT.length() + extension.length();
final StringBuilder builder = new StringBuilder(length).append(removeExtension(file)... | java |
public static String getExtension(File file)
{
Check.notNull(file);
return getExtension(file.getName());
} | java |
public static List<File> getFiles(File directory)
{
Check.notNull(directory);
if (directory.isDirectory())
{
final File[] files = directory.listFiles();
if (files != null)
{
return Arrays.asList(files);
}
}
thro... | java |
public static boolean isType(File file, String extension)
{
Check.notNull(extension);
if (file != null && file.isFile())
{
final String current = getExtension(file);
return current.equals(extension.replace(Constant.DOT, Constant.EMPTY_STRING));
}
retu... | java |
private void renderTile(Graphic g, int tx, int ty, double viewX, double viewY)
{
final Tile tile = map.getTile(tx, ty);
if (tile != null)
{
final int x = (int) Math.floor(tile.getX() - viewX);
final int y = (int) Math.floor(-tile.getY() + viewY - tile.getHeight(... | java |
private void renderHorizontal(Graphic g, int ty, double viewY)
{
final int inTileWidth = (int) Math.ceil(viewer.getWidth() / (double) map.getTileWidth());
final int sx = (int) Math.floor((viewer.getX() + viewer.getViewX()) / map.getTileWidth());
final double viewX = viewer.getX();
... | java |
public synchronized void start()
{
if (started.get())
{
throw new LionEngineException(ERROR_STARTED);
}
started.set(true);
thread.start();
} | java |
public static Map<TileRef, ColorRgba> imports(Media configMinimap)
{
Check.notNull(configMinimap);
final Map<TileRef, ColorRgba> colors = new HashMap<>();
final Xml nodeMinimap = new Xml(configMinimap);
for (final Xml nodeColor : nodeMinimap.getChildren(NODE_COLOR))
... | java |
public static void exports(Media configMinimap, Map<TileRef, ColorRgba> tiles)
{
Check.notNull(configMinimap);
Check.notNull(tiles);
final Map<ColorRgba, Collection<TileRef>> colors = convertToColorKey(tiles);
final Xml nodeMinimap = new Xml(NODE_MINIMAP);
for (fina... | java |
private static Map<ColorRgba, Collection<TileRef>> convertToColorKey(Map<TileRef, ColorRgba> tiles)
{
final Map<ColorRgba, Collection<TileRef>> colors = new HashMap<>();
for (final Map.Entry<TileRef, ColorRgba> entry : tiles.entrySet())
{
final Collection<TileRef> tilesRef... | java |
private static Collection<TileRef> getTiles(Map<ColorRgba, Collection<TileRef>> colors, ColorRgba color)
{
if (!colors.containsKey(color))
{
colors.put(color, new HashSet<TileRef>());
}
return colors.get(color);
} | java |
private int getCharWidth(String text, Align align)
{
final int width;
if (align == Align.RIGHT)
{
width = getTextWidth(text);
}
else if (align == Align.CENTER)
{
width = getTextWidth(text) / 2;
}
else
{
width... | java |
public static FeaturableConfig imports(Configurer configurer)
{
Check.notNull(configurer);
return imports(configurer.getRoot());
} | java |
public static FeaturableConfig imports(Xml root)
{
Check.notNull(root);
final String clazz;
if (root.hasChild(ATT_CLASS))
{
clazz = root.getChild(ATT_CLASS).getText();
}
else
{
clazz = DEFAULT_CLASS_NAME;
}
final Strin... | java |
public static Xml exportClass(String clazz)
{
Check.notNull(clazz);
final Xml node = new Xml(ATT_CLASS);
node.setText(clazz);
return node;
} | java |
public static Xml exportSetup(String setup)
{
Check.notNull(setup);
final Xml node = new Xml(ATT_SETUP);
node.setText(setup);
return node;
} | java |
@SuppressWarnings("unchecked")
private static <T> Class<T> getClass(String className)
{
if (CLASS_CACHE.containsKey(className))
{
return (Class<T>) CLASS_CACHE.get(className);
}
try
{
final Class<?> clazz = LOADER.loadClass(className);
... | java |
public boolean contains(Integer sheet, int number)
{
for (final TileRef current : tiles)
{
if (current.getSheet().equals(sheet) && current.getNumber() == number)
{
return true;
}
}
return false;
} | java |
public static CollisionFunction imports(Xml parent)
{
Check.notNull(parent);
final Xml node = parent.getChild(FUNCTION);
final String name = node.readString(TYPE);
try
{
final CollisionFunctionType type = CollisionFunctionType.valueOf(name);
... | java |
public static void exports(Xml root, CollisionFunction function)
{
Check.notNull(root);
Check.notNull(function);
final Xml node = root.createChild(FUNCTION);
if (function instanceof CollisionFunctionLinear)
{
final CollisionFunctionLinear linear = (Collis... | java |
public void update(double screenX, double screenY)
{
for (final Image current : surfaces.values())
{
current.setLocation(screenX + offsetX, screenY + offsetY);
}
if (nextSurface != null)
{
surface = nextSurface;
nextSurface = null;
... | java |
final void resize(int newWidth, int newHeight)
{
final int oldWidth = widthInTile;
final int oldheight = heightInTile;
// Adjust height
for (int v = 0; v < newHeight - oldheight; v++)
{
tiles.add(new ArrayList<Tile>(newWidth));
}
// Adjust width
... | java |
public static PathFinder createPathFinder(MapTile map, int maxSearchDistance, Heuristic heuristic)
{
return new PathFinderImpl(map, maxSearchDistance, heuristic);
} | java |
private static void writeIdAndName(ClientSocket client, int id, String name) throws IOException
{
// New client id
client.getOut().writeByte(id);
// New client name
final byte[] data = name.getBytes(NetworkMessage.CHARSET);
client.getOut().writeByte(data.length);
clie... | java |
private static boolean checkValidity(ClientSocket client, byte from, StateConnection expected)
{
return from >= 0 && client.getState() == expected;
} | java |
void notifyNewClientConnected(Socket socket)
{
try
{
int secure = 0;
while (clients.containsKey(Byte.valueOf(lastId)))
{
lastId++;
secure++;
final int max = 127;
if (secure > max)
{
... | java |
void removeClient(ClientSocket client)
{
if (client != null)
{
toRemove.add(client);
client.terminate();
clientsNumber--;
willRemove = true;
Verbose.info(SERVER, client.getName(), " disconnected");
}
} | java |
private void errorNewClientConnected(Exception exception)
{
Verbose.warning(Server.class, "addClient", "Error on adding client: ", exception.getMessage());
if (clients.remove(Byte.valueOf(lastId)) != null)
{
clientsNumber--;
}
} | java |
private void receiveConnecting(ClientSocket client, DataInputStream buffer, byte from, StateConnection expected)
throws IOException
{
if (ServerImpl.checkValidity(client, from, expected))
{
// Receive the name
final byte[] name = new byte[buffer.readByte()];
... | java |
private void receiveConnected(ClientSocket client, byte from, StateConnection expected) throws IOException
{
if (ServerImpl.checkValidity(client, from, expected))
{
// Terminate last connection step and accept it
Verbose.info(SERVER, client.getName(), " connected");
... | java |
private void receiveDisconnected(ClientSocket client, byte from, StateConnection expected) throws IOException
{
if (ServerImpl.checkValidity(client, from, expected))
{
// Notify other clients
client.setState(StateConnection.DISCONNECTED);
for (final ClientListener... | java |
private void receiveRenamed(ClientSocket client, DataInputStream buffer, byte from, StateConnection expected)
throws IOException
{
if (ServerImpl.checkValidity(client, from, expected))
{
// Receive the name
final byte[] name = new byte[buffer.readByte()];
... | java |
private void receiveMessage(ClientSocket client, DataInputStream buffer, byte from, StateConnection expected)
throws IOException
{
if (ServerImpl.checkValidity(client, from, expected))
{
final byte dest = buffer.readByte();
final byte type = buffer.readByte();
... | java |
private void updateMessage(ClientSocket client, DataInputStream buffer, byte messageSystemId, byte from)
throws IOException
{
switch (messageSystemId)
{
case NetworkMessageSystemId.CONNECTING:
receiveConnecting(client, buffer, from, StateConnection.CONNECTING)... | java |
private JFrame initMainFrame()
{
final String title = getTitle();
final JFrame jframe = new JFrame(title, conf);
jframe.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
jframe.addWindowListener(new WindowAdapter()
{
@Override
public void ... | java |
private static String getTitle()
{
final StringBuilder builder = new StringBuilder(Constant.BYTE_4);
if (Engine.isStarted())
{
builder.append(Engine.getProgramName()).append(Constant.SPACE).append(Engine.getProgramVersion());
}
else
{
builder.a... | java |
private static Collision collide(Origin origin,
FeatureProvider provider,
Transformable transformable,
Collidable other,
Collision collision,
... | java |
private static boolean checkCollide(Area area, Collidable other)
{
final List<Rectangle> others = other.getCollisionBounds();
final int size = others.size();
for (int i = 0; i < size; i++)
{
final Area current = others.get(i);
if (area.intersects(curren... | java |
private static Mirror getMirror(FeatureProvider provider, Collision collision)
{
if (collision.hasMirror() && provider.hasFeature(Mirrorable.class))
{
return provider.getFeature(Mirrorable.class).getMirror();
}
return Mirror.NONE;
} | java |
private static int getOffsetX(Collision collision, Mirror mirror)
{
if (mirror == Mirror.HORIZONTAL)
{
return -collision.getOffsetX();
}
return collision.getOffsetX();
} | java |
private static int getOffsetY(Collision collision, Mirror mirror)
{
if (mirror == Mirror.VERTICAL)
{
return -collision.getOffsetY();
}
return collision.getOffsetY();
} | java |
private void update(Collision collision,
double x,
double y,
int width,
int height,
Map<Collision, Rectangle> cacheRectRender)
{
if (boxs.containsKey(collision))
{
... | java |
public List<Collision> collide(Origin origin,
FeatureProvider provider,
Transformable transformable,
Collidable other,
Collection<Integer> accepted)
{
final List<... | java |
public static LaunchableConfig imports(Xml node)
{
Check.notNull(node);
final String media = node.readString(ATT_MEDIA);
final int delay = node.readInteger(ATT_DELAY);
final int ox = node.readInteger(0, ATT_OFFSET_X);
final int oy = node.readInteger(0, ATT_OFFSET_Y);
... | java |
public static Xml exports(LaunchableConfig config)
{
Check.notNull(config);
final Xml node = new Xml(NODE_LAUNCHABLE);
node.writeString(ATT_MEDIA, config.getMedia());
node.writeInteger(ATT_DELAY, config.getDelay());
node.writeInteger(ATT_OFFSET_X, config.getOffsetX())... | java |
public void mouseReleased(MouseEvent event)
{
lastClick = 0;
final int button = event.getClick();
clicks[button] = false;
clicked[button] = false;
} | java |
public static Collection<ZipEntry> getEntriesByExtension(File jar, String path, String extension)
{
Check.notNull(jar);
Check.notNull(path);
Check.notNull(extension);
try (ZipFile zip = new ZipFile(jar))
{
return checkEntries(zip, path, extension);
}
... | java |
private static Collection<ZipEntry> checkEntries(ZipFile zip, String path, String extension)
{
final Collection<ZipEntry> entries = new ArrayList<>();
final Enumeration<? extends ZipEntry> zipEntries = zip.entries();
while (zipEntries.hasMoreElements())
{
final ZipEntry e... | java |
public static AudioFormat getFailsafe()
{
try
{
return new Sc68Format();
}
catch (final LionEngineException exception)
{
Verbose.exception(exception, ERROR_LOAD_LIBRARY);
return new AudioVoidFormat(FORMATS);
}
} | java |
private static Sc68Binding loadLibrary()
{
try
{
Verbose.info("Load library: ", LIBRARY_NAME);
final Sc68Binding binding = Native.loadLibrary(LIBRARY_NAME, Sc68Binding.class);
Verbose.info("Library ", LIBRARY_NAME, " loaded");
return binding;
... | java |
public void add(Featurable featurable)
{
featurables.put(featurable.getFeature(Identifiable.class).getId(), featurable);
for (final Class<?> type : featurable.getClass().getInterfaces())
{
addType(type, featurable);
}
for (final Class<? extends Feature>... | java |
public void remove(Featurable featurable, Integer id)
{
for (final Class<?> type : featurable.getClass().getInterfaces())
{
remove(type, featurable);
}
for (final Class<? extends Feature> feature : featurable.getFeaturesType())
{
final Featur... | java |
private void addType(Class<?> type, Object object)
{
if (!items.containsKey(type))
{
items.put(type, new HashSet<>());
}
items.get(type).add(object);
} | java |
private void addSuperClass(Object object, Class<?> type)
{
for (final Class<?> types : type.getInterfaces())
{
addType(types, object);
}
final Class<?> parent = type.getSuperclass();
if (parent != null)
{
addSuperClass(object, parent);... | java |
private void removeSuperClass(Object object, Class<?> type)
{
for (final Class<?> types : type.getInterfaces())
{
remove(types, object);
}
final Class<?> parent = type.getSuperclass();
if (parent != null)
{
removeSuperClass(object, par... | java |
private void remove(Class<?> type, Object object)
{
final Set<?> set = items.get(type);
if (set != null)
{
set.remove(object);
}
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.