id
stringlengths
36
36
text
stringlengths
1
1.25M
29825548-b964-4d5d-ae10-1ace5c669889
public boolean hasTwoCycles();
d038921e-baae-49ac-a53a-abb35e89285f
public boolean hasCycles();
74816538-c072-4a4d-ad48-2b189e65776e
public Map<Integer, List<Integer>> feedbackEdges();
f951bb3b-430b-4a08-b2a5-29fa50bb04b0
public static void main(String[] args) { MyGraph g = new MyGraph(); g.addNode(1); g.addNode(999); g.addNode(12); g.addNode(13); g.addNode(2); g.addEdge(1, 999); g.addEdge(12, 999); g.addEdge(999, 2); g.addEdge(999, 999); // introduce cycle g.addEdge(999, 1); if(g.hasNode(999)) System.out.println("Node 999 exists"); if(g.hasEdge(1, 999)) System.out.println("Edge exists between 1 -- 999"); System.out.println("\nprintAllNodes:"); g.printAllNodes(); System.out.println(); System.out.println("\nprintAllEdges:"); g.printAllEdges(); System.out.println("\nvisitDFS:"); List<Integer> dfs = g.visitDFS(1); for(Integer i : dfs) System.out.println(i); System.out.println("\nvisitBFS:"); List<Integer> bfs = g.visitBFS(1); for(Integer i : bfs) System.out.println(i); System.out.println(); if(g.hasSelfLoops()) System.out.println("SELF LOOP"); else System.out.println("NO SELF LOOP"); System.out.println(); if(g.isConnected()) System.out.println("Connected!"); else System.out.println("Not Connected!"); if(g.hasCycles()) System.out.println("\nCYCLE FOUND"); else System.out.println("\nNO CYCLE FOUND"); if(g.hasTwoCycles()) System.out.println("\nTwo cycles found"); else System.out.println("\nNo double cycles found"); }
0899b66d-861d-4243-88c0-0f77e2a2ecd6
public MyGraph readCSVFile(String filename);
5483706c-a6f1-4907-9ef3-6914951239df
@Override public MyGraph readCSVFile(String filename) { BufferedReader CSVFile = null; try { CSVFile = new BufferedReader(new FileReader(filename)); } catch(FileNotFoundException e1) { System.err.println(e1.getMessage()); } g = new MyGraph(); try { String dataRow = CSVFile.readLine(); while(dataRow != null && dataRow.length() != 0) { String[] dataArray = dataRow.split(","); int src = Integer.valueOf(dataArray[0]); g.addNode(src); for(int i = 1; i < dataArray.length; i++) g.addEdge(src, Integer.valueOf(dataArray[i])); dataRow = CSVFile.readLine(); } CSVFile.close(); } catch (IOException e2) { System.err.println(e2.getMessage()); } return g; }
945d1bfd-5960-44fe-a59f-8e78a35383de
public static void main(String[] args) { if(args.length == 0) { System.out.println("Usage: GraphMain [FILENAME]"); System.exit(1); } GraphMain graphMain = new GraphMain(); MyGraph graph = graphMain.readCSVFile( args[0]); }
cd67bd04-4eca-4772-bf5b-2f2f2d6b444f
public FeedEntry(JsonObject entry) { title = entry.get("title").asString(); link = entry.get("link").asString(); publishedDate = entry.get("publishedDate").asString(); author = entry.get("author").asString(); contentSnippet = entry.get("contentSnippet").asString(); content = entry.get("content").asString(); }
3b90eece-3124-44a5-851a-f773ffa22e26
public String getTitle() { return title; }
8b5a8747-9164-47c4-8b6b-97da99da5958
public String getLink() { return link; }
cdc310d4-2098-4bdb-8de4-abcf93debead
public String getPublishedDate() { return publishedDate; }
45640862-859d-492f-b55c-74ebeeba03ee
public String getAuthor() { return author; }
f5412797-d391-4878-9c3d-f1d4757aaf96
public String contentSnippet() { return contentSnippet; }
2b3350ba-acf7-4ab8-9607-345c804e86fb
public String getContent() { return content; }
2f9d1fb7-1108-4faf-83e0-ce9842f4835c
public Feed(String json) { try { JsonObject response = JsonObject.readFrom(json); JsonObject feed = JsonObject.readFrom(JsonObject.readFrom(response .get("responseData").toString()).get("feed").toString()); feedUrl = feed.get("feedUrl").asString(); title = feed.get("title").asString(); link = feed.get("link").asString(); author = feed.get("author").asString(); description = feed.get("description").asString(); type = feed.get("type").asString(); responseStatus = response.get("responseStatus").asInt(); JsonArray es = feed.get("entries").asArray(); for( JsonValue entry : es ) entries.add(new FeedEntry(entry.asObject())); } catch(ParseException e) { System.err.println("Incorrectly formatted JSON."); } }
1657330a-842e-45b9-92d7-fab2e8d3116d
public String getFeedUrl() { return feedUrl; }
57400f76-a315-43e9-8173-b79bf3ea1f3a
public String getTitle() { return title; }
b7bb43d9-cc3a-4f6a-b611-3c1e3f44212b
public String getLink() { return link; }
1e56913f-199c-42c3-806c-925064787141
public String getAuthor() { return author; }
b94ce8b6-ad51-4306-a224-124f7ba2a598
public String getDescription() { return description; }
f7b2743e-2eda-43c0-9315-37095b94156e
public String getType() { return type; }
9e8b020e-38ef-45e3-be18-bc6c2fe94949
public int getResponseStatus() { return responseStatus; }
f3763ce3-861b-4a81-9cb1-eb638b08baa4
public ArrayList<FeedEntry> getEntries() { return entries; }
eae122de-2b4f-4ad7-b124-de9a26b2ed8c
public Entry(JsonObject entry) { url = entry.get("url").asString(); title = entry.get("title").asString(); contentSnippet = entry.get("contentSnippet").asString(); link = entry.get("link").asString(); }
d459d182-6be6-4e91-93be-2b6b4934110b
public String getUrl() { return url; }
3cf7d3b6-5360-47bf-a0ba-51d3822956ab
public String getTitle() { return title; }
0764cb0b-f794-4cd3-98be-b794ad7e7e61
public String getContentSnippet() { return contentSnippet; }
996ece89-9137-4884-bc56-c5d8f77fe5bf
public String getLink() { return link; }
edf3cd72-2405-4a1f-8ea4-0a23ead4fce7
public String toString() { return title + "\n" + contentSnippet; }
163c75ab-8f44-4400-928c-93558abb0fc7
public static FeedList findFeeds(String query) { return new FeedList(getJson("find", query)); }
d4297456-61fd-4007-bb77-e2c8d12bfc80
public static Feed loadFeed(String url) { return new Feed(getJson("load", url)); }
cbdeea3d-6034-4b93-9ddc-a28d4d1e4b6a
private static String getJson(String action, String query) { try { url = new URL("https://ajax.googleapis.com/ajax/services/feed/"+ action + "?v=1.0&q=" + query); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setReadTimeout(15*1000); connection.connect(); reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); stringBuilder = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) stringBuilder.append(line + "\n"); return stringBuilder.toString(); } catch (MalformedURLException e) { return "{ responseStatus: 503 }"; } catch (IOException e) { return "{ responseStatus: 503 }"; } }
c2656c40-cde9-4603-aa5c-75bc5490dd07
public FeedList(String json) { try { JsonObject jsonObject = JsonObject.readFrom(json); JsonArray es = JsonObject.readFrom(jsonObject.get("responseData") .toString()).get("entries").asArray(); for( JsonValue entry : es ) entries.add(new Entry(entry.asObject())); responseStatus = jsonObject.get("responseStatus").asInt(); } catch(ParseException e) { System.err.println("Incorrectly formatted JSON."); } }
d528b78e-7b7b-470e-91dc-f8a321ca7db3
public int getResponseStatus() { return responseStatus; }
5dfb022e-d72f-4c91-ad39-1a7998c8d14b
public ArrayList<Entry> getEntries() { return entries; }
afa20ea8-784d-4907-97f5-1cdaef7c5b19
@Test public void findFeedsTest() { assertEquals(skyrimFeeds.getResponseStatus(), 200); }
334bd14e-734a-43d3-adf4-9c57e5c67417
@Test public void loadFeedTest() { assertEquals(skyrim.getResponseStatus(), 200); }
c74d5c3e-fecb-4d93-8503-338e558fbe00
@Test public void titleTest() { assertEquals(topSkyrimTitle, true); }
9b42f87d-7cef-49e7-9062-d24140ee4957
public TicketXml() { }
51fce6b4-4568-4ba4-b78a-d85739bcef6d
public TicketXml(TransaccionXml transaccion) { super(); this.transaccion = transaccion; }
a31292db-329e-46ea-852e-20dd97be3760
public TransaccionXml getTransaccion() { return transaccion; }
6ade4e10-ce86-474a-a3a5-ac21ff6ea7ac
@XmlElement(name = "NEW_TA", type = TransaccionXml.class) public void setTransaccion(TransaccionXml transaccion) { this.transaccion = transaccion; }
86955791-13af-4903-8879-d1ca1c16fe47
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("Ticket [transaccion="); builder.append(transaccion); builder.append("]"); return builder.toString(); }
6a5104d4-f95a-42ec-bc55-6a180f8fd0e5
public TransaccionHeaderXml getHeader() { return header; }
d1e59797-ddbe-4133-b7fb-a4f2f5688d3d
@XmlElement(name = "HEADER", type = TransaccionHeaderXml.class) public void setHeader(TransaccionHeaderXml header) { this.header = header; }
ce7c4025-6fef-4143-80ff-37acbcb2863d
public List<PartidaXml> getPartidas() { return partidas; }
ab1d6360-4845-4e58-ad14-d013ca534870
@XmlElement(name = "ART_SALE", type = PartidaXml.class) public void setPartidas(List<PartidaXml> partidas) { this.partidas = partidas; }
9af63dbd-a652-4467-9dfe-e24e02ab914e
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("TransaccionXml [header="); builder.append(header); builder.append(", partidas="); builder.append(partidas); builder.append("]"); return builder.toString(); }
ecd6a06d-64d2-45b3-9dcf-bb9251470ade
public Integer getId() { return id; }
24a332be-2e4c-4dad-9b45-64c8acb1c1a8
@XmlElement(name = "szPOSItemID") public void setId(Integer id) { this.id = id; }
b6a286e1-a514-44a8-a69b-f279e5561b79
public String getDescripcion() { return descripcion; }
a577f911-21a6-4429-80a8-71314f9a1bfc
@XmlElement(name = "szDesc") public void setDescripcion(String descripcion) { this.descripcion = descripcion; }
3e7dbf42-b12e-4997-a0c8-58a4ddae3928
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ArticuloXml [id="); builder.append(id); builder.append(", descripcion="); builder.append(descripcion); builder.append("]"); return builder.toString(); }
e7945f2f-097e-4d3c-9abf-d7a495b813d7
public Integer getIdSucursal() { return idSucursal; }
31fedda0-8597-470c-81d5-461791d893c6
@XmlElement(name = "lRetailStoreID") public void setIdSucursal(Integer idSucursal) { this.idSucursal = idSucursal; }
62477e4f-ff78-47de-9f30-a2ea8d759c8f
public Integer getIdTicket() { return idTicket; }
c2ed1166-9009-4029-a887-164ae71267ed
@XmlElement(name = "lTaNmbr") public void setIdTicket(Integer idTicket) { this.idTicket = idTicket; }
0f0b3475-db47-4ef7-a798-df4bb3c11e82
public Integer getIdCaja() { return idCaja; }
1826a203-f6b8-43bd-97e9-01207af74c5b
@XmlElement(name = "lWorkstationNmbr") public void setIdCaja(Integer idCaja) { this.idCaja = idCaja; }
ffc6bed4-fe5a-4bd0-be68-a115dabdc9b5
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("TransaccionHeaderXml [idSucursal="); builder.append(idSucursal); builder.append(", idTicket="); builder.append(idTicket); builder.append(", idCaja="); builder.append(idCaja); builder.append("]"); return builder.toString(); }
13ecbfbc-55f9-4932-b039-9d3d88f64f7a
public ArticuloXml getArticulo() { return articulo; }
83e06b85-1c16-41c6-be90-169746ae4988
@XmlElement(name = "ARTICLE", type = ArticuloXml.class) public void setArticulo(ArticuloXml articulo) { this.articulo = articulo; }
dae475a0-a903-4504-b2a2-672f16ce8de5
public Double getPrecio() { return precio; }
b4b35ee5-76aa-4597-9f1d-716e3a4e49ab
@XmlElement(name = "dTaPrice") public void setPrecio(Double precio) { this.precio = precio; }
417e86b2-f403-44fb-ac52-33d7af469a99
public Integer getCantidad() { return cantidad; }
7dd02f30-826e-4098-9645-032a2b02416f
@XmlElement(name = "dTaQty") public void setCantidad(Integer cantidad) { this.cantidad = cantidad; }
aaf68285-068c-480b-810f-df3d976f04fd
public Double getTotal() { return total; }
d76bf82b-3da2-4346-991c-acdb1c6267cf
@XmlElement(name = "dTaTotal") public void setTotal(Double total) { this.total = total; }
4d9cdc00-9b45-4dbb-823b-49ab29c4a1c4
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("PartidaXml [articulo="); builder.append(articulo); builder.append(", precio="); builder.append(precio); builder.append(", cantidad="); builder.append(cantidad); builder.append(", total="); builder.append(total); builder.append("]"); return builder.toString(); }
7e9b85c1-144e-4db3-9e24-792c8ae21994
@RequestMapping("/datosTicket") public String datosTicket(ModelMap model) throws IOException { log.debug("datos Ticket..."); model.put("ticketHeader", new TransaccionHeaderXml()); // SmbFileInputStream is = null; // try { // int suc = 999; // int caja = 98; // int ticket = 19; // String regex = suc + "_" + caja + "_" + ticket + "_\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\.xml"; // log.debug(regex); // Pattern pattern = Pattern.compile(regex); // Matcher matcher = pattern.matcher("999_98_19_20131101101115.xml"); // log.debug("existe?" + matcher.matches()); // log.debug("Recuperando el flujo del archivo"); // Config.setProperty("jcifs.smb.client.useExtendedSecurity", "false"); // is = new SmbFileInputStream("smb://10.2.200.149/users/equipoDesarrollo03/Documents/ovelasco/DocumentosIncidentes/999_98_19_20131101101115.xml"); //// is = new SmbFileInputStream("smb://10.2.200.129/cfdi/999_98_19_20131101101115.xml"); // TicketXml ticketXml = (TicketXml) unmarshaller.unmarshal(new StreamSource(is)); // log.debug("El ticket " + ticketXml); // } finally { // if (is != null) { // is.close(); // } // } return "factura/datosTicket"; }
b4cee6bf-f55c-42ef-91af-8be6e96956ec
@RequestMapping(value="/validarTicket", method=RequestMethod.POST) public String validarTicket(@ModelAttribute("ticketHeader") TransaccionHeaderXml ticketHeader, ModelMap model) { TransaccionXml transaccion = new TransaccionXml(); transaccion.setHeader(ticketHeader); TicketXml ticket = new TicketXml(transaccion); model.put("ticket", ticket); log.debug("ticket" + ticket); return "factura/resultadoTicket"; }
83de247f-ec07-4f29-a8f2-6e75ff790335
public static void main(String[] args) throws MalformedURLException, SmbException { Config.setProperty("jcifs.smb.client.useExtendedSecurity", "false"); int suc = 999; int caja = 98; int ticket = 19; String regex = suc + "_" + caja + "_" + ticket + "_\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\.xml"; // String regex = suc + "_" + caja + "_" + ticket + "_\\d+.xml"; log.debug(regex); Pattern pattern = Pattern.compile(regex); SmbFile dir = new SmbFile("smb://10.2.200.125/compartido/"); if(dir.exists()) { SmbFile[] files = dir.listFiles(); for (SmbFile file : files) { Matcher matcher = pattern.matcher(file.getName()); log.debug(file.getName()); if (matcher.matches()) { log.debug("se ha encontrado una coincidencia"); } } } }
228e8bbd-8e15-47c4-bed8-0ccb445064af
public static String[] readFile(String file){ return readFile(new File(file)); }
76191aff-5468-41f4-86f3-2f77539ba86e
public static String[] readFile(File file){ try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); String line; ArrayList<String> lines = new ArrayList<String>(); while((line = br.readLine()) != null) { lines.add(line); } br.close(); String[] output = new String[lines.size()]; return lines.toArray(output); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return new String[0]; }
303c246c-6097-4184-8a4a-1d59fc8480df
public static void writeFile(String file, String[] lines) { writeFile(new File(file), lines); }
1c2cefa3-ebc5-4f1e-970f-48f6c1abb548
public static void writeFile(File file, String[] lines){ try { PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); for(String s : lines){ pw.println(s); } pw.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
49415fdd-5072-4d13-99a7-5429cc863e42
public static void writeLine(String file, String line) { writeLine(new File(file), line); }
879a5592-68e7-40a2-904a-7db458a2036e
public static void writeLine(File file, String line){ try { PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8")); pw.println(line); pw.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
a5008cba-76bc-4138-b0dd-a0a44329d31f
public static boolean copyFile(String src, String dest) { return copyFile(new File(src), new File(dest)); }
5ef5df3c-31ac-465e-8913-97345ee1df5e
public static boolean copyFile(File src, File dest) { try { FileInputStream fis = new FileInputStream(src); FileOutputStream fos = new FileOutputStream(dest); byte[] data = new byte[1024]; while(fis.read(data) != -1) { fos.write(data); } fis.close(); fos.flush(); fos.close(); return true; } catch (IOException e) { e.printStackTrace(); } return false; }
1566e5c1-fc8e-485d-96b6-2a85b52fbb6d
public static boolean moveFile(String src, String dest) { return moveFile(new File(src), new File(dest)); }
e8b345bc-c3ef-4951-9acb-0a0ccd9bc1a3
public static boolean moveFile(File src, File dest) { if(copyFile(src, dest)) { src.delete(); return true; } return false; }
2c291d3c-c7f9-441a-8253-badc7ee700fb
public SoundStream(File file) { try { killThread = false; soundFile = file; ais = AudioSystem.getAudioInputStream(soundFile); AudioFileFormat af = AudioSystem.getAudioFileFormat(soundFile); soundLine = AudioSystem.getSourceDataLine(af.getFormat()); soundLine.open(af.getFormat()); initLineWriter(); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } }
b46a30e2-2e48-4d20-9fca-64ee5cd81279
public SoundStream(String loc) { this(new File(loc)); }
46cd1512-4e96-47c9-a816-fd5fa69b1c15
private void initLineWriter() { lineWriter = new Thread() { public void run() { byte[] data = new byte[1024]; try { while(!killThread) { if(playing) { if(ais.available() > 0) { ais.read(data); soundLine.write(data, 0, data.length); } else if(repeating) { resetAudio(); } else { SoundStream.this.stop(); } } else { threadPause(); } } } catch (IOException e) { e.printStackTrace(); } } }; lineWriter.start(); System.out.println("running!"); }
ea393f0f-dc7e-4fcc-86dc-d7223f4ba264
public void run() { byte[] data = new byte[1024]; try { while(!killThread) { if(playing) { if(ais.available() > 0) { ais.read(data); soundLine.write(data, 0, data.length); } else if(repeating) { resetAudio(); } else { SoundStream.this.stop(); } } else { threadPause(); } } } catch (IOException e) { e.printStackTrace(); } }
9001dfa5-bacd-48cd-aab1-de640211a3ad
private synchronized void threadPause() { try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } }
08c7b94e-088f-4528-a590-8697471516fb
private synchronized void threadResume() { notify(); }
7a5241ae-e6cf-4a9c-bd6c-5a020d675200
@Override public void start() { soundLine.start(); playing = true; threadResume(); }
0a9bf595-8169-4d20-85de-5ef24b14cf25
@Override public void stop() { pause(); soundLine.flush(); resetAudio(); }
c64e05c8-2304-42ae-add0-36ca1cb71421
@Override public void pause() { soundLine.stop(); playing = false; }
a08832a6-0f40-48c2-8f59-bce7153225d8
public void close() { killThread = true; threadResume(); try { ais.close(); } catch (IOException e) { e.printStackTrace(); } soundLine.close(); }
50836585-118d-40a7-bd85-eaae8a8bdad8
@Override public void setRepeat(boolean repeat) { repeating = repeat; }
757add19-06d9-4ea9-a8e4-858f6657e981
@Override public boolean setVolume(float value) { if(soundLine.isControlSupported(FloatControl.Type.VOLUME)) { FloatControl volume = (FloatControl) soundLine.getControl(FloatControl.Type.VOLUME); volume.setValue(value); return true; } else if(soundLine.isControlSupported(FloatControl.Type.MASTER_GAIN)) { FloatControl volume = (FloatControl) soundLine.getControl(FloatControl.Type.MASTER_GAIN); volume.setValue(value); return true; } return false; }
0ee0cb19-d6b1-438b-9187-1e4189a75388
private void resetAudio() { try { ais.close(); ais = AudioSystem.getAudioInputStream(soundFile); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
6a618c23-bf49-44d4-b552-ce193e8bf1f6
public SoundClip(File file) { soundFile = file; try { soundClip = AudioSystem.getClip(); AudioInputStream aus = AudioSystem.getAudioInputStream(soundFile); soundClip.open(aus); } catch (LineUnavailableException e) { e.printStackTrace(); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
2f7414a7-1ab5-4474-b9c7-78b8dd2194b9
public SoundClip(String loc) { this(new File(loc)); }
f4f748f9-5d5f-4092-b4fc-7026c307e14d
@Override public void start() { soundClip.start(); playing = true; }
bc899ae3-c63b-4531-b737-fc6e521f4058
@Override public void stop() { pause(); soundClip.flush(); soundClip.setFramePosition(0); }
4f8a9347-c813-49bf-ab95-81cb2e36f6d7
@Override public void pause() { soundClip.stop(); playing = false; }