text stringlengths 14 410k | label int32 0 9 |
|---|---|
private void flushResponse() {
try {
if (!ctx.getChannel().isOpen()) {
System.err.println("channel is closed, channel: " + ctx.getChannel());
ctx.getChannel().disconnect();
ctx.getChannel().close();
return;
}
// mymod. WebbitException: cannot send more responses than requests
if (!ctx.getChannel().isWritable()) return;
// TODO: Shouldn't have to do this, but without it we sometimes seem to get two Content-Length headers in the response.
header("Content-Length", (String) null);
header("Content-Length", responseBuffer.readableBytes());
ChannelFuture future = response.isChunked() ? ctx.getChannel().write(new DefaultHttpChunk(ChannelBuffers.EMPTY_BUFFER)) : write(responseBuffer);
if (!isKeepAlive) {
future.addListener(ChannelFutureListener.CLOSE);
}
} catch (Exception e) {
exceptionHandler.uncaughtException(Thread.currentThread(),
WebbitException.fromException(e, ctx.getChannel()));
}
} | 5 |
public <T extends Component> void addComponent(UUID entity, T component) {
if (frozen) {
return;
}
synchronized (componentStores) {
HashMap<UUID, ? extends Component> store = componentStores
.get(component.getClass());
if (store == null) {
store = new HashMap<>();
componentStores.put(component.getClass(), store);
}
((HashMap<UUID, T>) store).put(entity, component);
}
} | 3 |
public boolean executeLine(String line) {
if (first && (line.equals("ditaa") || line.startsWith("ditaa("))) {
data = new StringBuilder();
if (line.contains("-E") || line.contains("--no-separation")) {
performSeparationOfCommonEdges = false;
}
if (line.contains("-S") || line.contains("--no-shadows")) {
dropShadows = false;
}
return true;
}
first = false;
if (data == null) {
return false;
}
data.append(line);
data.append("\n");
return true;
} | 8 |
public static String classDescriptor(String name) {
// The name of the class may arrive as the name of the class file
// in which in resides. In this case, we should remove the .class
// file extension.
if (name.endsWith(".class")) {
name = name.substring(0, name.lastIndexOf('.'));
}
name = name.replace('.', '/');
if (name.charAt(0) == Type.ARRAY_CHAR) {
return name;
}
return Type.CLASS_CHAR + name + ";";
} | 2 |
public static String vectorCaddieToHTML(Vector<Caddie> rs){
if (rs.isEmpty())
return "<p class=\"plusbas\">Le caddie est vide.</p>";
String toReturn = "<TABLE BORDER='1' width=\"1000\">";
toReturn+="<CAPTION>Le caddie :</CAPTION>";
toReturn+="<TR>";
toReturn+="<TH> <i>Reservation n°</i></TH>";
toReturn+="<TH> <i>Spectacle</i> </TH><TH> <i>Date représentation</i></TH>";
toReturn+="<TH> <i> Zone </i></TH>";
toReturn+="<TH> <i>Nombre de places (Ajouter/Retirer)</i></TH>";
toReturn+="<TH> <i>Supprimer la réservation</i></TH>";
toReturn+="</TR>";
for (int i = 0; i < rs.size(); i++) {
toReturn+="<TR>";
toReturn+="<TH> "+(i+1)+"</TH>";
toReturn+="<TH>"+rs.elementAt(i).getNom()+" </TH><TH> "+rs.elementAt(i).getDate()+"</TH>";
toReturn+="<TH> "+rs.elementAt(i).getZone()+" ("+rs.elementAt(i).getNomZ()+")</TH>";
if (rs.elementAt(i).getQt() > 1)
toReturn+="<TH> <a href=\"/servlet/ConsultationCaddieServlet?idm="+rs.elementAt(i).getId()+"\" >(-)</a> "+rs.elementAt(i).getQt()+" <a href=\"/servlet/ConsultationCaddieServlet?idp="+rs.elementAt(i).getId()+"\" >(+)</a></TH>";
else
toReturn+="<TH>"+rs.elementAt(i).getQt()+" <a href=\"/servlet/ConsultationCaddieServlet?idp="+rs.elementAt(i).getId()+"\" >(+)</a></TH>";
toReturn+="<TH> <a href=\"/servlet/ConsultationCaddieServlet?idd="+rs.elementAt(i).getId()+"\" >(X)</a> </TH>";
toReturn+="</TR>";
}
return toReturn+"</TABLE><form action=\"\"><input type=\"submit\" name=\"valider\" value=\"Valider le caddie\"/></form>";
} | 3 |
@Override
public boolean modificarCliente(TCliente cliente)
{
boolean correcto = false;
TransactionManager.obtenerInstanacia().nuevaTransaccion();
try
{
TransactionManager.obtenerInstanacia().getTransaccion().start();
TCliente tCliente = FactoriaDAO.obtenerInstancia().getDAOCliente().mostrarCliente(cliente.getId());
if(tCliente !=null && !tCliente.equals(cliente))
{
if(FactoriaDAO.obtenerInstancia().getDAOCliente().modificarCliente(cliente))
{
try
{
TransactionManager.obtenerInstanacia().getTransaccion().commit();
correcto = true;
}//si falla el commit
catch(Exception e){
TransactionManager.obtenerInstanacia().getTransaccion().rollback();
correcto = false;
}
}
}
else{
//echamos para atras la transaccion
TransactionManager.obtenerInstanacia().getTransaccion().rollback();
correcto = false;
}
//Eliminamos la transaccion
TransactionManager.obtenerInstanacia().eliminaTransaccion();
}
catch(Exception e ){
try {
TransactionManager.obtenerInstanacia().getTransaccion().rollback();
} catch (Exception ex) {
ex.printStackTrace();
}
TransactionManager.obtenerInstanacia().eliminaTransaccion();
correcto = false;
}
return correcto;
} | 6 |
@Override
public void setEntityManager(IEntityManager<? extends IEntityTracker> entityManager) {
if(!this.finalized) {
if(entityManager instanceof IPluggable) this.entityManager = entityManager;
else throw new UnsupportedOperationException("The EntityManager does not implement IPluggable!");
}
else throw new UnsupportedOperationException("The Chassis has been finalized, you cannot swap systems now");
} | 3 |
public Image getImage() {
if(image == null) {
try {
image = new Image("res/sprites/items/" + getItemID() + ".png");
} catch (SlickException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return image;
} | 2 |
public int saveBook(Book bookToSave) {
try {
// Erforderlicher SQL-Befehl
String sqlStatement = "INSERT INTO bookworm_database.books (isbn, title, author, "
+ "publicationDate, formatb, shortDescription, category, "
+ "commentb, readb) VALUES ('"
+ bookToSave.getIsbn()
+ "', '"
+ bookToSave.getTitle()
+ "', '"
+ bookToSave.getAuthor()
+ "', '"
+ bookToSave.getPublicationDate()
+ "', '"
+ bookToSave.getFormat()
+ "', '"
+ bookToSave.getShortDescription()
+ "', '"
+ bookToSave.getCategory()
+ "', '"
+ bookToSave.getComment()
+ "', '"
+ bookToSave.getRead()
+ "');";
// SQL-Befehl wird ausgeführt
successful = mySQLDatabase.executeSQLUpdate(sqlStatement);
return successful;
} catch (Exception e) {
System.out.println(e.toString());
// Ein Dialogfenster mit entsprechender Meldung soll erzeugt werden
String errorText = "Datenbank-Fehler beim Abspeichern eines Datensatzes.";
errorMessage.showMessage(errorText);
successful = 0;
return successful;
} finally {
// offene Verbindungen werden geschlossen
mySQLDatabase.closeConnections();
}
} | 1 |
public String[] getLastSenders()
{
return previousSenders;
} | 0 |
private void checkForWhite(int i, int j) {
gameBoard.step(blockBoard[i][j]);
// Checks that block is blank & 0 n
if (blockBoard[i][j] instanceof Blank) {
boardButtons[i][j].setVisible(false);
blockBoard[i][j].setAlreadyChecked(true);
for (int a = i - 1; a <= i + 1; a++) {
for (int b = j - 1; b <= j + 1; b++) {
try {
if (!blockBoard[a][b].isAlreadyChecked()) {
if (blockBoard[a][b] instanceof Blank) {
if (blockBoard[a][b].getNumOfMinesAround() == 0) {
checkForWhite(a, b);
} else {
boardButtons[a][b].doClick();
blockBoard[a][b].setAlreadyChecked(true);
}
}
if (blockBoard[a][b] instanceof Treasure) {
boardButtons[a][b].doClick();
}
}
} catch (Exception ArrayIndexOutOfBoundsException) {
}
}
}
}
} | 8 |
public void doAnswer(AnswerSide answerSide)
{
if (this.answerSide == answerSide || isRunning)
return;
isRunning = true;
AnswerSideManager answerSideManager = AnswerSideManager.getInstance();
answerSideManager.setAnswerSide(answerSide);
PriceManager priceManager = PriceManager.getInstance();
Timer timer = Timer.getInstance();
timer.stop();
boolean isCorrect = new BrainConfirmationDialog().showConfirmationDialog();
answerSideManager.setAnswerSide(null);
if (isCorrect)
{
ScoreManager.getInstance().increaseScore(answerSide, priceManager.getPrice());
priceManager.setPrice(1);
goNext();
}
else
{
if (this.answerSide == null)
{
this.answerSide = answerSide;
timer.start();
isRunning = false;
}
else
{
priceManager.setPrice(priceManager.getPrice() + 1);
goNext();
}
}
} | 4 |
@Override
public void tickServer() {
super.tickServer();
if (needsInit) {
needsInit = false;
for (WorldCoordinate pair : getPairs()) {
SignalController controller = getControllerAt(pair);
if (controller != null) {
onControllerAspectChange(controller, controller.getAspectFor(getCoords()));
}
}
}
} | 3 |
@Override
public boolean generateClientSettings(final File settingsFile) {
LOG.log(Level.FINE, "Generating client settings.");
final SimpleXMLSettingsFile xml = new SimpleXMLSettingsFile();
boolean result = false;
try {
final Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface n : Collections.list(nets)) {
if (n.isUp()) {
for (InetAddress address : Collections.list(n.getInetAddresses())) {
xml.addField(
XmlNodes.SERVER.toString(),
ClientSettings.composeServerAddress(address, serverSocket.getPort()));
}
}
}
result = xml.storeXML(settingsFile);
} catch (SocketException ex) {
LOG.log(Level.WARNING, "Error listing available network interfaces.", settingsFile.getAbsolutePath());
LOG.log(Level.FINE, "Error listing available network interfaces.", ex);
} catch (IOException ex) {
LOG.log(Level.WARNING, "Error accessing client settings at {0}.", settingsFile.getAbsolutePath());
LOG.log(Level.FINE, "Error accessing client settings at " + settingsFile.getAbsolutePath() + ".", ex);
}
return result;
} | 5 |
public RenderTable wrapper(final GraphReportExtension mr) {
GraphModelIterator it;
if (!gens.equals(GeneratorFilters.NoGenerator)) {
it = new GraphGeneratorIterator(gens);
} else {
it = new AllGraphIterator(type,size,part);
}
ToCall f = new ToCall() {
@Override
public Object f(GraphModel g) {
return mr.calculate(g);
}
};
int[] res = null;
int fl = 0;
RenderTable pq = new RenderTable();
while (it.hasNext()) {
fl++;
GraphModel g = it.next();
if(gf!=null) if(!gf.filter(g)) continue;
if (iterative) {
getResIterLimited(f, g, it.getCount(), pq);
} else {
RenderTable ret = (RenderTable) f.f(g);
Vector<Object> vo = ret.poll();
if (res == null) {
Vector<String> tts = ret.getTitles();
tts.add("Num of Filtered Graphs");
pq.setTitles(tts);
res = new int[vo.size()];
}
for (int i = 1; i < vo.size(); i++) {
checkTypeOfBounds(vo, res, i, bound);
}
}
}
if (!iterative) {
Vector<Object> result = new Vector<>();
for (int re : res) {
result.add(re);
}
result.add(it.size());
pq.add(result);
}
return pq;
} | 9 |
public static void main(String[] args) {
try {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File(ClassLoader.getSystemResource(runXMLAUTHORITY).getFile());
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
callback, warnings);
myBatisGenerator.generate(null);
for (String warning : warnings) {
System.out.println("Warning:" + warning);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMLParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} | 6 |
public Builder name(String receivedName) {
if (receivedName == null || receivedName.equals("")) {
log.warn("Wrong Name. receivedName ={}", name);
throw new IllegalArgumentException("name must be not null. Received value = " + receivedName);
}
this.name = receivedName;
return this;
} | 2 |
private List<Area> createAreas(CodelTableModel model) {
List<Segment> segments = getSegmentsAtRow(model, 0);
if (segments == null) {
return null;
}
List<Area> areas = new ArrayList<Area>();
for (Segment segment : segments) {
Area area = new Area(segment);
areas.add(area);
}
int height = model.getHeight();
for (int y = 1; y < height; ++y) {
segments = getSegmentsAtRow(model, y);
//TODO //CHECK
if (segments == null) {
continue;
}
for (Segment segment : segments) {
for (Area area : areas) {
area.tryToMerge(segment, DELTA_DOWN);
}
if (segment.hasParents() == false) {
Area area = new Area(segment);
areas.add(area);
}
if (segment.hasManyParents() == true) {
mergeSegmentAreas(areas, segment);
}
}
}
/*for (Area area : areas) {
System.out.println(area);
System.out.println("_________________________________");
}*/
return areas;
} | 8 |
@Override
public List<String> getSuggestions(CommandInvocation invocation)
{
List<String> result = new ArrayList<>();
Class completerClass = parameter.getProperty(Properties.COMPLETER);
if (completerClass == null)
{
completerClass = parameter.getType();
}
Completer completer = invocation.getManager().getCompleter(completerClass);
if (completer != null)
{
result.addAll(completer.getSuggestions(invocation));
}
else
{
System.out.println("No completer found for " + completerClass);
}
return result;
} | 2 |
public void shootshing() {
if (waitforshoot <= 0 && shoottwice == 30) {
getWorld().addObject(new sting(), getX(), getY());
shoottwice--;
}
else if (shoottwice != 30 && shoottwice > 0) {
shoottwice--;
}
else if (shoottwice <= 0) {
getWorld().addObject(new sting(), getX(), getY());
waitforshoot = 150;
shoottwice = 30;
}
else if (waitforshoot > 0) {
waitforshoot--;
}
} | 6 |
public static double ValueCoherentNoise3D (double x, double y, double z, int seed,
NoiseQuality noiseQuality)
{
// Create a unit-length cube aligned along an integer boundary. This cube
// surrounds the input point.
int x0 = (x > 0.0? (int)x: (int)x - 1);
int x1 = x0 + 1;
int y0 = (y > 0.0? (int)y: (int)y - 1);
int y1 = y0 + 1;
int z0 = (z > 0.0? (int)z: (int)z - 1);
int z1 = z0 + 1;
// Map the difference between the coordinates of the input value and the
// coordinates of the cube's outer-lower-left vertex onto an S-curve.
double xs = 0, ys = 0, zs = 0;
switch (noiseQuality)
{
case QUALITY_FAST:
xs = (x - (double)x0);
ys = (y - (double)y0);
zs = (z - (double)z0);
break;
case QUALITY_STD:
xs = Interp.SCurve3 (x - (double)x0);
ys = Interp.SCurve3 (y - (double)y0);
zs = Interp.SCurve3 (z - (double)z0);
break;
case QUALITY_BEST:
xs = Interp.SCurve5 (x - (double)x0);
ys = Interp.SCurve5 (y - (double)y0);
zs = Interp.SCurve5 (z - (double)z0);
break;
}
// Now calculate the noise values at each vertex of the cube. To generate
// the coherent-noise value at the input point, interpolate these eight
// noise values using the S-curve value as the interpolant (trilinear
// interpolation.)
double n0, n1, ix0, ix1, iy0, iy1;
n0 = ValueNoise3D (x0, y0, z0, seed);
n1 = ValueNoise3D (x1, y0, z0, seed);
ix0 = Interp.linearInterp (n0, n1, xs);
n0 = ValueNoise3D (x0, y1, z0, seed);
n1 = ValueNoise3D (x1, y1, z0, seed);
ix1 = Interp.linearInterp (n0, n1, xs);
iy0 = Interp.linearInterp (ix0, ix1, ys);
n0 = ValueNoise3D (x0, y0, z1, seed);
n1 = ValueNoise3D (x1, y0, z1, seed);
ix0 = Interp.linearInterp (n0, n1, xs);
n0 = ValueNoise3D (x0, y1, z1, seed);
n1 = ValueNoise3D (x1, y1, z1, seed);
ix1 = Interp.linearInterp (n0, n1, xs);
iy1 = Interp.linearInterp (ix0, ix1, ys);
return Interp.linearInterp (iy0, iy1, zs);
} | 6 |
@Override
public void mousePressed(MouseEvent m) {
Wall newWall;
if(m.getButton() == 1){//front click
newWall = new Wall(new Point2D.Double(m.getX(), m.getY()), Wall.Orientation.HORIZONTAL);
}
else{
newWall = new Wall(new Point2D.Double(m.getX(), m.getY()), Wall.Orientation.VERTICAL);
}
for(Wall wall : gameField.getWalls()){
if(!wall.willFit(newWall))
return;
}
if(!gameField.willFit(newWall))
return;
gameField.getWalls().add(newWall);
} | 4 |
public CategorieMotClef findCategorieOf(MotClef mot) {
for (CategorieMotClef c : categories) {
for (MotClef m : c.getMotClefs()) {
if (m.equals(mot)) {
return c;
}
}
}
return null;
} | 3 |
private double[] getMinMax() {
double[] minmax = new double[4];
double minX;
double maxX;
double minY;
double maxY;
try {
String sql = "SELECT (\n"
+ " SELECT MIN([start-x-coord])\n"
+ " FROM correctedCoastLine\n"
+ " ) AS c1,\n"
+ " (\n"
+ " SELECT MIN([end-x-coord])\n"
+ " FROM correctedCoastLine\n"
+ " ) AS c2,\n"
+ " (\n"
+ " SELECT MAX([start-x-coord])\n"
+ " FROM correctedCoastLine\n"
+ " ) AS c3,\n"
+ " (\n"
+ " SELECT MAX([end-x-coord])\n"
+ " FROM correctedCoastLine\n"
+ " ) AS c4,\n"
+ " (\n"
+ " SELECT MIN([start-y-coord])\n"
+ " FROM correctedCoastLine\n"
+ " ) AS c5,\n"
+ " (\n"
+ " SELECT MIN([end-y-coord])\n"
+ " FROM correctedCoastLine\n"
+ " ) AS c6,\n"
+ " (\n"
+ " SELECT MAX([start-y-coord])\n"
+ " FROM correctedCoastLine\n"
+ " ) AS c7,\n"
+ " (\n"
+ " SELECT MAX([end-y-coord])\n"
+ " FROM correctedCoastLine\n"
+ " ) AS c8\n"
+ " \n"
+ "";
Connection con = cpds.getConnection();
PreparedStatement pstatement = con.prepareStatement(sql);
ResultSet rs = executeQuery(pstatement);
while (rs.next()) {
minX = Math.min(rs.getDouble(1), rs.getDouble(2));
maxX = Math.max(rs.getDouble(3), rs.getDouble(4));
minY = Math.min(rs.getDouble(5), rs.getDouble(6));
maxY = Math.max(rs.getDouble(7), rs.getDouble(8));
//To clarify what is what;
minmax[0] = minX;
minmax[1] = maxX;
minmax[2] = minY;
minmax[3] = maxY;
}
} catch (SQLException ex) {
printSQLException(ex);
} finally {
closeConnection(cons, pstatements, resultsets);
}
return minmax;
} | 2 |
@Override
public boolean extensionExists(String ext) {
Iterator it = getExtensions();
while (it.hasNext()) {
String key = (String) it.next();
if (ext.equals(key)) {
return true;
}
}
return false;
} | 2 |
public void setDayStored (Day d)
{
dayStored = new Day (d);
} | 0 |
public static boolean checkStatementExceptions(List<Statement> lst) {
Set<Statement> all = new HashSet<>(lst);
Set<Statement> handlers = new HashSet<>();
Set<Statement> intersection = null;
for (Statement stat : lst) {
Set<Statement> setNew = stat.getNeighboursSet(StatEdge.TYPE_EXCEPTION, Statement.DIRECTION_FORWARD);
if (intersection == null) {
intersection = setNew;
}
else {
HashSet<Statement> interclone = new HashSet<>(intersection);
interclone.removeAll(setNew);
intersection.retainAll(setNew);
setNew.removeAll(intersection);
handlers.addAll(interclone);
handlers.addAll(setNew);
}
}
for (Statement stat : handlers) {
if (!all.contains(stat) || !all.containsAll(stat.getNeighbours(StatEdge.TYPE_EXCEPTION, Statement.DIRECTION_BACKWARD))) {
return false;
}
}
// check for other handlers (excluding head)
for (int i = 1; i < lst.size(); i++) {
Statement stat = lst.get(i);
if (!stat.getPredecessorEdges(StatEdge.TYPE_EXCEPTION).isEmpty() && !handlers.contains(stat)) {
return false;
}
}
return true;
} | 8 |
public VuePraticiens getVue() {
return vue;
} | 0 |
static public void main(String args[]) {
double x, y;
Random rand = new Random();
String prefixletter = "ABCDEFGHJKLMNOPQRSTUVWXYZ";
double sumx, sumx2;
int nsum;
OSNI osni = new OSNI();
osni.setErrorTolerance(0.0001);
nsum = 0;
sumx = sumx2 = 0.0;
for (int i = 0; i < 10000; i++) {
x = 100000.0 * rand.nextDouble();
y = 100000.0 * rand.nextDouble();
DPoint p0 = new DPoint(x, y);
int ib;
ib = rand.nextInt() % 25;
if (ib < 0)
ib += 25;
char cb = prefixletter.charAt(ib);
DPoint dp = osni.GridSquareToOffset(cb);
p0.offsetBy(dp);
char pfx = osni.GridToGridSquare(p0);
DPoint p1 = osni.GridToLongitudeAndLatitude(p0);
double phi, lambda;
lambda = (180.0 / Math.PI) * p1.getX();
phi = (180.0 / Math.PI) * p1.getY();
System.out.println("Grid coordinates (" + cb + " " + p0.getX()
+ ", " + p0.getY() + ") map to:");
double ls = Math.abs(lambda);
double ps = Math.abs(phi);
int ld, lm, pd, pm;
ld = (int) ls;
ls = 60.0 * (ls - ld);
lm = (int) ls;
ls = 60.0 * (ls - lm);
pd = (int) ps;
ps = 60.0 * (ps - pd);
pm = (int) ps;
ps = 60.0 * (ps - pm);
System.out.print((lambda < 0.0) ? "West " : "East ");
System.out.println(ld + " " + lm + " " + ls);
System.out.print((phi < 0.0) ? "South " : "North ");
System.out.println(pd + " " + pm + " " + ps);
System.out.println("Grid letter is " + pfx);
DPoint p2 = osni.LatitudeAndLongitudeToGrid(p1);
System.out.println("Reverse transform:");
System.out.println(" Easting = " + p2.getX());
System.out.println(" Northing = " + p2.getY());
double d = p2.distanceFrom(p0);
System.out.println(" DISTANCE = " + d);
if (cb != pfx)
System.out.println("*** MISMATCH OF PREFIX ***");
if (Math.abs(d) > 0.01)
System.out.println("*** POSITION ERROR *** " + pfx + " " + d);
else {
nsum += 1;
sumx += d;
sumx2 += d * d;
}
}
sumx /= (double) nsum;
sumx2 /= (double) nsum;
sumx2 -= sumx * sumx;
sumx2 = Math.sqrt(sumx2);
System.err.println("From " + nsum + " samples, mean = " + sumx
+ " and sigma = " + sumx2);
} | 6 |
static void runParser(String inPath, String outPath) {
String cs;
try {
// open a star file, read it in
cs = readFile(inPath);
} catch (IOException e) {
print("sorry, unable to read file. aborting");
System.exit(2);
return; // what? why do I need a return here? why isn't System.exit enough?
}
// run input through the scanner
ParseResult<Character, List<Token>> tokenization = Tokenizer.SCANNER.parse(new CharStream(cs));
if(!tokenization.isSuccess()) {
print("sorry, unable to tokenize star file");
System.exit(3);
}
// have to remove whitespace, newlines, comments
List<Token> tokens = new ArrayList<Token>();
for(Token t : tokenization.getValue()) {
if(t.type == TokenType.WHITESPACE || t.type == TokenType.COMMENT || t.type == TokenType.NEWLINES) {
// ditch the token
} else {
tokens.add(t);
}
}
ParseResult<Token, DataBlock> parseTree = ASTParser.dataBlock.parse(new LListList<Token>(tokens));
if(!parseTree.isSuccess()) {
print("sorry, unable to assemble star file tokens into parse tree");
System.exit(4);
}
try {
Gson gson = new Gson();
String json = gson.toJson(parseTree.getValue());
// String json = toJsonOrSomething(parseTree);
writeFile(outPath, json);
} catch (IOException e) {
print("sorry, unable to write output to file");
System.exit(5);
}
} | 8 |
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PhpposPermissionsEntityPK that = (PhpposPermissionsEntityPK) o;
if (personId != that.personId) return false;
if (moduleId != null ? !moduleId.equals(that.moduleId) : that.moduleId != null) return false;
return true;
} | 6 |
public void edit(Applicant applicant) throws NonexistentEntityException, RollbackFailureException, Exception {
EntityManager em = null;
try {
utx.begin();
em = getEntityManager();
applicant = em.merge(applicant);
utx.commit();
} catch (Exception ex) {
try {
utx.rollback();
} catch (Exception re) {
throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
}
String msg = ex.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
Short id = applicant.getId();
if (findApplicant(id) == null) {
throw new NonexistentEntityException("The applicant with id " + id + " no longer exists.");
}
}
throw ex;
} finally {
if (em != null) {
em.close();
}
}
} | 6 |
public void updateGame()
{
//System.out.println(gameWorld.getDrawableActorGroup().getBulletGroup().getList().size());
PlaneGroup planeGroup = gameWorld.getDrawableActorGroup().getPlaneGroup();
UserPlane up = planeGroup.getUserPlane();
if(up == null)
{
//you have lost the game, restart?
}
else
{
gameWorld.slideWorldToActor(up);
ArrayList<Plane> planes = planeGroup.getList(); //THIS SHOULD BE A METHOD
boolean flag = true;
for(int i = 0;i<planes.size();i++)
{
if(planes.get(i).getTeam()!=up.getTeam()){
flag = false;
break;
}
}
if(flag)
{
up.changeLife(up.getInitiallife()); //restoring health
level++;
for(int i = 1;i<level+1;i++)
{
gameWorld.addDrawableActor(makeEnemyAIPlane());
if(i%2==1)
gameWorld.addDrawableActor(makeAllyAIPlane());
}
}
}
} | 6 |
public List<Recipe> search(String search){
Document doc = null;
try {
doc = Jsoup.connect("http://www.recept.nu/search?searchtext="+search+"&orderby=relevance").get();
} catch (IOException ex) {
Logger.getLogger(RecipeSearch.class.getName()).log(Level.SEVERE, null, ex);
}
List<Recipe> searchResult = new ArrayList<>();
Element page = doc.getElementsByClass("page").get(0);
Elements recipeContainers = page.getElementsByClass("recipie-list__container");
if (recipeContainers.size()>2) {
recipeContainers.remove(2);
}
for (Element recipeContainer : recipeContainers) {
//System.out.println(recipeContainer.html());
for (Element recipeFront : recipeContainer.getElementsByClass("recipie-list__item")) {
Recipe recipeToMake = new Recipe();
Element recipe = recipeFront.getElementsByClass("recipie-list__front").first();
//get link
Element linktag = recipe.getElementsByTag("a").first();
recipeToMake.setLink(linktag.absUrl("href"));
System.out.println(recipeToMake.getLink());
// System.out.println(recipe.html());
//Get imgURL
Elements imghtml = recipe.getElementsByTag("img");
recipeToMake.setImgUrl(imghtml.first().absUrl("data-original"));
//Get name of the recipe
recipeToMake.setName(recipe.getElementsByTag("h2").text());
searchResult.add(recipeToMake);
}
}
return searchResult;
} | 4 |
public void paint(Graphics g, int offs0, int offs1, Shape bounds,
JTextComponent c) {
Rectangle alloc = bounds.getBounds();
// Set up translucency if necessary.
Graphics2D g2d = (Graphics2D)g;
Composite originalComposite = null;
if (getAlpha()<1.0f) {
originalComposite = g2d.getComposite();
g2d.setComposite(getAlphaComposite());
}
try {
// Determine locations.
TextUI mapper = c.getUI();
Rectangle p0 = mapper.modelToView(c, offs0);
Rectangle p1 = mapper.modelToView(c, offs1);
Paint paint = getPaint();
if (paint==null)
g2d.setColor(c.getSelectionColor());
else
g2d.setPaint(paint);
// Entire highlight is on one line.
if (p0.y == p1.y) {
Rectangle r = p0.union(p1);
g2d.fillRect(r.x, r.y, r.width, r.height);
}
// Highlight spans lines.
else {
int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
g2d.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
if ((p0.y + p0.height) != p1.y) {
g2d.fillRect(alloc.x, p0.y + p0.height, alloc.width,
p1.y - (p0.y + p0.height));
}
g2d.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
}
} catch (BadLocationException e) {
// Never happens.
e.printStackTrace();
} finally {
// Restore state from before translucency if necessary.
if (getAlpha()<1.0f)
g2d.setComposite(originalComposite);
}
} | 6 |
public StackSentence(
StackSentence parent, int newWord, int[] sourceSentence,
Dictionary dict, LanguageModel langMod, LengthModel lenMod) {
if(parent == null){
words = new int[1];
} else {
words = new int[parent.words.length + 1];
System.arraycopy(parent.words, 0, words, 0, parent.words.length);
}
words[words.length - 1] = newWord;
// TODO: calc score from previous score
double bigramScore = 1f;
for(int i=0; i<words.length-1; i++){
bigramScore *= langMod.getBigramProbability(words[i], words[i+1]);
}
double lengthScore = lenMod.getLengthPairProbability(words.length, sourceSentence.length);
double dictScore = 1f;
for(int f=0; f<sourceSentence.length; f++){
if(sourceSentence[f] < 0) continue;
double targetWordScore = 0.001f;
for(int e=0; e<words.length; e++){
if(words[e] < 0) continue;
targetWordScore += dict.getTranslationScore(sourceSentence[f], words[e]);
}
dictScore *= targetWordScore;
}
score = bigramScore * lengthScore * dictScore * (double)(Math.pow(sourceSentence.length, words.length));
} | 6 |
public void waitForPeersToPopulate() {
while (!peersPopulated) {
while (manager.peers.size() < 1)
try {
Thread.sleep(10L);
} catch (InterruptedException e) {}
for (Peer p : manager.peers)
{
if (p.availablePieces.size() > 0)
{
this.peersPopulated = true;
break;
}
}
}
} | 5 |
private boolean isBlocked(int x, int y, int i, int j) {
int delta[] = {x, y};
int next[] = {i, j};
int block[] = new int[2];
int k;
for(k = 0; k < 2; k++) {
delta[k] -= next[k];
block[k] = next[k]-delta[k];
}
// it is blocked if it is out of bound
if((block[0] < 0 || block[0] >= X) ||
(block[1] < 0 || block[1] >= Y)) {
return true;
} else if(state[block[0]][block[1]] != BL)
return true;
return false;
} | 6 |
@EventHandler
public void MagmaCubeSpeed(EntityDamageByEntityEvent event) {
Entity e = event.getEntity();
Entity damager = event.getDamager();
String world = e.getWorld().getName();
boolean dodged = false;
Random random = new Random();
double randomChance = plugin.getMagmaCubeConfig().getDouble("MagmaCube.Speed.DodgeChance") / 100;
final double ChanceOfHappening = random.nextDouble();
if (ChanceOfHappening >= randomChance) {
dodged = true;
}
if (plugin.getMagmaCubeConfig().getBoolean("MagmaCube.Speed.Enabled", true) && damager instanceof MagmaCube && e instanceof Player && plugin.getConfig().getStringList("Worlds").contains(world) && !dodged) {
Player player = (Player) e;
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, plugin.getMagmaCubeConfig().getInt("MagmaCube.Speed.Time"), plugin.getMagmaCubeConfig().getInt("MagmaCube.Speed.Power")));
}
} | 6 |
private Combo findChunk(int index) {
boolean b = true;
boolean startFirst = startFirst(index);
int count;
Chunk current;
// This isn't 100% optimal, because the size of the chunks can be different, but it's not bad anyway
if (startFirst) {
count = 0;
current = firstChunk;
} else {
count = size;
current = lastChunk;
}
while (b) {
if (startFirst) {
if (count + current.getUsed() > index) {
b=false;
} else {
count = count + current.getUsed();
}
} else {
if (count - current.getUsed() < index) {
b=false;
} else {
count = count - current.getUsed();
}
}
}
int position;
if (startFirst) {
position = index - count;
} else {
position = count - (current.getUsed() - index); // TODO pas bon...
}
return new Combo(current, position);
} | 6 |
public void debug(String s) {
getConnectionProcessor().get_logger().debug(StringUtils.shortName(getClass()) + s);
} | 0 |
public void sendState(int currentState, int activeDrum)
{
//System.out.println("STATE:" + currentState);
long milliTime = (long)(parent.getCurrentUnixTime());
for(Observer o : StateListeners)
{
o.update("STATE;"+String.valueOf(currentState)+";"+String.valueOf(milliTime));
}
if(currentState == 3)
{
newLaunch = true;
try {
DatabaseUtilities.DatabaseDataObjectUtilities.addLaunchToDB(parent.getCurrentUnixTime(), parent.getCurrentUnixTime());
} catch (SQLException | ClassNotFoundException ex) {
}
}
} | 3 |
public void setZugZuende(Boolean b) {
zugZuende = b;
} | 0 |
public void agregarEntidad(final Long cantidad, final String nombre, final Double precioUnitario) {
if (DAO.listarEntidades() == null) { //Si no hay entidades se creará una arreglo que las contendrá
DAO.setEntidades(new ArrayList<Entidad>());
}
DAO.agregarEntidad(new Entidad(cantidad, nombre, precioUnitario)); //Crea una entidad y la agrega
} | 1 |
@Before
public void setUp() {
try
{
clientProxy = AqWsFactory.newAqAcqClient(TestContext.AcquisitionServiceUrl,
TestContext.User, TestContext.Pwd);
}
catch(Exception ex)
{
fail("setUp failed: " + ex.toString());
}
} | 1 |
public int compareTo(HotTestDetails comp) {
int result = 0;
if (m_minimize) {
if (m_merit == comp.m_merit) {
// larger support is better
if (m_support == comp.m_support) {
} else if (m_support > comp.m_support) {
result = -1;
} else {
result = 1;
}
} else if (m_merit < comp.m_merit) {
result = -1;
} else {
result = 1;
}
} else {
if (m_merit == comp.m_merit) {
// larger support is better
if (m_support == comp.m_support) {
} else if (m_support > comp.m_support) {
result = -1;
} else {
result = 1;
}
} else if (m_merit < comp.m_merit) {
result = 1;
} else {
result = -1;
}
}
return result;
} | 9 |
public static void main(String[] args) {
int[][] arr = {{59},{73,41},{52,40,9},{26,53,6,34},{10,51,87,86,81},{61,5,66,57,25,68},{90,81,80,38,92,67,73},{30,28,51,76,81,18,75,44},{84,14,95,87,62,81,17,78,58},{21,46,71,58,2,79,62,39,31,9},{56,34,35,53,78,31,81,18,90,93,15},{78,53,4,21,84,93,32,13,97,11,37,51},{45,3,81,79,5,18,78,86,13,30,63,99,95},{39,87,96,28,3,38,42,17,82,87,58,7,22,57},{06,17,51,17,7,93,9,7,75,97,95,78,87,8,53},{67,66,59,60,88,99,94,65,55,77,55,34,27,53,78,28},{76,40,41,4,87,16,9,42,75,69,23,97,30,60,10,79,87},{12,10,44,26,21,36,32,84,98,60,13,12,36,16,63,31,91,35},{70,39,6,5,55,27,38,48,28,22,34,35,62,62,15,14,94,89,86},{66,56,68,84,96,21,34,34,34,81,62,40,65,54,62,5,98,3,2,60},{38,89,46,37,99,54,34,53,36,14,70,26,2,90,45,13,31,61,83,73,47},{36,10,63,96,60,49,41,5,37,42,14,58,84,93,96,17,9,43,5,43,6,59},{66,57,87,57,61,28,37,51,84,73,79,15,39,95,88,87,43,39,11,86,77,74,18},{54,42,5,79,30,49,99,73,46,37,50,2,45,9,54,52,27,95,27,65,19,45,26,45},{71,39,17,78,76,29,52,90,18,99,78,19,35,62,71,19,23,65,93,85,49,33,75,9,2},{33,24,47,61,60,55,32,88,57,55,91,54,46,57,7,77,98,52,80,99,24,25,46,78,79,5},{92,9,13,55,10,67,26,78,76,82,63,49,51,31,24,68,5,57,7,54,69,21,67,43,17,63,12},{24,59,6,8,98,74,66,26,61,60,13,3,9,9,24,30,71,8,88,70,72,70,29,90,11,82,41,34},{66,82,67,4,36,60,92,77,91,85,62,49,59,61,30,90,29,94,26,41,89,4,53,22,83,41,9,74,90},{48,28,26,37,28,52,77,26,51,32,18,98,79,36,62,13,17,8,19,54,89,29,73,68,42,14,8,16,70,37},{37,60,69,70,72,71,9,59,13,60,38,13,57,36,9,30,43,89,30,39,15,2,44,73,5,73,26,63,56,86,12},{55,55,85,50,62,99,84,77,28,85,3,21,27,22,19,26,82,69,54,4,13,7,85,14,1,15,70,59,89,95,10,19},{04,9,31,92,91,38,92,86,98,75,21,5,64,42,62,84,36,20,73,42,21,23,22,51,51,79,25,45,85,53,3,43,22},{75,63,2,49,14,12,89,14,60,78,92,16,44,82,38,30,72,11,46,52,90,27,8,65,78,3,85,41,57,79,39,52,33,48},{78,27,56,56,39,13,19,43,86,72,58,95,39,7,4,34,21,98,39,15,39,84,89,69,84,46,37,57,59,35,59,50,26,15,93},{42,89,36,27,78,91,24,11,17,41,5,94,7,69,51,96,3,96,47,90,90,45,91,20,50,56,10,32,36,49,4,53,85,92,25,65},{52,9,61,30,61,97,66,21,96,92,98,90,6,34,96,60,32,69,68,33,75,84,18,31,71,50,84,63,3,3,19,11,28,42,75,45,45},{61,31,61,68,96,34,49,39,5,71,76,59,62,67,6,47,96,99,34,21,32,47,52,7,71,60,42,72,94,56,82,83,84,40,94,87,82,46},{01,20,60,14,17,38,26,78,66,81,45,95,18,51,98,81,48,16,53,88,37,52,69,95,72,93,22,34,98,20,54,27,73,61,56,63,60,34,63},{93,42,94,83,47,61,27,51,79,79,45,1,44,73,31,70,83,42,88,25,53,51,30,15,65,94,80,44,61,84,12,77,2,62,2,65,94,42,14,94},{32,73,9,67,68,29,74,98,10,19,85,48,38,31,85,67,53,93,93,77,47,67,39,72,94,53,18,43,77,40,78,32,29,59,24,6,2,83,50,60,66},{32,1,44,30,16,51,15,81,98,15,10,62,86,79,50,62,45,60,70,38,31,85,65,61,64,6,69,84,14,22,56,43,9,48,66,69,83,91,60,40,36,61},{92,48,22,99,15,95,64,43,1,16,94,2,99,19,17,69,11,58,97,56,89,31,77,45,67,96,12,73,8,20,36,47,81,44,50,64,68,85,40,81,85,52,9},{91,35,92,45,32,84,62,15,19,64,21,66,6,1,52,80,62,59,12,25,88,28,91,50,40,16,22,99,92,79,87,51,21,77,74,77,7,42,38,42,74,83,2,5},{46,19,77,66,24,18,5,32,2,84,31,99,92,58,96,72,91,36,62,99,55,29,53,42,12,37,26,58,89,50,66,19,82,75,12,48,24,87,91,85,2,7,3,76,86},{99,98,84,93,7,17,33,61,92,20,66,60,24,66,40,30,67,5,37,29,24,96,3,27,70,62,13,4,45,47,59,88,43,20,66,15,46,92,30,4,71,66,78,70,53,99},{67,60,38,6,88,4,17,72,10,99,71,7,42,25,54,5,26,64,91,50,45,71,6,30,67,48,69,82,8,56,80,67,18,46,66,63,1,20,8,80,47,7,91,16,3,79,87},{18,54,78,49,80,48,77,40,68,23,60,88,58,80,33,57,11,69,55,53,64,2,94,49,60,92,16,35,81,21,82,96,25,24,96,18,2,5,49,3,50,77,6,32,84,27,18,38},{68,1,50,4,3,21,42,94,53,24,89,5,92,26,52,36,68,11,85,1,4,42,2,45,15,6,50,4,53,73,25,74,81,88,98,21,67,84,79,97,99,20,95,4,40,46,2,58,87},{94,10,2,78,88,52,21,3,88,60,6,53,49,71,20,91,12,65,7,49,21,22,11,41,58,99,36,16,9,48,17,24,52,36,23,15,72,16,84,56,2,99,43,76,81,71,29,39,49,17},{64,39,59,84,86,16,17,66,3,9,43,6,64,18,63,29,68,6,23,7,87,14,26,35,17,12,98,41,53,64,78,18,98,27,28,84,80,67,75,62,10,11,76,90,54,10,5,54,41,39,66},{43,83,18,37,32,31,52,29,95,47,8,76,35,11,4,53,35,43,34,10,52,57,12,36,20,39,40,55,78,44,7,31,38,26,8,15,56,88,86,1,52,62,10,24,32,5,60,65,53,28,57,99},{03,50,3,52,7,73,49,92,66,80,1,46,8,67,25,36,73,93,7,42,25,53,13,96,76,83,87,90,54,89,78,22,78,91,73,51,69,9,79,94,83,53,9,40,69,62,10,79,49,47,3,81,30},{71,54,73,33,51,76,59,54,79,37,56,45,84,17,62,21,98,69,41,95,65,24,39,37,62,3,24,48,54,64,46,82,71,78,33,67,9,16,96,68,52,74,79,68,32,21,13,78,96,60,9,69,20,36},{73,26,21,44,46,38,17,83,65,98,7,23,52,46,61,97,33,13,60,31,70,15,36,77,31,58,56,93,75,68,21,36,69,53,90,75,25,82,39,50,65,94,29,30,11,33,11,13,96,2,56,47,7,49,2},{76,46,73,30,10,20,60,70,14,56,34,26,37,39,48,24,55,76,84,91,39,86,95,61,50,14,53,93,64,67,37,31,10,84,42,70,48,20,10,72,60,61,84,79,69,65,99,73,89,25,85,48,92,56,97,16},{03,14,80,27,22,30,44,27,67,75,79,32,51,54,81,29,65,14,19,4,13,82,4,91,43,40,12,52,29,99,7,76,60,25,1,7,61,71,37,92,40,47,99,66,57,1,43,44,22,40,53,53,9,69,26,81,7},{49,80,56,90,93,87,47,13,75,28,87,23,72,79,32,18,27,20,28,10,37,59,21,18,70,4,79,96,3,31,45,71,81,6,14,18,17,5,31,50,92,79,23,47,9,39,47,91,43,54,69,47,42,95,62,46,32,85},{37,18,62,85,87,28,64,5,77,51,47,26,30,65,5,70,65,75,59,80,42,52,25,20,44,10,92,17,71,95,52,14,77,13,24,55,11,65,26,91,1,30,63,15,49,48,41,17,67,47,3,68,20,90,98,32,4,40,68},{90,51,58,60,6,55,23,68,5,19,76,94,82,36,96,43,38,90,87,28,33,83,5,17,70,83,96,93,6,4,78,47,80,6,23,84,75,23,87,72,99,14,50,98,92,38,90,64,61,58,76,94,36,66,87,80,51,35,61,38},{57,95,64,6,53,36,82,51,40,33,47,14,7,98,78,65,39,58,53,6,50,53,4,69,40,68,36,69,75,78,75,60,3,32,39,24,74,47,26,90,13,40,44,71,90,76,51,24,36,50,25,45,70,80,61,80,61,43,90,64,11},{18,29,86,56,68,42,79,10,42,44,30,12,96,18,23,18,52,59,2,99,67,46,60,86,43,38,55,17,44,93,42,21,55,14,47,34,55,16,49,24,23,29,96,51,55,10,46,53,27,92,27,46,63,57,30,65,43,27,21,20,24,83},{81,72,93,19,69,52,48,1,13,83,92,69,20,48,69,59,20,62,5,42,28,89,90,99,32,72,84,17,8,87,36,3,60,31,36,36,81,26,97,36,48,54,56,56,27,16,91,8,23,11,87,99,33,47,2,14,44,73,70,99,43,35,33},{90,56,61,86,56,12,70,59,63,32,1,15,81,47,71,76,95,32,65,80,54,70,34,51,40,45,33,4,64,55,78,68,88,47,31,47,68,87,3,84,23,44,89,72,35,8,31,76,63,26,90,85,96,67,65,91,19,14,17,86,4,71,32,95},{37,13,4,22,64,37,37,28,56,62,86,33,7,37,10,44,52,82,52,6,19,52,57,75,90,26,91,24,6,21,14,67,76,30,46,14,35,89,89,41,3,64,56,97,87,63,22,34,3,79,17,45,11,53,25,56,96,61,23,18,63,31,37,37,47},{77,23,26,70,72,76,77,4,28,64,71,69,14,85,96,54,95,48,6,62,99,83,86,77,97,75,71,66,30,19,57,90,33,1,60,61,14,12,90,99,32,77,56,41,18,14,87,49,10,14,90,64,18,50,21,74,14,16,88,5,45,73,82,47,74,44},{22,97,41,13,34,31,54,61,56,94,3,24,59,27,98,77,4,9,37,40,12,26,87,9,71,70,7,18,64,57,80,21,12,71,83,94,60,39,73,79,73,19,97,32,64,29,41,7,48,84,85,67,12,74,95,20,24,52,41,67,56,61,29,93,35,72,69},{72,23,63,66,1,11,7,30,52,56,95,16,65,26,83,90,50,74,60,18,16,48,43,77,37,11,99,98,30,94,91,26,62,73,45,12,87,73,47,27,1,88,66,99,21,41,95,80,2,53,23,32,61,48,32,43,43,83,14,66,95,91,19,81,80,67,25,88},{8,62,32,18,92,14,83,71,37,96,11,83,39,99,5,16,23,27,10,67,2,25,44,11,55,31,46,64,41,56,44,74,26,81,51,31,45,85,87,9,81,95,22,28,76,69,46,48,64,87,67,76,27,89,31,11,74,16,62,3,60,94,42,47,9,34,94,93,72},{56,18,90,18,42,17,42,32,14,86,6,53,33,95,99,35,29,15,44,20,49,59,25,54,34,59,84,21,23,54,35,90,78,16,93,13,37,88,54,19,86,67,68,55,66,84,65,42,98,37,87,56,33,28,58,38,28,38,66,27,52,21,81,15,8,22,97,32,85,27},{91,53,40,28,13,34,91,25,1,63,50,37,22,49,71,58,32,28,30,18,68,94,23,83,63,62,94,76,80,41,90,22,82,52,29,12,18,56,10,8,35,14,37,57,23,65,67,40,72,39,93,39,70,89,40,34,7,46,94,22,20,5,53,64,56,30,5,56,61,88,27},{23,95,11,12,37,69,68,24,66,10,87,70,43,50,75,7,62,41,83,58,95,93,89,79,45,39,2,22,5,22,95,43,62,11,68,29,17,40,26,44,25,71,87,16,70,85,19,25,59,94,90,41,41,80,61,70,55,60,84,33,95,76,42,63,15,9,3,40,38,12,3,32},{9,84,56,80,61,55,85,97,16,94,82,94,98,57,84,30,84,48,93,90,71,5,95,90,73,17,30,98,40,64,65,89,7,79,9,19,56,36,42,30,23,69,73,72,7,5,27,61,24,31,43,48,71,84,21,28,26,65,65,59,65,74,77,20,10,81,61,84,95,8,52,23,70},{47,81,28,9,98,51,67,64,35,51,59,36,92,82,77,65,80,24,72,53,22,7,27,10,21,28,30,22,48,82,80,48,56,20,14,43,18,25,50,95,90,31,77,8,9,48,44,80,90,22,93,45,82,17,13,96,25,26,8,73,34,99,6,49,24,6,83,51,40,14,15,10,25,1},{54,25,10,81,30,64,24,74,75,80,36,75,82,60,22,69,72,91,45,67,3,62,79,54,89,74,44,83,64,96,66,73,44,30,74,50,37,5,9,97,70,1,60,46,37,91,39,75,75,18,58,52,72,78,51,81,86,52,8,97,1,46,43,66,98,62,81,18,70,93,73,8,32,46,34},{96,80,82,7,59,71,92,53,19,20,88,66,3,26,26,10,24,27,50,82,94,73,63,8,51,33,22,45,19,13,58,33,90,15,22,50,36,13,55,6,35,47,82,52,33,61,36,27,28,46,98,14,73,20,73,32,16,26,80,53,47,66,76,38,94,45,2,1,22,52,47,96,64,58,52,39},{88,46,23,39,74,63,81,64,20,90,33,33,76,55,58,26,10,46,42,26,74,74,12,83,32,43,9,2,73,55,86,54,85,34,28,23,29,79,91,62,47,41,82,87,99,22,48,90,20,5,96,75,95,4,43,28,81,39,81,1,28,42,78,25,39,77,90,57,58,98,17,36,73,22,63,74,51},{29,39,74,94,95,78,64,24,38,86,63,87,93,6,70,92,22,16,80,64,29,52,20,27,23,50,14,13,87,15,72,96,81,22,8,49,72,30,70,24,79,31,16,64,59,21,89,34,96,91,48,76,43,53,88,1,57,80,23,81,90,79,58,1,80,87,17,99,86,90,72,63,32,69,14,28,88,69},{37,17,71,95,56,93,71,35,43,45,4,98,92,94,84,96,11,30,31,27,31,60,92,3,48,5,98,91,86,94,35,90,90,8,48,19,33,28,68,37,59,26,65,96,50,68,22,7,9,49,34,31,77,49,43,6,75,17,81,87,61,79,52,26,27,72,29,50,7,98,86,1,17,10,46,64,24,18,56},{51,30,25,94,88,85,79,91,40,33,63,84,49,67,98,92,15,26,75,19,82,5,18,78,65,93,61,48,91,43,59,41,70,51,22,15,92,81,67,91,46,98,11,11,65,31,66,10,98,65,83,21,5,56,5,98,73,67,46,74,69,34,8,30,5,52,7,98,32,95,30,94,65,50,24,63,28,81,99,57},{19,23,61,36,9,89,71,98,65,17,30,29,89,26,79,74,94,11,44,48,97,54,81,55,39,66,69,45,28,47,13,86,15,76,74,70,84,32,36,33,79,20,78,14,41,47,89,28,81,5,99,66,81,86,38,26,6,25,13,60,54,55,23,53,27,5,89,25,23,11,13,54,59,54,56,34,16,24,53,44,6},{13,40,57,72,21,15,60,8,4,19,11,98,34,45,9,97,86,71,3,15,56,19,15,44,97,31,90,4,87,87,76,8,12,30,24,62,84,28,12,85,82,53,99,52,13,94,6,65,97,86,9,50,94,68,69,74,30,67,87,94,63,7,78,27,80,36,69,41,6,92,32,78,37,82,30,5,18,87,99,72,19,99},{44,20,55,77,69,91,27,31,28,81,80,27,2,7,97,23,95,98,12,25,75,29,47,71,7,47,78,39,41,59,27,76,13,15,66,61,68,35,69,86,16,53,67,63,99,85,41,56,8,28,33,40,94,76,90,85,31,70,24,65,84,65,99,82,19,25,54,37,21,46,33,2,52,99,51,33,26,4,87,2,8,18,96},{54,42,61,45,91,6,64,79,80,82,32,16,83,63,42,49,19,78,65,97,40,42,14,61,49,34,4,18,25,98,59,30,82,72,26,88,54,36,21,75,3,88,99,53,46,51,55,78,22,94,34,40,68,87,84,25,30,76,25,8,92,84,42,61,40,38,9,99,40,23,29,39,46,55,10,90,35,84,56,70,63,23,91,39},{52,92,3,71,89,7,9,37,68,66,58,20,44,92,51,56,13,71,79,99,26,37,2,6,16,67,36,52,58,16,79,73,56,60,59,27,44,77,94,82,20,50,98,33,9,87,94,37,40,83,64,83,58,85,17,76,53,2,83,52,22,27,39,20,48,92,45,21,9,42,24,23,12,37,52,28,50,78,79,20,86,62,73,20,59},{54,96,80,15,91,90,99,70,10,9,58,90,93,50,81,99,54,38,36,10,30,11,35,84,16,45,82,18,11,97,36,43,96,79,97,65,40,48,23,19,17,31,64,52,65,65,37,32,65,76,99,79,34,65,79,27,55,33,3,1,33,27,61,28,66,8,4,70,49,46,48,83,1,45,19,96,13,81,14,21,31,79,93,85,50,5},{92,92,48,84,59,98,31,53,23,27,15,22,79,95,24,76,5,79,16,93,97,89,38,89,42,83,2,88,94,95,82,21,1,97,48,39,31,78,9,65,50,56,97,61,1,7,65,27,21,23,14,15,80,97,44,78,49,35,33,45,81,74,34,5,31,57,9,38,94,7,69,54,69,32,65,68,46,68,78,90,24,28,49,51,45,86,35},{41,63,89,76,87,31,86,9,46,14,87,82,22,29,47,16,13,10,70,72,82,95,48,64,58,43,13,75,42,69,21,12,67,13,64,85,58,23,98,9,37,76,5,22,31,12,66,50,29,99,86,72,45,25,10,28,19,6,90,43,29,31,67,79,46,25,74,14,97,35,76,37,65,46,23,82,6,22,30,76,93,66,94,17,96,13,20,72},{63,40,78,8,52,9,90,41,70,28,36,14,46,44,85,96,24,52,58,15,87,37,5,98,99,39,13,61,76,38,44,99,83,74,90,22,53,80,56,98,30,51,63,39,44,30,91,91,4,22,27,73,17,35,53,18,35,45,54,56,27,78,48,13,69,36,44,38,71,25,30,56,15,22,73,43,32,69,59,25,93,83,45,11,34,94,44,39,92},{12,36,56,88,13,96,16,12,55,54,11,47,19,78,17,17,68,81,77,51,42,55,99,85,66,27,81,79,93,42,65,61,69,74,14,1,18,56,12,1,58,37,91,22,42,66,83,25,19,4,96,41,25,45,18,69,96,88,36,93,10,12,98,32,44,83,83,4,72,91,4,27,73,7,34,37,71,60,59,31,1,54,54,44,96,93,83,36,4,45},{30,18,22,20,42,96,65,79,17,41,55,69,94,81,29,80,91,31,85,25,47,26,43,49,2,99,34,67,99,76,16,14,15,93,8,32,99,44,61,77,67,50,43,55,87,55,53,72,17,46,62,25,50,99,73,5,93,48,17,31,70,80,59,9,44,59,45,13,74,66,58,94,87,73,16,14,85,38,74,99,64,23,79,28,71,42,20,37,82,31,23},{51,96,39,65,46,71,56,13,29,68,53,86,45,33,51,49,12,91,21,21,76,85,2,17,98,15,46,12,60,21,88,30,92,83,44,59,42,50,27,88,46,86,94,73,45,54,23,24,14,10,94,21,20,34,23,51,4,83,99,75,90,63,60,16,22,33,83,70,11,32,10,50,29,30,83,46,11,5,31,17,86,42,49,1,44,63,28,60,7,78,95,40},{44,61,89,59,4,49,51,27,69,71,46,76,44,4,9,34,56,39,15,6,94,91,75,90,65,27,56,23,74,6,23,33,36,69,14,39,5,34,35,57,33,22,76,46,56,10,61,65,98,9,16,69,4,62,65,18,99,76,49,18,72,66,73,83,82,40,76,31,89,91,27,88,17,35,41,35,32,51,32,67,52,68,74,85,80,57,7,11,62,66,47,22,67},{65,37,19,97,26,17,16,24,24,17,50,37,64,82,24,36,32,11,68,34,69,31,32,89,79,93,96,68,49,90,14,23,4,4,67,99,81,74,70,74,36,96,68,9,64,39,88,35,54,89,96,58,66,27,88,97,32,14,6,35,78,20,71,6,85,66,57,2,58,91,72,5,29,56,73,48,86,52,9,93,22,57,79,42,12,1,31,68,17,59,63,76,7,77},{73,81,14,13,17,20,11,9,1,83,8,85,91,70,84,63,62,77,37,7,47,1,59,95,39,69,39,21,99,9,87,2,97,16,92,36,74,71,90,66,33,73,73,75,52,91,11,12,26,53,5,26,26,48,61,50,90,65,1,87,42,47,74,35,22,73,24,26,56,70,52,5,48,41,31,18,83,27,21,39,80,85,26,8,44,2,71,7,63,22,5,52,19,8,20},{17,25,21,11,72,93,33,49,64,23,53,82,3,13,91,65,85,2,40,5,42,31,77,42,5,36,6,54,4,58,7,76,87,83,25,57,66,12,74,33,85,37,74,32,20,69,3,97,91,68,82,44,19,14,89,28,85,85,80,53,34,87,58,98,88,78,48,65,98,40,11,57,10,67,70,81,60,79,74,72,97,59,79,47,30,20,54,80,89,91,14,5,33,36,79,39},{60,85,59,39,60,7,57,76,77,92,6,35,15,72,23,41,45,52,95,18,64,79,86,53,56,31,69,11,91,31,84,50,44,82,22,81,41,40,30,42,30,91,48,94,74,76,64,58,74,25,96,57,14,19,3,99,28,83,15,75,99,1,89,85,79,50,3,95,32,67,44,8,7,41,62,64,29,20,14,76,26,55,48,71,69,66,19,72,44,25,14,1,48,74,12,98,7},{64,66,84,24,18,16,27,48,20,14,47,69,30,86,48,40,23,16,61,21,51,50,26,47,35,33,91,28,78,64,43,68,4,79,51,8,19,60,52,95,6,68,46,86,35,97,27,58,4,65,30,58,99,12,12,75,91,39,50,31,42,64,70,4,46,7,98,73,98,93,37,89,77,91,64,71,64,65,66,21,78,62,81,74,42,20,83,70,73,95,78,45,92,27,34,53,71,15},{30,11,85,31,34,71,13,48,5,14,44,3,19,67,23,73,19,57,6,90,94,72,57,69,81,62,59,68,88,57,55,69,49,13,7,87,97,80,89,5,71,5,5,26,38,40,16,62,45,99,18,38,98,24,21,26,62,74,69,4,85,57,77,35,58,67,91,79,79,57,86,28,66,34,72,51,76,78,36,95,63,90,8,78,47,63,45,31,22,70,52,48,79,94,15,77,61,67,68},{23,33,44,81,80,92,93,75,94,88,23,61,39,76,22,3,28,94,32,6,49,65,41,34,18,23,8,47,62,60,3,63,33,13,80,52,31,54,73,43,70,26,16,69,57,87,83,31,3,93,70,81,47,95,77,44,29,68,39,51,56,59,63,7,25,70,7,77,43,53,64,3,94,42,95,39,18,1,66,21,16,97,20,50,90,16,70,10,95,69,29,6,25,61,41,26,15,59,63,35}};
int[][] resArr = new int[100][101];
resArr[0][0] = arr[0][0];
for(int i = 1; i < 100; i++)
{
for(int j = 0; j <= i; j++)
{
if(j != 0)
{
if(resArr[i-1][j-1] < resArr[i-1][j])
resArr[i][j] = arr[i][j] + resArr[i-1][j];
else
resArr[i][j] = arr[i][j] + resArr[i-1][j-1];
}
else
resArr[i][j] = arr[i][j] + resArr[i-1][j];
}
}
int res = 0;
for(int i = 0; i < 100; i++)
{
if(resArr[99][i] > res)
res = resArr[99][i];
}
System.out.println(res);
} | 6 |
public void rotate(double angle, int axis) {
if (axis != X_AXIS && axis != Y_AXIS && axis != Z_AXIS)
return;
double cosAngle = Math.cos(angle);
double sinAngle = Math.sin(angle);
double xNew, yNew, zNew;
switch (axis) {
case X_AXIS:
yNew = y * cosAngle + z * sinAngle;
zNew = -y * sinAngle + z * cosAngle;
y = yNew;
z = zNew;
break;
case Y_AXIS:
zNew = z * cosAngle + x * sinAngle;
xNew = -z * sinAngle + x * cosAngle;
z = zNew;
x = xNew;
break;
case Z_AXIS:
xNew = x * cosAngle + y * sinAngle;
yNew = -x * sinAngle + y * cosAngle;
x = xNew;
y = yNew;
break;
}
} | 6 |
public void clearHalt () throws IOException
{
if ("bulk" != getType ())
throw new IllegalArgumentException ();
// this affects the USB data toggle and other HCD state,
// otherwise we could issue control requests directly
if (spi == null)
spi = iface.getDevice ().getSPI ();
spi.clearHalt ((byte) (0x8f & getU8 (2)));
} | 2 |
public static List<String> getStringListValue(String nodeValue) {
List<String> values = new ArrayList<String>();
for(String part : nodeValue.split(",")) {
String value = part.trim();
if(value.isEmpty())
continue;
values.add(value);
}
return Collections.unmodifiableList(values);
} | 2 |
static double log2ScaleExp(double[] xs) {
if (xs.length == 0) return 0.0;
double max = xs[0];
for (int i = 1; i < xs.length; ++i)
if (max < xs[i]) max = xs[i];
if (max < 0.0 || max > 1.0) {
String msg = "Max must be >= 0 and <= 1."
+ " Found max=" + max;
throw new IllegalArgumentException(msg);
}
if (max == 0.0) return 0.0;
// can't we just do this analytically?
double exp = 0.0;
double mult = 1.0;
while (max < 0.5) {
exp -= 1.0;
mult *= 2.0;
max *= 2.0;
}
for (int j = 0; j < xs.length; ++j)
xs[j] = xs[j] * mult;
if (exp > 0) {
String msg = "Exponent must be <= 0."
+ " Found exp=" + exp;
throw new IllegalArgumentException(msg);
}
return exp;
} | 9 |
protected static Item possibleContainer(MOB mob, List<String> commands, boolean withStuff, Filterer<Environmental> filter)
{
if((commands==null)||(commands.size()<2))
return null;
final String possibleContainerID=commands.get(commands.size()-1);
final Environmental thisThang=mob.location().fetchFromMOBRoomFavorsItems(mob,null,possibleContainerID,filter);
if((thisThang!=null)
&&(thisThang instanceof Item)
&&(((Item)thisThang) instanceof Container)
&&((!withStuff)||(((Container)thisThang).hasContent())))
{
commands.remove(commands.size()-1);
return (Item)thisThang;
}
return null;
} | 7 |
private void readyForTermination() {
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
currentState.processKeyPressed(e);
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_ESCAPE
|| keyCode == KeyEvent.VK_Q
|| keyCode == KeyEvent.VK_END) {
logger.log(Level.INFO, "End key pressed. Key code: {0}", keyCode);
running = false;
}
}
@Override
public void keyReleased(KeyEvent e){
currentState.processKeyReleased(e);
}
});
} | 3 |
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
} | 6 |
public static int longestValidParentheses(String s) {
String[] parts = s.split("");
int len = parts.length;
int[] position = new int[len-1];
int left = 0;
Stack<Integer> right = new Stack<Integer>();
for(int i=1;i<len;i++) {
position[i-1] = -1;
if(parts[i].equals("(")) {
left++;
right.push(i-1);
}else {
if(left!=0) {
left--;
int nextPosition = right.pop();
position[nextPosition] = i-1;
}
}
}
int max = 0;
int tmp = 0;
for(int i=0;i<len-1;i++) {
if(position[i]!= -1) {
tmp = tmp + (position[i]-i+1);
i = position[i];
if(tmp > max) {
max = tmp;
}
}else {
if(tmp > max) {
max = tmp;
}
tmp = 0;
}
}
if(tmp > max) {
max = tmp;
}
return max;
} | 8 |
public void paintComponent(Graphics g)
{
BufferedImage spriteSheet = null,engine;
BufferedImageLoader loader = new BufferedImageLoader();
try {
spriteSheet = loader.loadImage("images/Ship_Shop/shipshopparts.png");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// the following two lines are needed because calling the paint overrides the background color
this.setBackground(Color.black);
g.fillRect(265, 200, 600, 300);
g.setColor(Color.white);
if(Main.ShipShopEnginesMenu.selectionOvalX == 340)
{
engine = spriteSheet.getSubimage(80, 4, 19, 30);
g.drawImage(engine,515, 250, 76, 120,this);
if(Main.Player1.Ship.Ship_Engine.check_purchased_engines(0) == 1)
{
g.setFont(new Font("Serif",Font.PLAIN,48));
g.drawString("Equip This Engine?",400,235);
g.setFont(new Font("Serif",Font.PLAIN,25));
g.drawString("Equip Part", 315, 494);
}
else
{
g.setFont(new Font("Serif",Font.PLAIN,48));
g.drawString("Confirm Your Engine Purchase",265,235);
g.setFont(new Font("Serif",Font.PLAIN,25));
g.drawString("Buy and Equip Part", 265, 494);
}
}
else if(Main.ShipShopEnginesMenu.selectionOvalX == 540)
{
if(Main.Player1.Ship.Ship_Engine.check_purchased_engines(1) == 1)
{
g.setFont(new Font("Serif",Font.PLAIN,48));
g.drawString("Equip This Engine?",400,235);
g.setFont(new Font("Serif",Font.PLAIN,25));
g.drawString("Equip Part", 315, 494);
}
else
{
g.setFont(new Font("Serif",Font.PLAIN,48));
g.drawString("Confirm Your Engine Purchase",265,235);
g.setFont(new Font("Serif",Font.PLAIN,25));
g.drawString("Buy and Equip Part", 265, 494);
}
engine = spriteSheet.getSubimage(46, 5, 25, 29);
g.drawImage(engine,500, 250, 100, 116,this);
}
else if(Main.ShipShopEnginesMenu.selectionOvalX == 740)
{
if(Main.Player1.Ship.Ship_Engine.check_purchased_engines(2) == 1)
{
g.setFont(new Font("Serif",Font.PLAIN,48));
g.drawString("Equip This Engine?",400,235);
g.setFont(new Font("Serif",Font.PLAIN,25));
g.drawString("Equip Part", 315, 494);
}
else
{
g.setFont(new Font("Serif",Font.PLAIN,48));
g.drawString("Confirm Your Engine Purchase",265,235);
g.setFont(new Font("Serif",Font.PLAIN,25));
g.drawString("Buy and Equip Part", 265, 494);
}
engine = spriteSheet.getSubimage(2, 5, 26, 30);
g.drawImage(engine,515, 250, 104, 120,this);
}
g.drawString("Cancel",750, 494);
g.drawOval(selectionOvalX, selectionOvalY, selectionOvalHeight, selectionOvalWidth);
} | 7 |
private void handleInput(){
camera.doKeyboardControl();
camera.doMouseControl();
while (Keyboard.next()){
if (Keyboard.getEventKey() == Keyboard.KEY_Q){
System.exit(0);
}
}
while (Mouse.next()){
if (Mouse.getEventButtonState() && Mouse.getEventButton() == 2){
Mouse.setGrabbed(!Mouse.isGrabbed());
}
}
} | 5 |
protected void setList(List list)
throws IteratorException {
this.list = list;
if (list != null) {
listIterator = list.listIterator();
} else {
throw new IteratorException();
}
} | 1 |
public void setMinValue(double minValue, boolean filterArchivedValues)
throws IOException, RrdException {
double maxValue = this.maxValue.get();
if(!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) {
throw new RrdException("Invalid min/max values: " + minValue + "/" + maxValue);
}
this.minValue.set(minValue);
if(!Double.isNaN(minValue) && filterArchivedValues) {
int dsIndex = getDsIndex();
Archive[] archives = parentDb.getArchives();
for(int i = 0; i < archives.length; i++) {
archives[i].getRobin(dsIndex).filterValues(minValue, Double.NaN);
}
}
} | 6 |
private static void renameAndTrimBackups() {
File directory = new File(DatabaseWrapper.storagePath + "Backup/");
ArrayList<Path> paths = new ArrayList<>();
if (!directory.exists()) {
try {
Files.createDirectory(directory.toPath());
} catch (IOException ex) {
Logger.getLogger(AwanaDatabase.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
try {
DirectoryStream<Path> stream = Files.newDirectoryStream(FileSystems.getDefault().getPath(DatabaseWrapper.storagePath + "Backup/"), "*.back");
for (Path p : stream) {
paths.add(p);
Logger.getGlobal().log(Level.INFO, p.toString());
}
stream.close();
if (!paths.isEmpty()) {
for (int i = paths.size(); i > 0; i--) {
File file = paths.get(i - 1).toFile();
System.out.println(file.getPath());
if (i >= backupCutoff) {
file.delete();
} else {
File FileR = FileSystems.getDefault().getPath(file.getPath().substring(0, file.getPath().lastIndexOf("db") + 3).concat(i + ".back")).toFile();
file.renameTo(FileR);
}
}
}
} catch (IOException ex) {
Logger.getGlobal().log(Level.SEVERE, null, ex);
}
}
} | 7 |
public static HashMap<String, Profile> loadProfiles() {
LOGGER.log(Level.INFO, "Loading player profiles..");
HashMap<String, Profile> profiles = new HashMap<String, Profile>();
File[] proFiles = new File("profiles").listFiles();
for (File file : proFiles) {
try {
if (!file.getCanonicalPath().endsWith(".json")) { continue; }
Profile profile = new Profile((JSONObject) new JSONParser().parse(new FileReader(file)));
LOGGER.log(Level.INFO, "Loaded player '" + profile.getUsername() + "'");
profiles.put(profile.getUsername(), profile);
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, null, ex);
} catch (org.json.simple.parser.ParseException e) { e.printStackTrace(); }
}
LOGGER.log(Level.INFO, "Finished loading profiles");
return profiles;
} | 4 |
@Override
public Iterator<T> iterator() {
return new Iterator<T>(){
private int pos = 0;
public boolean hasNext() {
return pos < size;
}
@SuppressWarnings("unchecked")
public T next() {
if(hasNext())
return (T)array[pos++];
else
throw new NoSuchElementException("Pas de suivant");
}
public void remove(){
if(pos == 0)
throw new IllegalStateException("next() n'a pas été appelé!");
else if(size-1 == 0){
array = new Object[1];
array[0] = null;
size--;
}
else{
System.arraycopy(array, pos, array, pos-1, size-1-pos-1);
array[--size] = null;
}
}
};
} | 3 |
public void populateTasks(File tasks)
{
try
{
Scanner fileInput = new Scanner(tasks);
int level = 0;
char group = 0;
String name = "";
String token = "";
while (fileInput.hasNextLine())
{
token = fileInput.next();
if (!token.equals(""))
name = token;
token = fileInput.next();
if (!token.equals(""))
group = token.charAt(0);
token = fileInput.next();
if (!token.equals(""))
level = Integer.parseInt(token);
this.PQ.add(new Task(name, group, level));
}
fileInput.close();
//this.PQ.generateDotFile("tasks.dot");
}
catch (FileNotFoundException e)
{
System.err.println("File " + tasks + " cannot be found.");
}
} | 5 |
private void printBuffersStatus() {
System.out.println("{sendBuffer:" + sendBuffer.size() + " receiveBuffer:" + receiveBuffer.size()
+ " inputQueue:" + inputQueue.size() + "}");
System.out.println("------------------------------------------------");
} | 0 |
protected boolean checkCDATA(StringBuffer buf)
throws IOException
{
char ch = this.readChar();
if (ch != '[') {
this.unreadChar(ch);
this.skipSpecialTag(0);
return false;
} else if (! this.checkLiteral("CDATA[")) { //$NON-NLS-1$
this.skipSpecialTag(1); // one [ has already been read
return false;
} else {
int delimiterCharsSkipped = 0;
while (delimiterCharsSkipped < 3) {
ch = this.readChar();
switch (ch) {
case ']':
if (delimiterCharsSkipped < 2) {
delimiterCharsSkipped += 1;
} else {
buf.append(']');
buf.append(']');
delimiterCharsSkipped = 0;
}
break;
case '>':
if (delimiterCharsSkipped < 2) {
for (int i = 0; i < delimiterCharsSkipped; i++) {
buf.append(']');
}
delimiterCharsSkipped = 0;
buf.append('>');
} else {
delimiterCharsSkipped = 3;
}
break;
default:
for (int i = 0; i < delimiterCharsSkipped; i += 1) {
buf.append(']');
}
buf.append(ch);
delimiterCharsSkipped = 0;
}
}
return true;
}
} | 9 |
public Integer getId() {
return id;
} | 0 |
public boolean isValidKill(Player p){
String pName = p.getName().toLowerCase();
if(this.recentKills.containsKey(pName)){
long lastKill = recentKills.get(pName);
if(lastKill + 60000 > System.currentTimeMillis()){
//Killed them in the last 60 seconds.
return false;
}
}
Player m = this.getPlayer();
if(p.getAddress() == null || m.getAddress().getAddress().getHostAddress().equals(p.getAddress().getAddress().getHostAddress())){
return false;
}
KarmaPlayer vic = plugin.getKarmaPlayer(p);
//If my kdr is over 3x their kdr, and i have 5 more kills than them at least, its not valid.
if(vic.getKDR() * 3 < this.getKDR() && this.getTotalKills() - 5 > vic.getTotalKills()){
return false;
}
return true;
} | 6 |
public JTextField getjTextFieldNom() {
return jTextFieldNom;
} | 0 |
public void update(float delta)
{
System.out.println(x+" "+y);
if(moving)
{
progress=Math.min(1, progress+speed*delta);
}
if(progress==1)
{
progress=0;
moving=false;
switch(dir)
{
case NORTH:
y--;
break;
case SOUTH:
y++;
break;
case WEST:
x--;
break;
case EAST:
x++;
}
}
} | 6 |
private void BroadcastAddMember(final DataPacket<AddMember> dp) {
//TODO delete after test
System.out.println("BroadCast AddMember begin");
String peopleOnline = "";
String peopleOffline = "";
String senderIdentity = dp.getLog().getidentity();
AddMember newMember = dp.getContent();
ArrayList<String> members = getAllMembers();
loginInfoLock.lock();
try {
for (String memberName : members) {
if (!memberName.equals(senderIdentity) && !memberName.equals(newMember.getMemberIdentity())) {
if(clientLoginInfo.containsKey(memberName)) {
// online, then send to him
final String receiverIP = clientLoginInfo.get(memberName).getIPAddress();
(new Thread() {
public void run() {
try {
IHost clientStub = getStub(receiverIP);
if (clientStub != null)
clientStub.transferData(dp);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
peopleOnline += memberName + " ";
}
else{
// offline, then save it
pushLog.addPushMessage(senderIdentity, memberName, newMember.getApproverSign(),
P2PMessage.MessageType.AddMember,
newMember.getMemberIdentity() + "|" + dp.getLog().getLogId());
peopleOffline += memberName + " ";
}
}
}
}finally{
loginInfoLock.unlock();
}
// TODO: delete after test
System.out.println("people recv: " + peopleOnline + " people offline: " + peopleOffline);
// return sender a dp packet
final DataPacket<String> returnDp = new DataPacket<String>(myIP, String.class, OperationType.textMessage);
final String senderIP = dp.getSenderIP();
returnDp.setContent("people recv: " + peopleOnline + " people offline: " + peopleOffline);
(new Thread() {
public void run() {
try {
IHost senderStub = getStub(senderIP);
if (senderStub != null)
senderStub.transferData(returnDp);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
} | 8 |
public final char[] signature() /* (ILjava/lang/Thread;)Ljava/lang/Object; */ {
if (signature != null)
return signature;
StringBuffer buffer = new StringBuffer(parameters.length + 1 * 20);
buffer.append('(');
TypeBinding[] targetParameters = this.parameters;
boolean isConstructor = isConstructor();
// if (isConstructor && declaringClass.isEnum()) { // insert String name,int ordinal
// buffer.append(ConstantPool.JavaLangStringSignature);
// buffer.append(TypeBinding.INT.signature());
// }
boolean needSynthetics = isConstructor && declaringClass.isNestedType();
if (targetParameters != Binding.NO_PARAMETERS) {
for (int i = 0; i < targetParameters.length; i++) {
buffer.append(targetParameters[i].signature());
}
}
if (needSynthetics) {
// move the extra padding arguments of the synthetic constructor invocation to the end
for (int i = targetParameters.length, extraLength = parameters.length; i < extraLength; i++) {
buffer.append(parameters[i].signature());
}
}
buffer.append(')');
if (this.returnType != null)
buffer.append(this.returnType.signature());
int nameLength = buffer.length();
signature = new char[nameLength];
buffer.getChars(0, nameLength, signature, 0);
return signature;
} | 7 |
public static void unjar(File jarFile, File directory)
{
JarFile jfile;
try
{
jfile = new JarFile(jarFile);
final Enumeration<? extends JarEntry> entries = jfile.entries();
while (entries.hasMoreElements())
{
final JarEntry entry = entries.nextElement();
final File file = new File(directory, entry.getName());
if (entry.isDirectory())
{
file.mkdirs();
}
else
{
file.getParentFile().mkdirs();
final InputStream in = jfile.getInputStream(entry);
try
{
copy(in, file);
}
finally
{
in.close();
}
}
}
}
catch (final IOException e)
{
e.printStackTrace();
}
} | 4 |
public boolean equals(Object o) {
if (!(o instanceof ContactImpl)) {
return false;
} else {
ContactImpl contact = (ContactImpl) o;
if (firstName.equals(contact.firstName)
&& lastName.equals(contact.lastName)
&& organization.equals(contact.organization)
&& title.equals(contact.title)) {
return true;
}
return false;
}
} | 5 |
public boolean allowMove(int dx, int dy) {
int nx = x + dx;
int ny = y + dy;
int nx2 = x2 + dx;
int ny2 = y2 + dy;
int i;
for (i = 0; i != sim.elmList.size(); i++) {
CircuitElm ce = sim.getElm(i);
if (ce.x == nx && ce.y == ny && ce.x2 == nx2 && ce.y2 == ny2) {
return false;
}
if (ce.x == nx2 && ce.y == ny2 && ce.x2 == nx && ce.y2 == ny) {
return false;
}
}
return true;
} | 9 |
public EssenceOfDeath(boolean isFullscreen, int newWidth, int newHeight) {
try {
add(new Board(this, isFullscreen, newWidth, newHeight, 32));
} catch (IOException e) {
System.out.println("Error loading Board - " + e);
}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(newWidth + 6, newHeight + 28);
setLocationRelativeTo(null);
setTitle("Essence of Death - v 0.0.005 - INTERNAL PROTOTYPE TEST");
setVisible(true);
setResizable(false);
} | 1 |
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Borrower)) {
return false;
}
Borrower other = (Borrower) obj;
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
return true;
} | 6 |
private GenericDAO<Project> getCustomersDAO() {
if (_customersDAO == null) {
_customersDAO = new GenericDAO<Project>(Project.class);
}
return _customersDAO;
} | 1 |
public void actionPerformed(ActionEvent e){
if (e.getSource() == newButton){
newButtonClicked(e);
}
if (e.getSource() == showButton){
showButtonClicked(e);
}
if (e.getSource() == timeButton){
timeButtonClicked(e);
}
} | 3 |
public TuringToGrammarConverter()
{
myAllReadableString=new HashSet <String>();
myAllWritableString=new HashSet <String>();
} | 0 |
private void submitOrder(String label, OrderCommand orderCmd) throws JFException {
this.order = engine.submitOrder(label, this.instrument, orderCmd, this.amount);
while (order.getState() == IOrder.State.CREATED || order.getState() == IOrder.State.OPENED) {
order.waitForUpdate(2, TimeUnit.SECONDS);
}
if (order.getState() == IOrder.State.CANCELED) {
this.order = null;
}
} | 3 |
private void handlePingResponse(Packet pingResponse) {
//ignore if the ping response is null
if(pingResponse == null)
return;
//if the ping response doesn't have a sequence number of the ping it's responding to then we can't do anything
if(pingResponse.getLastReceivedSequenceNumber() == Packet.SEQUENCE_NUMBER_NOT_APPLICABLE)
return;
synchronized(CONNECTION_LOCK) {
//if we have no record of when the ping was sent then we can't do anything
PacketReceipt pingReceipt = recorder.getSentPacketWithSequenceNumber(pingResponse.getLastReceivedSequenceNumber());
if(pingReceipt == null)
return;
//record the latency
long timeOfPing = pingReceipt.getTime();
long now = System.currentTimeMillis();
long timeSincePing = now - timeOfPing;
latency = (latency == -1 ? timeSincePing : (latency + timeSincePing) / 2);
}
} | 4 |
public static Image generateImage(Dataset dataset, BitSet selected, String infoString) {
List<Point> points = dataset.getPoints();
float distance = dataset.getMaxDistance();
//If no bitset is provided, show all connections
if(selected==null) {
selected = new BitSet(points.size());
selected.set(0, points.size());
}
Image image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
Graphics2D g2 = (Graphics2D)g;
g.setColor(Color.WHITE);
g.fillRect(0, 0, 1000, 1000);
RenderingHints rh = new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHints(rh);
g2.addRenderingHints(new RenderingHints(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
for(int i=0;i<points.size();i++) {
Point p = points.get(i);
if(selected.get(i)){
g.setColor(Color.RED);
g.fillRect((int)(p.x-POINT_SIZE/2)+OFFSET_X, (int)(p.y-POINT_SIZE/2)+OFFSET_Y, POINT_SIZE, POINT_SIZE);
} else {
g.setColor(Color.BLACK);
g.fillOval((int)(p.x-POINT_SIZE/2)+OFFSET_X, (int)(p.y-POINT_SIZE/2)+OFFSET_Y, POINT_SIZE, POINT_SIZE);
}
if(selected.get(i)) {
g.setColor(Color.BLUE);
g.drawOval((int)(p.x-(distance))+OFFSET_X, (int)(p.y-(distance))+OFFSET_Y, (int)distance*2, (int)distance*2);
g.setColor(Color.GRAY);
for (int j = selected.nextSetBit(0); j >= 0; j = selected.nextSetBit(j+1)) {
if(j!=i&& dataset.getGraph().getAdjacency(i, j)) {
Point a = points.get(i);
Point b = points.get(j);
g.drawLine((int)a.x+OFFSET_X, (int)a.y+OFFSET_Y, (int)b.x+OFFSET_X, (int)b.y+OFFSET_Y);
}
}
}
//g.setColor(Color.BLACK);
//g.drawString(""+i, (int)p.x+OFFSET_X, (int)p.y+OFFSET_Y);
}
if(infoString!=null) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, WIDTH, 30);
float thickness = 5;
Stroke oldStroke = g2.getStroke();
g2.setStroke(new BasicStroke(thickness*2));
g2.setColor(new Color(0,0,0,100));
g2.drawRect((int)(OFFSET_X-thickness), (int)(OFFSET_Y-thickness), (int)(Dataset.MAX_X+(thickness*2)), (int)(Dataset.MAX_Y+thickness*2));
g2.setStroke(oldStroke);
g.setColor(Color.WHITE);
g.setFont(new Font("Source Sans Pro SemiBold", Font.PLAIN, 20));
g.drawString(infoString, OFFSET_X, 22);
//setTitle(infoString);
}
return image;
} | 8 |
public void invalidatePacketEventsForThisEdge(Edge toDelFor){
boolean changed = false;
Iterator<Event> eventIter = iterator();
while(eventIter.hasNext()){
Event eventInQueue = eventIter.next();
if(eventInQueue instanceof PacketEvent){
PacketEvent pe = (PacketEvent) eventInQueue;
if(pe.packet.edge != null && toDelFor.getID() == pe.packet.edge.getID()) {
pe.packet.positiveDelivery = false;
pe.packet.edge = null; // the edge may not exist anymore
changed = true;
}
}
}
if(changed){
notifyListeners();
}
} | 5 |
public void setScheme(int scheme) {
if ((scheme == SIMPLE) || (scheme == NUMBERED) || (scheme == TIME)) {
this.scheme = scheme;
} else {
throw new IllegalArgumentException("Invalid output strategy scheme.");
}
} | 3 |
private static void setDefaults() {
List<String> check = Announcements.announcements.getSubNodes( "Announcements" );
if ( !check.contains( "Global" ) ) {
Announcements.announcements.setInt( "Announcements.Global.Interval", 300 );
List<String> l = new ArrayList<String>();
l.add( "&4Welcome to the server!" );
l.add( "&aDon't forget to check out our website" );
Announcements.announcements.setListString( "Announcements.Global.Messages", l );
}
for ( String server : proxy.getServers().keySet() ) {
if ( !check.contains( server ) ) {
Announcements.announcements.setInt( "Announcements." + server + ".Interval", 150 );
List<String> l = new ArrayList<String>();
l.add( "&4Welcome to the " + server + " server!" );
l.add( "&aDon't forget to check out our website" );
Announcements.announcements.setListString( "Announcements." + server + ".Messages", l );
}
}
} | 3 |
public static void main(String[] args) throws IOException {
final String method = CLASS_NAME + ".main()";
boolean start = Peer.start(args);
if(!start) {
LogUtil.log(method, "Peer not initialized properly");
return;
}
Set<String> filenames = FileStore.getInstance().getFilenames();
if(filenames == null || filenames.isEmpty()) {
LogUtil.log(method, "No files in directory");
return;
}
for (String filename : filenames) {
String fullPathFileName = FileStore.getInstance().getFileStoreDirectory() + filename;
LogUtil.log(method, "Reading : " + fullPathFileName);
FileMemoryObject readFile = null;
try {
readFile = FileIOUtil.readFile(fullPathFileName);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
continue;
}
LogUtil.log(method, "DONE Reading : " + filename);
LogUtil.log(method, "calculating MD5 checksum : " + filename);
byte[] createChecksumBeforeWriting = MD5CheckSumUtil.createChecksum(fullPathFileName);
LogUtil.log(method, "DONE calculating MD5 checksum : " + filename);
FileMemoryObject writeFileOnject = new FileMemoryObject(filename, readFile.getBytecontents());
LogUtil.log(method, "Writing : " + filename);
try {
FileIOUtil.writeToDisk(writeFileOnject);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
continue;
}
LogUtil.log(method, "DONE Writing : " + filename);
LogUtil.log(method, "calculating MD5 checksum : " + filename);
byte[] createChecksumAfterWriting = MD5CheckSumUtil.createChecksum(filename);
LogUtil.log(method, "DONE calculating MD5 checksum : " + filename);
if(MD5CheckSumUtil.isEqualCheckSum(createChecksumBeforeWriting, createChecksumAfterWriting)) {
LogUtil.log(method, "CheckSums equal");
}else{
LogUtil.log(method, "CheckSums NOT equal");
}
}
try {
PeerPeerLatencyStore.getInstance().initialize(args[5]);
} catch (WrongPeerLatencyConfigFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PeerPeerLatencyStore.getInstance().printLatencies();
} | 8 |
public boolean execute(ChatClient sender, String[] args) {
if (args.length < 2) {
sender.serverChat(usage());
return true;
}
ChatAccount account = AccountManager.getAccount(args[1]);
if (account == null) {
sender.serverChat("There is no account by that name");
}
StringBuilder strBuf = new StringBuilder(BLD);
strBuf.append(String.format("%sAccount Name: %s%s\n", BLU, CYN, account.getName()));
strBuf.append(String.format("%sLevel: %s%d\n", BLU, CYN, account.getLevel()));
if (ChatServer.checkOnlineAccount(account.getName(), ""))
strBuf.append(WHT + account.getName() + " is online right now!");
else {
Date lastLogin = account.lastLogin();
strBuf.append(String.format("%s%s last online %s", WHT, account.getName(), (lastLogin != null ? df.format(lastLogin) : "Never!")));
}
if (sender.getAccount().getLevel() == 5) {
List<String> gags = account.gagList();
if (gags != null) {
strBuf.append(BLU + "\nGags: " + CYN);
for (String s : gags) {
strBuf.append(s + " ");
}
}
List<String> ips = account.getKnownAddresses();
if (ips != null) {
strBuf.append(BLU + "\nKnown Addresses:" + CYN);
for (String s : ips) {
strBuf.append("\n" + s);
}
}
}
sender.sendChat(strBuf.toString());
return true;
} | 9 |
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == saveButton)
{
Dimension size = this.getSize();
BufferedImage image = (BufferedImage) this.createImage(size.width,
size.height);
Graphics g = image.getGraphics();
this.paint(g);
g.dispose();
JFileChooser fileChooser = new JFileChooser();
ExtensionFileFilter filterPNG = new ExtensionFileFilter(
"PNG Image Files", ".png");
ExtensionFileFilter filterJPG = new ExtensionFileFilter(
"JPG Image Files", ".jpg");
fileChooser.addChoosableFileFilter(filterPNG);
fileChooser.addChoosableFileFilter(filterJPG);
fileChooser.setFileFilter(filterJPG);
fileChooser.setCurrentDirectory(new File(prefs.GetImageDir()));
int option = fileChooser.showSaveDialog(this);
if (option == JFileChooser.APPROVE_OPTION)
{
String filename = fileChooser.getSelectedFile().getPath();
if (fileChooser.getFileFilter() == filterPNG)
{
if (!(filename.endsWith(".png")))
{
filename = filename + ".png";
}
} else if (fileChooser.getFileFilter() == filterJPG)
{
if (!(filename.endsWith(".jpg")))
{
filename = filename + ".jpg";
}
}
try
{
prefs.SetImageDir(fileChooser.getCurrentDirectory().getAbsolutePath());
if (filename.endsWith(".png"))
{
ImageIO.write(image, "png", new File(filename));
} else
{
ImageIO.write(image, "jpg", new File(filename));
}
} catch (IOException exc)
{
System.err.println("Unable to save window image to " + filename);
exc.printStackTrace();
}
} // User said save
} // SaveButton pushed
else if (source == doneButton)
{
prefs.SetAngleOriginX(this.getX());
prefs.SetAngleOriginY(this.getY());
prefs.SetAngleHeight(this.getHeight());
prefs.SetAngleWidth(this.getWidth());
prefs.SavePrefs();
setVisible(false);
}
} // actionPerformed() | 9 |
public static void clear() {
for(Stack<Edge> s : stacks.values()) {
s.clear();
}
stacks.clear();
if(lastStack != null) {
lastStack.clear();
}
lastStack = null;
} | 2 |
public void printCombs(ArrayList<ArrayList<Integer>> comb) {
System.out.println("[");
for (int i = 0; i < comb.size(); i++) {
ArrayList<Integer> curComb = comb.get(i);
System.out.print("[");
for (int j = 0; j < curComb.size(); j++) {
if (j == curComb.size() - 1)
System.out.print(curComb.get(j));
else
System.out.print(curComb.get(j) + ",");
}
System.out.println("]");
}
System.out.println("]");
} | 3 |
private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
this.anadirCliente();
}//GEN-LAST:event_btnNuevoActionPerformed | 0 |
public boolean collide_static() {
for(int i = 0; i < Fenetre._list_static_items.size(); i++) {
//Ici on verifie que le rectangle de l'objet dans lequel on est collide avec un des objets de la liste static
if (Fenetre._list_static_items.get(i).getSolid() && _r.intersects(Fenetre._list_static_items.get(i).getRect())) {
return true;
}
}
return false;
} | 3 |
public static ArrayList<Vector2D> getTriangleTriangleIntersects(Triangle A, Triangle B) {
ArrayList<Vector2D> intersects = new ArrayList<Vector2D>();
for (Vector2D intersect : getTriangleLineIntersects(A, B.getAB())) {
intersects.add(intersect);
}
for (Vector2D intersect : getTriangleLineIntersects(A, B.getAC())) {
intersects.add(intersect);
}
for (Vector2D intersect : getTriangleLineIntersects(A, B.getBC())) {
intersects.add(intersect);
}
return intersects;
} | 3 |
protected void doPrintHeader() {
if (m_Header.classAttribute().isNominal())
if (m_OutputDistribution)
append(" inst# actual predicted error distribution");
else
append(" inst# actual predicted error prediction");
else
append(" inst# actual predicted error");
if (m_Attributes != null) {
append(" (");
boolean first = true;
for (int i = 0; i < m_Header.numAttributes(); i++) {
if (i == m_Header.classIndex())
continue;
if (m_Attributes.isInRange(i)) {
if (!first)
append(",");
append(m_Header.attribute(i).name());
first = false;
}
}
append(")");
}
append("\n");
} | 7 |
public static Customer getCustomer(String name) {
for (String s : names) {
if (s.equalsIgnoreCase(name))
return new RealCustomer(name);
}
return new NullCustomer();
} | 2 |
public void runToNextWalkFrame(int excuseFrames) throws CapturedByRotatoException {
int startSteps = curGb.stepCount;
// forward to first possible input frame
while(true) {
Util.runToFirstDifference(0, dir, Metric.DOWN_JOY);
State s = curGb.newState();
int add2 = Util.runToAddressNoLimit(0, dir, curGb.pokemon.doPlayerMovementFuncAddress, curGb.pokemon.printLetterDelayJoypadAddress);
if(add2 == curGb.pokemon.printLetterDelayJoypadAddress)
throw new CapturedByRotatoException();
curGb.restore(s);
int add = curGb.step(dir, curGb.pokemon.doPlayerMovementFuncAddress);
curGb.restore(s);
if(add != 0) {
//System.out.println("found walk input frame ("+steps+")");
break;
}
if(excuseFrames-- <= 0)
System.out.println("INFO: WalkStep: found non-walk input frame ("+(curGb.stepCount - startSteps)+")");
curGb.step();
}
} | 4 |
@Override
public void applyComponent(Mat inputMat, ProcessInfo info) {
Integer dilateSize = (Integer) dilateSizeSpinner.getValue();
Integer erodeSize = (Integer) erodeSizeSpinner.getValue();
int shape = Imgproc.MORPH_ELLIPSE;
switch ((Shape)comboBox.getSelectedItem()) {
case CIRCLE:
shape = Imgproc.MORPH_ELLIPSE;
break;
case CROSS:
shape = Imgproc.MORPH_CROSS;
break;
case SQUARE:
shape = Imgproc.MORPH_RECT;
break;
default:
break;
}
Mat dilateKernel = Imgproc.getStructuringElement(shape, new Size(dilateSize, dilateSize));
Mat erodeKernel = Imgproc.getStructuringElement(shape, new Size(erodeSize, erodeSize));
if(!chckbxNewCheckBox.isSelected()){
Imgproc.dilate(inputMat, inputMat, erodeKernel);
}
Imgproc.erode(inputMat, inputMat, erodeKernel);
if(chckbxNewCheckBox.isSelected()){
Imgproc.dilate(inputMat, inputMat, dilateKernel);
}
} | 5 |
public float abSearch(ABNode node, int depth, float a, float b, Boolean maximizingPlayer) {
if(depth == 0 || node.isTerminal()) {
return node.getHVal();
}
if (maximizingPlayer) {
for(ABNode child : node.getChildNodes(1)) { //Each child node
a = Math.max(a, abSearch(child, depth -1, a, b, false));
if(b <= a) {
break; //B cut-off
}
return a;
}
} else {
for(ABNode child : node.getChildNodes(0)) { //Each child node
b = Math.min(b, abSearch(child, depth - 1, a, b, true));
if (b <= a) {
break; //a cut-off
}
return b;
}
}
return -1;
} | 7 |
protected int findGridlet(Collection obj, int gridletId, int userId)
{
ResGridlet rgl = null;
int found = -1; // means the Gridlet is not in the list
try
{
// Search through the list to find the given Gridlet object
int i = 0;
Iterator iter = obj.iterator();
while ( iter.hasNext() )
{
rgl = (ResGridlet) iter.next();
// Need to check against the userId as well since
// each user might have same Gridlet id submitted to
// same GridResource
if (rgl.getGridletID()==gridletId && rgl.getUserID()==userId)
{
found = i;
break;
}
i++;
}
}
catch (Exception e)
{
System.out.println(super.get_name() +
".findGridlet(): Exception error occurs.");
System.out.println( e.getMessage() );
}
return found;
} | 4 |
public static Pet[] createArray(int size) {
return creator.createArray(size);
} | 0 |
Subsets and Splits
SQL Console for giganticode/java-cmpx-v1
The query retrieves a limited number of text entries within a specific length range, providing basic filtering but minimal analytical insight.