method_id
stringlengths
36
36
cyclomatic_complexity
int32
0
9
method_text
stringlengths
14
410k
95cde0fe-c854-42a2-bb2b-a95c0cd5c55f
1
public void playBattle() throws InterruptedException{ try { in = new FileInputStream(battle); as = new AudioStream(in); ap.player.start(as); } catch(Exception e) { System.out.println("Got an IOException: " + e.getMessage()); e.printStackTrace(); ...
c451052b-d1ee-4a3e-92a5-4a46e70eda91
1
@Override public List<Direction> findDirections(Criteria criteria) throws DaoException { if (criteria.getParam(DAO_DIRECTION_STATUS) == null) { criteria.addParam(DAO_DIRECTION_STATUS, ACTIVE); } TypedQuery query = TypedQueryFactory.getInctance(QueryType.DIRECTIONQUERY); r...
963d13d5-9ef3-4501-bf52-1cd4ecd31e05
8
public void createChoosingList() { double[] choosingList = new double[popSize]; double min=fitness[0]; for(int i=1;i<popSize;i++) { if(fitness[i]<min) { min = fitness[i]; } } if(min < 0) { choosingList[0] = 0; } else { ...
8f44890a-6639-4f0f-8686-eae9e4275d66
0
@Override public int getSum() { return money; }
3aedcbb7-7a8d-4423-9829-4e19e99c1265
9
public boolean refreshSMS(final Voice voice) throws IOException { System.out.println("Refreshing sms"); final Collection<SMSThread> smsThreads = voice.getSMSThreads(); if (smsThreads == null || smsThreads.isEmpty()) { System.out.println("No SMSes in thread"); return false; ...
d7de702f-b481-416c-9621-5cc005cd7d66
0
public void setShopUrl(String shopUrl) { this.shopUrl = shopUrl; }
c68ccb05-1fb3-4722-9da4-a7bcd8bdf2c7
9
@Override public boolean equals(Object o) { if(this == o) return true; if(!(o instanceof Event)) return false; Event other = (Event)o; if(this.gameStep != other.gameStep) return false; if(this.fromAvatar != other.fromAvatar) return false; if(this.activeTypeId != ...
5cb06495-e81b-4c4a-a96c-0a3281de01ac
7
@Override public double generarRenta(int d) { double total = consola.getPrecio(); switch(consola){ case PS3: case XBOX: if( d > 3 ) total += total * 0.6 * (d - 3); break; case WII: if( d ...
763cf343-266d-4b2c-800a-9e969f19dd9a
6
public static int[] rotate2Bilinear(int[] pix, float beta, int iw, int ih, int owh) { pix = GT.translate(pix, (owh-iw)/2, (owh-ih)/2, iw, ih, owh, owh); int[] opix = new int[owh * owh]; double t = beta / 180; for (int i = 0; i < owh; i++) { for (int j = 0; j < owh; j++) { double p = Math.sqrt((j...
3bd025eb-52d7-4e7b-99b3-714d8a1aaf5a
0
public boolean getCountsValid() { return countsValid; }
88cb62c9-47c3-4908-9c5c-ef5960d846c0
7
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; Font f = new Font("font", Font.PLAIN, 40); g2d.setFont(f); g2d.setColor(java.awt.Color.yellow); int k = this.getHeight() * tile_height; int l = this.getWidth() * tile_width; ...
9230166c-3757-46e9-b40a-045572d81c41
3
public void onAction(String sender, String login, String hostname, String target, String action) { if (status != GameStatus.IDLE) { if (status != GameStatus.PRE) { if (players2.isDead(players2.getPlayerNumber(sender))) bot.setMode(gameChan, "-v " + sender); } } }
9c418b35-37f2-430d-8015-46c4547bdd02
3
public void setFocus(Accessible focus) { for(UIElement e : uiElements) { if(e instanceof Accessible && e != focus) { e.setState(DISABLED); } } }
241d4621-158b-45d5-98dd-ee2ed6eea455
3
protected void updateAllExistingParticles(ParticleEmitter emitterDetails, long elapsedTimeMilliSecs) { // If this emitter detail slot is free create, grab a new bunch // of values and reset the particle, reusing the original entity // for (int j = 0; j < emitterDetails.maximumParticles; j++) { Queue<Entity> cur...
8b63542e-8a70-424c-adb6-d0c9469cac4d
7
private void ObtemCaminhos() { LinkedList<Integer> ruasCaminho = new LinkedList<Integer>(); int inicio; int fim; int tamanho; for (int i = 0; i < grafo.getNumeroDeVertices(); i++) { BuscaEmLargura buscaLargura = new BuscaEmLargura(grafo, i); for (int u = 0; u < grafo.getNumeroDeVerti...
4885f262-7bcb-4cb0-924e-3122ba74aab6
1
public void setTableCount(int tableCount) throws CarriageException { if (tableCount < 0) { throw new CarriageException("Table count is under zero"); } this.tableCount = tableCount; }
0b68a118-8e53-41d7-8569-608614cc9695
6
@Override public void paint(Graphics windowGraphics) { if (windowGraphics == null) return; windowWidth = getWidth(); windowHeight = getHeight(); if (frontImageBuffer == null) { // no image to display windowGraphics.clearRect(0, 0, windowWidth, windowHeight); return; } synchronized (Zen.class) ...
472e19d4-0a40-4618-b75b-bf171f427309
6
@Override public RenderResult nextResult() { if( !run || !task.pixelRayIteratorIterator.hasNext() ) return null; final PixelRayIterator pri = task.pixelRayIteratorIterator.next(); int imageDataSize = pri.getImageDataSize(); final PixelRayBuffer prb = new PixelRayBuffer(batchSize); final float[] r = new ...
073acfb5-1a5c-43f4-a1da-653bcd9a3055
5
public static void main(String[] args) { Image image = readImageData("joker.jpg"); if (image == null || image.getData() == null) { System.err.println("Given image could not be read"); return; } try { // initialize proxy class (this perform authorisation) ITraffSoapProxy iTraffSoap = new ITraffSoap...
8a093bea-046f-492e-a6c7-410b838d1779
8
public static Node updateRunTimeEnvironment(Node root) { SymTab newTable = runTimeStack.push(); int level = root.getSymTab().getNestingLevel() + 1; newTable.setNestingLevel(level); if (level > runTimeDisplay.getCurrentNestingLevel()) { runTimeDisplay.push(newTable); ...
f71c0d6b-b1f1-41f9-8bf3-cfec0cb0ad6e
2
public static void initializeVariableDependencyGraph( VariableDependencyGraph graph, Grammar grammar) { String[] variables = (String[]) getCompleteUsefulVariableSet(grammar) .toArray(new String[0]); for (int k = 0; k < variables.length; k++) { double theta = 2.0 * Math.PI * (double) k / (double) vari...
118b898c-dbef-4dfc-9fd7-af470a98a05f
0
public Command(String name){ _name = name; }
5b33b03f-6f9d-46cc-8dc0-66cb8e4fea8a
8
public static void preperation() { table = new HashMap<Integer, ArrayList<Node>>(); if (Config.verbose >= 2){ System.out.println("========================================"); System.out.println("Generating possible Atoms"); } generateLeafs(); if (Config.verbose >= 2){ System.out.print("Generat...
0357f27b-5623-44f9-8c9e-04e6e5b926e8
2
private void init() { try { emetteur = new Socket(adresseIPServeur, port); } catch (UnknownHostException e) { System.out.println("Impossible de trouver l'hôte du serveur."); } catch (IOException e) { System.out.println("Problème d'E/S."); } }
ce7030fd-5864-4414-b158-e7e2654938e4
3
public static void main(String[] args) { // Something to start from Store store = new Store(); // define FD store // define finite domain variables vdd = new IntVar(store, "vdd", 1, 1); gnd = new IntVar(store, "gnd", 0, 0); IntVar a = new IntVar(store, "A", 0, 1); IntVar b = new IntVar(store, "B", 0, 1)...
16a62aec-ca6e-4018-b22f-c2107ef65309
7
@EventHandler public void onInvClick(InventoryClickEvent event) { HumanEntity human = event.getWhoClicked(); if (human instanceof Player) { Player player = (Player) human; Inventory inv = player.getOpenInventory().getTopInventory(); if (inv.getHolder() != null && ...
cbe16ac4-5036-4a54-997d-778f3452efa0
5
public Collection<JSONObject> listRelatedViewpoints() throws Exception { Set<String> identifiers = new HashSet(); for (HypertopicMap.Corpus c : this.openedCorpora) { for (HypertopicMap.Corpus.Item i : c.getItems()) { for (HypertopicMap.Viewpoint.Topic t : i.getTopics()) { identifiers.add(t.getViewpointID());...
0cc17f5f-97a9-4da5-8374-476abd03cd7b
1
public boolean more() throws JSONException { this.next(); if (this.end()) { return false; } this.back(); return true; }
ff3b474c-43d5-47a5-996a-bce65267047e
0
public static void main(String[] args) { System.out.println("Creating new Cupboard() in main"); new Cupboard(); System.out.println("Creating new Cupboard() in main"); new Cupboard(); }
2ad59042-66f2-4e26-998b-994a0f343e00
3
private void expect(TokenType... types) throws UnexpectedTokenException { boolean ret = false; for(TokenType type : types) { if(type == this.getToken().type) { ret = true; break; } } if(!ret) { Token given = this.getToken(); throw new UnexpectedTokenException(given.type, types); }...
796dea6a-ed15-4884-9af2-0416466859db
3
public List<VcfNmd> parseNmd() { String nmdStr = getInfo(LossOfFunction.VCF_INFO_LOF_NAME); ArrayList<VcfNmd> nmdList = new ArrayList<VcfNmd>(); if (nmdStr == null || nmdStr.isEmpty()) return nmdList; // Split comma separated list String lofs[] = nmdStr.split(","); for (String lof : lofs) nmdList.add(n...
6b038f53-8620-4dff-aafe-a949853fa01e
9
public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) { super.randomDisplayTick(par1World, par2, par3, par4, par5Random); for (int var6 = par2 - 2; var6 <= par2 + 2; ++var6) { for (int var7 = par4 - 2; var7 <= par4 + 2; ++var7) ...
15022b83-bb6a-46ea-bb3d-4ae79cc86ce8
2
private static void registrarCasete() { boolean salir; String nombre, codigo; float precio; Casete casete; do { try { System.out.print( "Introduce el nombre del Casete: "); nombre = scanner.nextLine(); System.out.print( "Introduce el cdigo del Casete: "); codigo = scanner.nex...
f85d401a-e419-4306-9f66-6bf3a22e351d
5
public boolean containsDuplicates() { if (!isProperList) { if (this.contains(this.dottedElement)) { return true; } } for (int i = 0; i < this.size(); i++) { for (int j = i + 1; j < this.size(); j++) { if (this.get(i).equals(this.get(j))) { return true; } ...
3af7d29e-d8c8-49b4-8fb4-d110b3115114
2
private static String listAsString(List list) { Iterator it = list.iterator(); if (!it.hasNext()) return ""; StringBuffer sb = new StringBuffer(); sb.append(it.next()); while (it.hasNext()) { sb.append(' '); sb.append(it.next()); } return sb.toString(); }
6eb705aa-1308-4e31-8781-341d739df74d
6
private void copyRGBtoRGBA(ByteBuffer buffer, byte[] curLine) { if(transPixel != null) { byte tr = transPixel[1]; byte tg = transPixel[3]; byte tb = transPixel[5]; for(int i=1,n=curLine.length ; i<n ; i+=3) { byte r = curLine[i]; by...
3883774c-2b17-4461-8393-e92b45c87290
4
private void ApplySingleVulnerabilityButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ApplySingleVulnerabilityButtonActionPerformed String[] VulnerabilityData = null; int count = 0; Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; int VULNERABILI...
22787b29-5091-4253-80f9-830ac9e87fcd
6
private void setLookAndFeel() { //<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/...
59fd8ee8-4609-432c-a5a1-383f4d2711c7
3
@Override protected Dimension getSizeSelf(LayoutSize type) { Dimension[] sizes = getChildSizes(type); Dimension size = new Dimension(0, getVerticalGap() * (sizes.length > 0 ? sizes.length - 1 : 0)); for (Dimension one : sizes) { size.height += one.height; if (one.width > size.width) { size.width = one....
2fec566e-114a-4383-9acd-0101d3f21406
1
@Test public void testTimeStep_MONTHLY_MEAN() throws Exception { printDebug("----------------------------"); printDebug("Monthly Mean: " + this.toString()); printDebug("----------------------------"); CSTable t = DataIO.table(r, "obs"); Assert.assertNotNull(t); // 4 ...
9962bbc8-34e6-4b5b-92c1-75ab42bc04d5
8
final public void AdditiveExpression() throws ParseException { Token t = null; MultiplicativeExpression(); label_15: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case PLUS: case MINUS: ; break; default: break label_15; } switch ((jj_ntk...
22b408a4-7d24-4e08-9f8b-d0228facbb20
2
public double getDouble(String key) throws JSONException { Object object = this.get(key); try { return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object); } catch (Exception e) { throw new JSONException("JS...
0c5719da-8cd4-4c21-ac08-ae1b8f087ec1
1
public static void main(String[] args) { In[] streams = new In[args.length]; for (int i = 0; i < args.length; i++) streams[i] = new In(args[i]); merge(streams); /* * IndexMinPQ<Double> pq = new IndexMinPQ<Double>(4); * pq.insert(3, 3.0); * pq.insert(2, 2.0); * pq.insert(1, 1.0); * pq.insert(...
313dde0e-74dd-4953-b5c3-5f6c2a39a901
5
public static boolean DateFormatHasYear(CSTable table, int col) { if (col < 0 || col > table.getColumnCount()) { throw new IllegalArgumentException("invalid column: " + col); } String format = table.getColumnInfo(col).get(KEY_FORMAT); if (format == null) { format ...
eb2fb3ee-9e2a-40b3-bec7-c6c05d382725
3
public boolean compareApproximate(String textToCompare, String sequence, int mismatches) { //number of mismatches int d = 0; //compare characters and increase number of mismatches if necessary for (int i = 0; i < textToCompare.length(); i++) { Character first = textToCompare...
65d77245-2e17-4bb5-a030-62e9ded0df7c
0
public boolean isEmpty() { return myCards.isEmpty(); }
d65629a8-56ea-4500-a052-c54176e6ff69
9
public static void main(String[] args) throws FileNotFoundException, Exception { AudioDecoder decoder = null; DetectionFunction onsetDetector = null; /* * System.out.println(Math.exp(0.0)); System.out.println(Math.abs(0.0)); */ if (FILE.endsWith(".wav")) { decoder = new WavDecoder(new FileInputSt...
5c8aad94-f6ea-483f-a277-c58dc0e23bfe
1
@Override public boolean equals(Object other) { boolean result = false; if (other instanceof RouteLength) { RouteLength that = (RouteLength) other; result = this.length == that.length; } return result; }
e1c697e0-1a60-413a-b38d-55c49e51b949
0
@Test public void num_should_be_add_1_when_out_a_car() { final int num = 20; Park park = new Park(num); Car car = new Car(); Ticket ticket = park.in(car); Assert.assertEquals(park.getEmptyNum(), num - 1); park.out(ticket); Assert.assertEquals(park.getEmptyNum(...
06314f58-1023-4b91-9fbd-9a241420b5c1
7
private final JSONWriter append(String s) throws JSONException { if (s == null) { throw new JSONException("Null pointer"); } if (this.mode == 'o' || this.mode == 'a') { try { if (this.comma && this.mode == 'a') { this.writer.write(',');...
df979138-7646-4012-83f1-bffac09695f7
4
void drawString(String text, int x, int y, FontStyle style) { final Color colorBackup = g.getColor(); final Font fontBackup = g.getFont(); if (fontBackup != style.font) { g.setFont(style.font); } if (colorBackup != style.color) { g.setColor(style.color)...
ff6961b7-422b-4e75-987b-0fac351bd316
3
protected Vector3f findBestGunPosition(Actor ship, Vector3f direction){ java.util.List<Vector3f> gunPositions = ship.getHotSpotsFor("Weapon"); // Make sure we have gun positions if(gunPositions == null) return null; Vector3f closestPosition = gunPositions.get(0); fl...
e8b2eb34-6ab8-4c61-932a-21f0cf531256
6
private static int calculateChecksum (String tagString, ByteBuffer data) { int sum = 0; data.mark (); // special adjustment for head table: always treat the 4-bytes // starting at byte 8 as 0x0000. This the checkSumAdjustment so // must be ignored here (see the TTF spec) ...
4e7a823a-54e4-4b2e-8bd5-083caf2029ed
5
public static void logRaw(String message, int level) { if (LOG_EXACT) { if (level == LOG_LEVEL.getLevel()) { if(MainWindow.txtPnLog == null) { System.out.println(message); }else { MainWindow.txtPnLog.setText(MainWindow.txtPnLog....
83e1e91c-4f02-419a-9910-221257f9d522
0
public Panel getPanel() { return panel; }
25b564c6-9e1d-4656-96cb-ce6c7fcd100c
9
public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(metho...
6e86be7f-6f96-4628-a895-77779c50916d
7
@Override public void decode(final ByteBuffer buf, final int available, final StringBuilder log) throws Exception { final byte service_code = buf.get(); final CNService reply = CNService.forCode(service_code); if (reply == null) throw new Exception("Received reply with unknown service code ...
e04efd98-ece8-4bf1-ba48-cfbbb803083e
5
public static void expandNodes( JTree tree, TreePath parent, boolean expand, int depth ) { if( parent == null || depth == 0 ) return; Object node = parent.getLastPathComponent(); if( node != null ) { for( int i = 0; i < tree.getModel().getChildCount( node ); i++ ) { ...
5af72712-6878-44fa-8fdf-c4283d5e744e
1
public static void main(String[] args) { SymbolDigraph<String> sg = new SymbolDigraph<String>(4); try { sg.addEdge("Main", "Object"); sg.addEdge("A", "B"); sg.addEdge("B", "A"); } catch (Exception e) { e.printStackTrace(); } System.out.println(sg); System.out.println(sg.keys); }
536f5308-886c-458b-bb88-2367c1c21611
3
static boolean check(int r, int c) { return r >= 0 && r < 4 && c >= 0 && c < 4; }
ae756a90-164f-4783-81a3-d9fbfa47fffc
9
@Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_UP: System.out.println("Bewege dich hoch"); break; case KeyEvent.VK_DOWN: currentSprite = characterDown; if (robot.isJumped() == false) { robot.setDucked(true); robot.setSpeedX(0); } bre...
801996bb-52b4-4a5a-9983-a7dd8e3c67d3
0
@Override public void mouseExited(MouseEvent e) { }
25275c9a-3e61-47a4-ba26-bfee2e0e3e3c
2
public void removeOldImagesAfter2DaysPeriod() { List<Image> images = getAllImagesTimestamps(); for (Image image : images) { DateTime date = new DateTime(image.getTimestamp()); if (date.plusDays(DAYS_LIMIT).isBeforeNow()) { mongoImageTemplate.remove(image); } } }
73b955e5-5c5f-4358-a39b-5263a01f92ff
4
public Slideshow(final String currentAlbum) { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 800, 500); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); setLocationRelativeTo(nul...
4a98da8a-09d5-430e-8f73-ccd8a49ce68f
6
public static void main(String[] args) { // TODO Auto-generated method stub //Question: //Write an algorithm such that if an element in an MxN matrix is 0, //its entire row and column is set to 0 int[][] testMatrix ={{1,5,2,8,7},{5,9,9,0,2},{2,7,0,1,4}}; System.out.println("Orignal one"); for(int i=0;...
eef16298-d12a-4807-8bf0-7afb9a1a829f
2
public static int execUpdate(String strSql) { try { stmt = conn.createStatement(); } catch (SQLException e) { logger.fatal(e); e.printStackTrace(); } try { logger.info("Execute Update Sql Start"); logger.info("Execute Update Sql statment:" + strSql); int SqlR = stmt.executeUpdate...
e5bd840d-e3ec-4e7c-be94-f152b27be9b0
6
public void sendMessage(Message m, String url) { if (url == null) { logger.info("Wtf wie heet null"); } else{ try { IMessageReceivedHandler stub = (IMessageReceivedHandler) java.rmi.Naming.lookup("rmi://"+registry+":1099/"+url); stub.onMessageReceived(m); } catch (MalformedURLException e) { Syste...
37164a42-89e2-4c3b-a704-5619914676fd
2
@RequestMapping(value = "/clearDB", method = RequestMethod.POST) public String clearDB(HttpServletRequest paramHttpServletRequest, RedirectAttributes redirectAttributes) { try { if (isAuthenticated(paramHttpServletRequest)) { imageService.removeAll(); redirectAttributes.addAttribute("success", true); }...
fb9c9898-1337-4945-afb7-309ab7833046
5
public JSONObject increment(String key) throws JSONException { Object value = this.opt(key); if (value == null) { this.put(key, 1); } else if (value instanceof Integer) { this.put(key, ((Integer)value).intValue() + 1); } else if (value instanceof Long) { ...
140afb16-6266-43b4-b9f6-8c6b5ba0d017
4
public void check_collisions(ShipFire shipFire) { Iterator<Invader> it = invaders.iterator(); while (shipFire.not_destroyed() && it.hasNext()) { Invader invader = it.next(); if (invader.is_alive() && shipFire.collide_with(invader)) { shipFire.change_state_to_explosion(invader); inva...
b9106341-8528-4cee-b90f-03669ec5f996
7
public int locInPrompt(String p, String n) { System.out.print("Enter starting " + p + " position for " + n + ": "); String str = CommandLine.s.next(); try { int i = Integer.parseInt(str); if (0 < i && 11 > i) {return i;} else { System.out.print...
06d9195b-9877-420a-89ab-20c2ce0313b6
6
@Override public boolean equals (Object other){ if (other == null) return false; if (other == this) return true; if (!(other instanceof Solution))return false; Solution c = (Solution)other; if(c.weapon.equals(weapon) &&c.person.equals(person)&&c.room.equals(room)) return true; return false; }
734469a9-59a7-4943-853b-7d426286247d
3
public static void main(String[] args) { Object[] shapes = {new LegacyLine(), new LegacyRectangle()}; // A begin and end point from a graphical editor int x1 = 10, y1 = 20; int x2 = 30, y2 = 60; for (int i = 0; i < shapes.length; ++i) { if (shapes[i] instanceof Legacy...
1f4429f4-a240-4531-94f3-e62338789598
3
public boolean addInvocationTarget( String name, RPCInvocationTarget target, boolean useAsDefaultTarget ) throws NullPointerException { if( name == null ) throw new NullPointerException( "Cannot add invocation targets with null name." ); if( target == null ) throw new NullPointerException...
a5b5cb6d-1d5c-4fb0-b666-6800d469f554
1
public Value merge(final Value v, final Value w) { if (!v.equals(w)) { return BasicValue.UNINITIALIZED_VALUE; } return v; }
96a58774-b2d1-4740-80e2-fc9ae6016650
5
public boolean shapeValido (){ switch(ttggss){ //case "030202": //return true; // Margenes de rios que van a tener natural=water //case "030302": //return true; // Emborrona mas que ayudar case "037101": return true; case "038101": return true; case "038102": return true; case "037102": ...
00ad8044-7b91-4c4e-8850-ca66434d8df8
0
public String getLHS() { return myLHS; }
0d315d60-63b3-4d4e-94a2-2469754d4166
0
public int getMax() { return this.upperBound; }
f8f49306-4781-40ae-8455-d14f68ffb1d7
9
public List<List<Integer>> subsetsWithDup(int[] nums) { List<List<Integer>> subsets = new ArrayList<List<Integer>>(); if (nums == null) { return subsets; } Arrays.sort(nums); int i = 0; while (i != nums.length) { List<List<Integer>> newLists = new...
c946c922-19d5-4420-9b1d-6f0f483edf83
2
@Override public Category getCategory(Integer id) { Category category = null; PreparedStatement pStmt = null; ResultSet rs = null; try { pStmt = conn.prepareStatement("SELECT * FROM CATEGORY WHERE id = ?;"); pStmt.setInt(1, id); rs = pStmt.executeQuery(); while (rs.next()) { ...
508e719e-cbea-47e0-bec8-c66d5ee57a59
8
public void prune() throws Exception { Evaluation nodeModelEval = null; if (m_isLeaf) { buildLinearModel(m_indices); nodeModelEval = new Evaluation(m_instances); // count the constant term as a paramter for a leaf // Evaluate the model nodeModelEval.evaluateModel(m_nodeModel, m_i...
0d287ea4-69a6-48bc-93ff-e16f1f5bc3f9
4
public void setProfile( Profile p ) { boolean[] unlocks = p.getShipUnlocks(); for (int i = 0; i < shipBoxes.size(); i++) { shipBoxes.get(i).setSelected( unlocks[i] ); } for ( Map.Entry<Achievement, JCheckBox> entry : shipAchBoxes.entrySet() ) { String achId = entry.getKey().getId(); JCheckBox box = e...
2fca42fc-3a0c-4c31-bde5-7ac54b1a46d8
2
public Dimension getMinimumSize() { Dimension size = super.getMinimumSize(); if (size.width < 80) { size.width = 80; } if (size.height < 25) { size.height = 25; } return size; }
6b94e631-10e6-45d7-9043-22f322d6f93f
3
public synchronized void addStation(String alias) { Iterator<String> it = stations.iterator(); for(int i = 0; i < stations.size(); i++) { // compare both strings int com = it.next().compareTo(alias); if(com == 0) { throw new IllegalStateException("The alias " + alias + " is already part of this network...
7ae16f82-f8c6-4f34-9e6a-edbc5a7cb5fb
6
public static Path findPath(IPosition start, IPosition end) { if ((start instanceof Door) && (end instanceof Door)) { // start and end are doors return findDoorToDoorPath((Door) start, (Door) end); } Point2D startPoint = start.getCentralPoint(); Point2D endPoint = end.getCentralPoint(); Room room = Worl...
35c10319-458f-4be1-83a8-42dffc2633fc
7
public Map getRecordByID(String table, String primaryKeyField, Object keyValue, boolean closeConnection) throws SQLException, Exception { Statement stmt = null; ResultSet rs = null; ResultSetMetaData metaData = null; final Map record=new HashMap(); // do this in an excpetion handler so that we can depend o...
c8435e4b-ff47-40ea-943d-4f75d898642f
9
private static Method getMostSpecific(List methods, Class[] classes) throws AmbiguousException { LinkedList<Method> applicables = getApplicables(methods, classes); if(applicables.isEmpty()) { return null; } if(applicables.size() == 1) { ...
0aec1e90-f8b4-4b86-a47e-4ac7d9946bd4
5
private Sword getRandomSword() { switch (random.nextInt(5)) { case 0: return (Sword) Item.longSword; case 1: return (Sword) Item.claymore; case 2: return (Sword) Item.sabre; case 3: return (Sword) Item.heavenlyShortSword; case 4: return (Sword) Item.heavenlySword; default: return (Sword...
07d397ee-38b6-4339-b974-19d2fbd36e2e
1
@Override public String toString() { if (filterConfig == null) { return ("LoginFilter()"); } StringBuffer sb = new StringBuffer("LoginFilter("); sb.append(filterConfig); sb.append(")"); return (sb.toString()); }
c56678c2-a12f-4fbb-ad6a-b41b65092046
4
protected void printTopKChild4Parent(String filePrefix, int topK) { String topKChild4StnFile = filePrefix + "topChild4Parent.txt"; try { PrintWriter pw = new PrintWriter(new File(topKChild4StnFile)); for (_Doc d : m_trainSet) { if (d instanceof _ParentDoc) { _ParentDoc pDoc = (_ParentDoc) d; p...
683b1054-0530-4ce0-be75-a2d5f9c9e879
4
public void execute(String path) throws Exception { HttpURLConnection connection = getConnection(path); int code = connection.getResponseCode(); if (400 <= code && code <= 600) { CommandHelper.printErrorInformation(connection); return; } InputStream inp...
3d2ee7fb-c02b-4dcc-b8d9-6481c162f4a2
8
public void sampleQueryMenu() { boolean wantToQuit = false; while (!wantToQuit) { System.out.println("This is the sample query menu."); System.out.println("1. List titles of all projects, and the number of commits they have done on them."); Sy...
5569383b-7093-4ec6-bc65-c510e9e21c4c
4
public static List<Person> tallestTower(List<Person> lop) { // 1. sort the list of person based on height; List<Person> l1 = new ArrayList<>(lop); List<Person> l2 = new ArrayList<>(lop); Collections.sort(l1, new Comparator<Person>(){ @Override public int compare(Person p1, Person p2){ if ( p1.h...
dd0bc167-1a02-47e0-9115-27ff2107b436
4
@Override public ArrayList<Album> getAllAlbums(ResultSet rsetAlbum) throws SQLException { ArrayList<Album> albums = new ArrayList<Album>(); try { // for every album do... while (rsetAlbum.next()) { ResultSet rsetGenre; ResultSet rsetArtist; ResultSet rsetRating; ResultSet rsetReview; ...
de0d7a62-68eb-4ef1-a051-ac386721327f
6
private boolean horConnection(Colors color, int row, int col) { int connection = 1; for (int j = col - 1; j >= 0; j--) { if (board[row][j] == color) { ++connection; if (connection == 4) { return true; } } else { break; } } for (int j = col + 1; j < 7; j++) { if (board[row][j] =...
e49d1a32-db0d-487e-8a61-889d8e6debd8
4
public MapPoint translate(MapPoint original, int numSteps) { switch (this) { case NORTH: return original.cloneAndTranslate(0, numSteps); case SOUTH: return original.cloneAndTranslate(0, -numSteps); case EAST: return original.cloneAndTranslate(numSteps, 0); case WEST: return original.clone...
ec917bfb-3ba2-4185-843d-82bbdb9127b8
8
public void setup() { // We want to continue searching for starting solutions as long as we don't have any solutions and there is time left on the clock while (System.currentTimeMillis() < endTime && solutions.size() == 0) { // Begin by populating our solution set with random, valid solutions for (int ...
da315ec9-5d1d-4c8e-a0a5-aca467641597
3
public synchronized AudioDevice createAudioDevice() throws JavaLayerException { if (!tested) { testAudioDevice(); tested = true; } try { return createAudioDeviceImpl(); } catch (Exception ex) { throw new JavaLayerException("unable to create JavaSound device: "+ex); } catch (L...
61d6087c-f583-4fa0-9d68-9bbbf69c9e67
6
public void testConstructor_int_int_int_Chronology() throws Throwable { TimeOfDay test = new TimeOfDay(10, 20, 30, JulianChronology.getInstance()); assertEquals(JulianChronology.getInstanceUTC(), test.getChronology()); assertEquals(10, test.getHourOfDay()); assertEquals(20, test.getMinut...
ad074db6-b6e9-4f50-afe9-0e83b4718ab6
9
public void commitDirty() { PersistentBloatContext.comm("Committing dirty data"); // Commit all dirty fields Object[] array = this.fieldEditors.values().toArray(); for (int i = 0; i < array.length; i++) { final FieldEditor fe = (FieldEditor) array[i]; if (fe.isDirty() && !ignoreField(fe.memberRef())) { ...