id
stringlengths
36
36
text
stringlengths
1
1.25M
1aaa956e-2617-4d80-adce-e9821765c801
public void setGenero(JogosGenero genero) { this.genero = genero; }
1026ced1-c6e0-4318-8454-f1ba2ba1b560
public List<EdicaoJogo> getEdicoes() { return edicoes; }
5eacef9a-e6d1-4588-ba33-b425d903fc80
public void setEdicoes(List<EdicaoJogo> edicoes) { this.edicoes = edicoes; }
f20dfb16-a50e-407f-9d8f-81cb368e8a60
public EdicaoJogo addEdicao(EdicaoJogo edicao) { getEdicoes().add(edicao); edicao.setJogo(this); return edicao; }
e76edb84-45e1-480b-8720-451bc0f5b6dc
public EdicaoJogo removeEdicao(EdicaoJogo edicao) { getEdicoes().remove(edicao); edicao.setJogo(null); return edicao; }
7016cba0-b0f9-4168-bba4-7b1b1027db82
public List<Usuario> getUsuarios() { return this.usuarios; }
9550f2d8-0010-4662-ba38-ddd747bd2168
public void setUsuarios(List<Usuario> usuarios) { this.usuarios = usuarios; }
27d6bc86-00b6-427b-ab29-35e9976233fd
public EdicaoJogo() { }
0e025b4a-2fc9-4721-8854-15b70eef7da4
public Long getCodigo() { return this.codigo; }
d11ed3f0-dfce-4889-9b46-ca8c2ab2ddd8
public void setCodigo(Long codigo) { this.codigo = codigo; }
ce5d1a27-b38c-4a07-a8f9-d94bf763e980
public String getDescricao() { return this.descricao; }
9e51af50-bc91-4900-81f2-9a8712b5f229
public void setDescricao(String descricao) { this.descricao = descricao; }
f34a157f-3b73-43ee-a888-02a4a1cecf03
public Jogo getJogo() { return this.jogo; }
7e365621-339d-4512-9dce-9b31a0b31de2
public void setJogo(Jogo jogo) { this.jogo = jogo; }
fd001a3c-ba4a-47ae-b4bf-57b7649717a3
public AutoridadeUsuario() { }
26e5acd0-a4ac-4fe0-bc27-a699766cefe5
public Usuario getUsuario() { return this.usuario; }
332bd015-8df9-468c-82d6-13f681de4951
public void setUsuario(Usuario usuario) { this.usuario = usuario; }
28193a70-c09a-4dae-96f2-71f49d25e3c1
public Autoridade getAutoridade() { return this.autoridade; }
4ff6b270-fb07-41f8-8026-f3f0f193e2c3
public void setAutoridade(Autoridade autoridade) { this.autoridade = autoridade; }
32627e6c-dae7-4b73-b8d8-34f5722b77c3
@Before public void beforeStarts(){ entityManager = VGXORMTestUtil.getEntityManagerFactory().createEntityManager(); }
21944d6f-7b28-413b-b51b-ed729b7b34a3
@Test @Transactional public void testeSalvarComAutoridade() throws Exception{ Usuario usuario = new Usuario(); usuario.setEmail("[email protected]"); usuario.setUsuariosAutoridade(new AutoridadeUsuario()); entityManager.persist(usuario); entityManager.flush(); }
894b3d22-87f1-4413-95fa-47edf4182291
@Test @Transactional public void testeSalvarBuscar() throws Exception{ String email = "[email protected]"; Usuario usuario = new Usuario(); usuario.setEmail(email); usuario.setUsuariosAutoridade(new AutoridadeUsuario()); entityManager.persist(usuario); entityManager.flush(); entityManager.clear(); Usuario usuarioBusca = (Usuario) entityManager.find(Usuario.class, email); Assert.assertEquals(email, usuarioBusca.getEmail()); }
891f512e-1a8c-4e68-8f07-967d2da4f8e5
public static EntityManagerFactory getEntityManagerFactory() { return Persistence.createEntityManagerFactory("vgx-test"); }
a96b327f-490a-47d4-866e-62e98c7741ae
@RequestMapping(value = "/", method = RequestMethod.GET) public String home(Locale locale, Model model) { logger.info("Welcome home! The client locale is {}.", locale); Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate ); return "home"; }
83cd09e7-5215-423e-a7b3-cfc455bb5854
public TetrisGrid(boolean[][] grid) { this.grid = grid; }
2a1d7410-d7aa-4536-8f49-711ae58fee28
public void clearRows() { clearRowsFromRow(0); }
5b0cf5ee-844c-4fb8-8056-db0f8817ba6f
private void clearRowsFromRow(int row) { for ( int y=0; y < grid[0].length; ++y ) { boolean shouldClear = true; for ( int x=0; x < grid.length; ++x ) { if ( !grid[x][y] ) { shouldClear = false; } } // clear this row (if necessary) and then recursively clear from same spot if ( shouldClear ) { collapseRowsFromRow(y); clearRowsFromRow(y); } } }
aceb30a9-6557-4d58-a0c8-73858b4c6656
private void collapseRowsFromRow(int row) { for ( int y=row+1; y < grid[0].length; ++y ) { for ( int x=0; x < grid.length; ++x ) { grid[x][y-1] = grid[x][y]; } } // clear the "top" row, setting to false for ( int x=0; x < grid.length; ++x ) { grid[x][grid[0].length-1] = false; } }
9ac560f1-4ff3-4023-8688-4596e2847ac6
public boolean[][] getGrid() { return grid; }
00814825-7f80-4139-96d0-0a2e313bd5e8
public void display() { displayBar(); displayGrid(); displayBar(); }
ee5e055c-7ad2-44bb-9037-874d82d86d6e
private void displayBar() { for ( int i=0; i < grid.length; ++i ) { System.out.print( i < grid.length-1 ? "__" : "_\r\n" ); } }
ea2d88b9-9dd8-423e-a0ac-7d5e32a18a81
private void displayGrid() { for ( int y=grid[0].length-1; y >= 0; --y ) { for ( int x=0; x < grid.length; ++x ) { System.out.print(grid[x][y] ? "x " : " "); } System.out.println(""); } }
c8b6a97a-5ab5-4138-8487-d9c321b7653b
public static String blowup(String str) { return blowupFromIndex(str,0); }
3f8c4b27-a2ca-417c-9ea4-21fdd1dc0a2a
private static String blowupFromIndex(String str,int index) { // if string is empty, nothing to do if ( str.length() == 0 ) { return ""; } // set up variables String newString = null, token = null; StringBuffer buffer = null; // start at index, and step forward, stopping if we find any digits for ( int i=index; i < str.length(); ++i ) { // check if we are at the end, and if so terminate recursion char c = str.charAt(i); if ( i == str.length() - 1 ) { return Character.isDigit(c) ? str.substring(0,i) : str; } // build a new string and recursively invoke the // procedure on the remaining string elements if ( Character.isDigit(c) ) { char d = str.charAt(i+1); buffer = new StringBuffer(); int x = Integer.parseInt(Character.toString(c)); for ( int j=0; j < x; ++j ) { buffer.append(d); } token = buffer.toString(); newString = str.substring(0,i) + token + str.substring(i+1); return blowupFromIndex(newString, i+token.length()); } } // terminate recursion, if necessary return str; }
28b98e66-aaaa-43e8-8f54-4b6af22832da
public static int maxRun(String str) { // handle corner cases if ( str.length() == 0 ) { return 0; } if ( str.length() == 1 ) { return 1; } // handle general case int sample = 0, max = 0; for ( int i=0; i < str.length()-1; ++i ) { if ( ( sample = countRunFromIndex(str,i)) > max ) { max = sample; } } return max; }
fad08077-3470-483a-ba11-9a02d9341ee7
private static int countRunFromIndex(String str,int index) { // if index is out of bounds, throw a new exception if ( index < 0 || index > str.length() - 2 ) { throw new IllegalArgumentException("Index out of bounds ["+index+"]: "+str); } // count the run, starting at index (will always be at least "1") int count = 1; for ( int i=index; i < str.length()-1; ++i ) { char c = str.charAt(i); char d = str.charAt(i+1); if ( c == d ) { count++; } else { break; } } return count; }
51b96868-0d2e-4f1d-a9b6-7b7bc624d22f
public static boolean stringIntersect(String a, String b, int len) { // the size of intersection must be at least 1 if ( len < 1 ) { throw new IllegalArgumentException("Size of intersection must be at least 1: " + len); } // generate the substrings Set<String> s1 = generateSubstrings(a,len); Set<String> s2 = generateSubstrings(b,len); // find the intersection s1.retainAll(s2); return s1.size() > 0; }
403fe3a9-52ad-4b73-a8ee-9ac3ac3fdd86
private static Set<String> generateSubstrings(String str, int len) { Set<String> set = new HashSet<String>(); for ( int i=0; i < str.length() - len + 1; ++i ) { set.add(str.substring(i,i+len)); } return set; }
369b5207-f437-4f13-a583-78584a23b8ca
@Test public void testBlowup1() { assertEquals("attttxzzz", StringCode.blowup("a3tx2z")); assertEquals("2xxx", StringCode.blowup("12x")); }
671dadcd-752f-4c5d-8c71-a732d6e0fb09
@Test public void testBlowup2() { assertEquals("xxaaaabb", StringCode.blowup("xx3abb")); assertEquals("xxxZZZZ", StringCode.blowup("2x3Z")); }
4331c68a-f1b6-4d62-9a6f-8aca0462ddc5
@Test public void testBlowup3() { assertEquals("axxx", StringCode.blowup("a2x3")); assertEquals("a33111", StringCode.blowup("a231")); assertEquals("aabb", StringCode.blowup("aa0bb")); }
9e3cf096-69b7-4b73-9571-696bf372d96c
@Test public void testBlowup4() { assertEquals("AB&&,- ab", StringCode.blowup("AB&&,- ab")); assertEquals("", StringCode.blowup("")); assertEquals("", StringCode.blowup("2")); assertEquals("abc", StringCode.blowup("abc")); assertEquals("ABC", StringCode.blowup("ABC")); assertEquals("33", StringCode.blowup("23")); }
622e427b-1320-4759-b7a4-deb46c92e044
@Test public void testMaxRun1() { // test the corner cases assertEquals(0, StringCode.maxRun("")); assertEquals(1, StringCode.maxRun("1")); assertEquals(1, StringCode.maxRun("a")); assertEquals(1, StringCode.maxRun("b")); assertEquals(1, StringCode.maxRun("c")); }
40e3c789-deff-4973-86fc-59b5f0ce1f4f
@Test public void testMaxRun2() { assertEquals(2, StringCode.maxRun("xx")); assertEquals(3, StringCode.maxRun("xxx")); assertEquals(3, StringCode.maxRun("xxxa")); assertEquals(3, StringCode.maxRun("xxaaxxxbazc1")); assertEquals(3, StringCode.maxRun("xxxaxxx")); }
3ec42e03-53fc-419f-a9d5-155941c9a85c
@Test public void testMaxRun3() { assertEquals(3, StringCode.maxRun("xxyyyz")); assertEquals(1, StringCode.maxRun("xyz")); }
194dbd3c-7511-4f08-8214-f6270421d100
@Test public void testMaxRun4() { assertEquals(2, StringCode.maxRun("hoopla")); assertEquals(3, StringCode.maxRun("hoopllla")); }
d9c885ef-b29a-4aef-a80f-63d13cd3ce38
@Test public void testMaxRun5() { assertEquals(3, StringCode.maxRun("abbcccddbbbxx")); assertEquals(0, StringCode.maxRun("")); assertEquals(3, StringCode.maxRun("hhhooppoo")); }
26e530c7-d2b3-47ee-9b2b-279c05368408
@Test public void testMaxRun6() { assertEquals(1, StringCode.maxRun("123")); assertEquals(2, StringCode.maxRun("1223")); assertEquals(2, StringCode.maxRun("112233")); assertEquals(3, StringCode.maxRun("1112233")); }
81e46585-aae2-463c-91cf-c155fe99239c
@Test public void testIntersection1() { String s1 = "one"; String s2 = "one two"; assertEquals(true, StringCode.stringIntersect(s1,s2,1)); assertEquals(true, StringCode.stringIntersect(s1,s2,2)); assertEquals(true, StringCode.stringIntersect(s1,s2,3)); assertEquals(false, StringCode.stringIntersect(s1,s2,4)); assertEquals(false, StringCode.stringIntersect(s1,s2,5)); }
40786c27-9b74-44a2-a0a0-13e173e8fc1a
@Test public void testIntersection2() { String s1 = "this is my xxx"; String s2 = "yxxx"; assertEquals(true, StringCode.stringIntersect(s1,s2,1)); assertEquals(true, StringCode.stringIntersect(s1,s2,2)); assertEquals(true, StringCode.stringIntersect(s1,s2,3)); assertEquals(false, StringCode.stringIntersect(s1,s2,4)); assertEquals(false, StringCode.stringIntersect(s1,s2,5)); }
db6c3373-5782-4d8b-8146-85d48cfc15af
@Test public void testIntersection3() { String s1 = "xxxthis is a test"; String s2 = "now now nowxxx"; assertEquals(true, StringCode.stringIntersect(s1,s2,1)); assertEquals(true, StringCode.stringIntersect(s1,s2,2)); assertEquals(true, StringCode.stringIntersect(s1,s2,3)); assertEquals(false, StringCode.stringIntersect(s1,s2,4)); assertEquals(false, StringCode.stringIntersect(s1,s2,5)); }
d17ebe8a-352c-4adb-8c0b-291ec347d40b
@Test public void testIntersection4() { String s1 = "The Tarantula Nebula in the Large Magellanic Cloud, a companion galaxy to the Milky Way, is called a nursery for new stars."; String s2 = "The growing awareness of plasma should make it also a nursery for new ideas to explain its features."; // the largest common substring will be " a nursery for new ", which contains 19 characters assertEquals(true,StringCode.stringIntersect(s1, s2, 19)); assertEquals(false,StringCode.stringIntersect(s1, s2, 20)); }
45477ed6-daec-4a59-a1ba-f9b8a43fcce0
public JTetris(int pixels) { super(); }
79d3cfa6-8577-4027-94c9-ebd57727f7e5
public JComponent createControlPanel() { JPanel panel = new JPanel(); return panel; }
084c90fe-4184-4fa5-8cdb-0a1378845f90
public static JFrame createFrame(JTetris tetris) { // configure the frame container JFrame frame = new JFrame("Stanford Tetris"); JComponent container = (JComponent)frame.getContentPane(); container.setLayout(new BorderLayout()); int unitWidth = 150; int unitHeight = 100; JPanel center = new JPanel(); center.setPreferredSize(new Dimension(unitWidth,unitHeight)); center.setBackground(Color.black); container.add(center,BorderLayout.CENTER); JButton button = new JButton("here"); center.add(button); JPanel west = new JPanel(); west.setPreferredSize(new Dimension(unitWidth,unitHeight)); west.setBackground(Color.red); container.add(west,BorderLayout.WEST); JPanel east = new JPanel(); east.setPreferredSize(new Dimension(unitWidth,unitHeight)); east.setBackground(Color.green); container.add(east,BorderLayout.EAST); JPanel north = new JPanel(); north.setPreferredSize(new Dimension(3*unitWidth,unitHeight/2)); north.setBackground(Color.blue); container.add(north,BorderLayout.NORTH); JPanel south = new JPanel(); south.setPreferredSize(new Dimension(3*unitWidth,unitHeight/2)); south.setBackground(Color.yellow); container.add(south,BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); return frame; }
4a68eb41-d7f0-44f2-923d-e11eabbbb45f
public static void main(String[] args) { // configure look and feel of the app try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch ( Exception ignored ) { } // configure and display the game itself JTetris tetris = new JTetris(16); JFrame frame = JTetris.createFrame(tetris); frame.setVisible(true); UIManager.LookAndFeelInfo[] feels = UIManager.getInstalledLookAndFeels(); for ( UIManager.LookAndFeelInfo feel : feels ) { System.out.println(feel); } }
42ef7163-f6cf-4cc6-a9cc-81f307fdc6e6
public static void main(String[] args) { int[] arr = {3, 2, 8, 9, 4, 5, 7, 10, 1}; for (int i = 1; i < arr.length; i++) { int temp = arr[i]; int cur = i; while (cur > 0 && arr[cur - 1] >= temp) { arr[cur] = arr[cur - 1]; cur--; } arr[cur] = temp; } for (int i : arr) { System.out.print(i + " "); } System.out.println(); }
d9efbcbd-d3c3-473f-9a1d-904220ffd513
public MyStack(int N) { maxSize = N; arr = new char[N]; top = -1; }
454c5f72-386a-4753-bf62-1dc05b65f9ea
public void push(char c) { arr[++top] = c; }
df8ef42d-2ddf-418e-be73-de660d023d18
public char pop() { return arr[top--]; }
331cf7a8-2fd8-472b-b5e9-39b962ec365f
public char peek() { return arr[top]; }
0995dfdc-8725-4074-9e3c-69ac9119a101
public boolean isEmpty() { return (top == -1); }
03192851-7684-4a49-9c8f-825a7c539f7f
public boolean isFull() { return (top == maxSize - 1); }
bcc463d9-82e2-46e2-aeff-6b467a48daa1
public static void main(String[] args) throws Exception { MyStack ms = new MyStack(10); String s = "a{b(c[d]e)f}"; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '{' || c == '(' || c == '[') { ms.push(c); } else if (c == '}' || c == ')' || c == ']') { if (!ms.isEmpty()) { char cc = ms.pop(); if (!((cc == '{' && c == '}') || (cc == '(' && c == ')') || (cc == '[' && c == ']'))) { throw new Exception("Error, doesn't match!"); } } else { System.out.println("Error, doesn't match!"); break; } } } s = "a{b(c[d]e[f}"; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '{' || c == '(' || c == '[') { ms.push(c); } else if (c == '}' || c == ')' || c == ']') { if (!ms.isEmpty()) { char cc = ms.pop(); if (!((cc == '{' && c == '}') || (cc == '(' && c == ')') || (cc == '[' && c == ']'))) { throw new Exception("Exception: Error, doesn't match!"); } } else { System.out.println("Error, doesn't match!"); break; } } } if (!ms.isEmpty()) { System.err.println("Error, doesn't match!"); } }
f6f93d88-98e1-41a1-a448-fe117dbf6e18
public void LinkedList() { //empty }
2ee4d060-b9b7-4a61-a15f-774e2cd3f728
public boolean isEmpty() { return (first == null); }
39a37b87-8c71-41d8-9de6-f6b3636fb740
public void insertFirst(int data) { Link newLink = new Link(data); if (isEmpty()) { last = newLink; } else { first.prev = newLink; } newLink.next = first; first = newLink; }
7da0d042-e995-4ba6-8bbf-15e0922ec5fa
public void insertLast(int data) { Link newLink = new Link(data); if (isEmpty()) { first = newLink; } else { last.next = newLink; newLink.prev = last; } last = newLink; }
b0ceb266-f970-4829-aa3e-c56411ba23f3
public Link removeFirst() { Link temp = first; if (first.next == null) { last = null; } else { first.next.prev = null; } first = first.next; return temp; }
959cb366-d668-486e-896f-1fbe5126725d
public Link removeLast() { Link temp = last; if (first.next == null) { first = null; } else { last.prev.next = null; } last = last.prev; return temp; }
a1dbe437-3c3c-4708-bf7d-5ddd40715670
public static void main(String[] args) { LinkedList list = new LinkedList(); list.insertFirst(0); list.insertFirst(2); list.insertLast(3); list.insertFirst(1); list.insertLast(5); list.insertLast(4); }
f80121a5-d35a-4947-80a4-2ebb5500a858
public Link(int data) { this.data = data; }
326a4705-e741-48dc-8eaf-6eb981e76ff6
static int power(int x, int y) { if (y == 1) { return x; } else { return power(x * x, y >> 1) * (y % 2 == 1 ? x : 1); } }
c98d509a-0e18-461b-b27c-14a63dccc24c
public static void main(String[] args) { int x = 2; int y = 17; int z = power(x, y); System.out.println(z); x = 3; y = 18; int sisa = 0, base = x, s = 0; List<Integer> list = new ArrayList<Integer>(); while (y > 1) { ++s; if (y % 2 == 1) { list.add(x); } x *= x; y >>= 1; } for (int i : list) { x *= i; ++s; } System.out.println("Total step : " + s); System.out.println(x); }
cd6e6b6b-e05c-4560-9dff-b80313a2cfcb
public static void main(String[] args) { int[] arr = {3, 2, 8, 9, 4, 5, 7, 10, 1}; for (int i = arr.length - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (arr[j] > arr[i]) { arr[j] ^= arr[i]; arr[i] ^= arr[j]; arr[j] ^= arr[i]; } } } for (int i : arr) { System.out.print(i + " "); } System.out.println(); }
8b9a03c0-952f-4e8e-afff-d5d9916cb651
public MyQueue(int N) { maxSize = N; arr = new int[N]; nItem = 0; front = 0; rear = -1; }
7d515eb0-bf0c-4e1c-9e6b-74de6505d8b9
public void insert(int x) throws Exception { if (nItem == maxSize) { throw new Exception("Q is full"); } arr[++rear] = x; if (rear == maxSize - 1) { rear = -1; } nItem++; }
1bbbc468-91ea-4f7e-acf7-4db8146da04f
public int size() { return nItem; }
2c26c45b-f9e3-42e6-84c6-53f8c42c1bcd
public int poll() { nItem--; int res = arr[front++]; if (front == maxSize) { front = 0; } return res; }
1ee991ad-f8b5-48a5-afa4-e8f6ef0c93f4
public boolean isEmpty() { if (nItem == 0) { front = 0; rear = -1; return true; } return false; }
ef7e119b-c896-44f8-9c28-55b6a751ab5e
public boolean isFull() { return (nItem == maxSize - 1); }
b6d9b7aa-4c8a-4b53-8ad1-72abac1a9c2a
public static void main(String[] args) throws Exception { MyQueue mq = new MyQueue(10); mq.insert(0); mq.insert(-1); mq.insert(20); mq.insert(21); int ind = 0; while (!mq.isEmpty()) { System.out.println(mq.poll()); ind++; if (ind == 1) { break; } } System.out.println("size : " + mq.size()); mq.insert(4); mq.insert(3); mq.insert(2); mq.insert(1); mq.insert(0); mq.insert(-1); mq.insert(-2); while (!mq.isEmpty()) { System.out.println(mq.poll()); } mq.insert(4); mq.insert(3); mq.insert(2); while (!mq.isEmpty()) { System.out.println(mq.poll()); } }
c465f943-2dc6-40f8-ba98-7d90956b8e7d
public static void main(String[] args) { HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("a", map.get("a") + 1); int[] arr = {3, 2, 8, 9, 4, 5, 7, 10, 1}; for (int i = 0; i < arr.length; i++) { int ind = i; for (int j = i + 1; j < arr.length; j++) { if (arr[j] < arr[ind]) { ind = j; } } if (ind != i) { arr[i] ^= arr[ind]; arr[ind] ^= arr[i]; arr[i] ^= arr[ind]; } } for (int i : arr) { System.out.print(i + " "); } System.out.println(); }
53c8635d-2b4c-4368-95fe-8e53a7548719
public SortedList() { }
6cd2cb72-8ea4-4970-80ea-d76f2f75a389
public void offer(int data) { Link newItem = new Link(data); Link cur = first; Link prev = null; while (cur != null && newItem.data > cur.data) { prev = cur; cur = cur.next; } if (prev == null) { first = newItem; } else { prev.next = newItem; } newItem.next = cur; }
1d8023a2-2efa-4ecc-aa4f-a356c4059237
public boolean isEmpty() { return (first == null); }
4eaf4f8b-4d10-49d4-b4d9-a0c46b4330ba
public Link poll() { Link ret = first; first = first.next; return ret; }
f6791c45-4087-4bb6-b55d-62d44f021d5c
public static void main(String[] args) { SortedList sl = new SortedList(); sl.offer(4); sl.offer(1); sl.offer(6); sl.offer(5); sl.offer(0); while (!sl.isEmpty()) { System.out.println(sl.poll().data); } }
5980b9d4-3d47-48fc-be02-5a18903bc48d
public Link(int data) { this.data = data; }
3ba0bd69-6614-4075-90a2-77dc45b2b8fe
static List<Integer> sort(List<Integer> arr) { if (arr.size() <= 1) { return arr; } int mid = arr.size() / 2; List<Integer> left = new ArrayList<Integer>(); List<Integer> right = new ArrayList<Integer>(); for (int i = 0; i < mid; i++) { left.add(arr.get(i)); } for (int i = mid; i < arr.size(); i++) { right.add(arr.get(i)); } left = sort(left); right = sort(right); return merge(left, right); }
512f7a12-103c-4de2-bad2-899904080a68
static List<Integer> merge(List<Integer> left, List<Integer> right) { List<Integer> result = new ArrayList<Integer>(); while (left.size() > 0 && right.size() > 0) { if (left.get(0) <= right.get(0)) { result.add(left.remove(0)); } else { result.add(right.remove(0)); } if (left.isEmpty() && right.size() > 0) { result.addAll(right); } if (right.isEmpty() && left.size() > 0) { result.addAll(left); } } return result; }
aeae7211-92bb-4f56-b575-32db1de889eb
public static void main(String[] args) { int[] arr = new int[]{3, 4, 1, 9, 6, 8, 3, 4}; List<Integer> list = new ArrayList<Integer>(); for (int i : arr) { list.add(i); } list = sort(list); for (int i : list) { System.out.print(i + " "); } }
48871319-3e91-47aa-b6b4-7ec2aadab9b9
@Override public Sequence fromByteArray(byte[] bytes) throws BinaryReaderException { if (bytes.length != SIZE){ throw new BinaryReaderException("Illegal Byte Array Size: "+bytes.length+" (Expected "+SIZE+")"); } long code = 0; byte len = bytes[0]; for (int i=1; i<9; i++){ code = code << 8; int b = 255 & bytes[i]; code = code | b; } return new Sequence(code, len); }
adfdb207-6cfe-4d5d-bec8-9f6b4541b48e
@Override public byte[] toByteArray(Sequence object) { long code = object.getLong(); byte len = object.getLength(); int mask = 255; byte[] bytes = new byte[9]; bytes[0]=len; for (int i = 8; i > 0; i--){ byte b = (byte)(code & mask); bytes[i]=b; code = code>>8; } return bytes; }
cd079a75-ddba-49da-8436-4fe149bc4f43
@Override public int sizeOf() { return SIZE; }
d5185051-e0ef-4d15-ada1-1a8de55a2bf5
public static void main(String[] args) { // TODO Auto-generated method stub int cacheOption = 0; int degree = 5; int seqLength = 14; int cacheSize = 4; int debugLevel = 0; String gbkFileName = args[2]; File gbkFile = new File (gbkFileName); //BTree btree; Cache<Sequence> cache; BufferedWriter btreeFile; BufferedWriter dump; try { if (args.length < 4 || args.length > 6) { System.out.println("Incorrect command line usage. 4, 5, or 6 argments required.\n"); printUsage(); } cacheOption = Integer.parseInt(args[0]); degree = Integer.parseInt(args[1]); seqLength = Integer.parseInt(args[3]); //btree = new BTree(degree); String btreeFileName = gbkFileName + "." + seqLength + "." + degree; btreeFile = new BufferedWriter(new FileWriter(btreeFileName)); dump = new BufferedWriter(new FileWriter("dump")); if (cacheOption != 0 && cacheOption != 1) { System.out.println("Cache options must be either 0 or 1.\n"); printUsage(); } if (degree == 0) { // calculate optimal degree using formula } else if (degree < 0) { System.out.println("Degree must be a positive integer value.\n"); printUsage(); } // should we place a max value on degree?? if (seqLength <= 1 || seqLength > 31) { System.out.println("Sequence length must be an integer value between 1 and 31 (inclusive)\n"); printUsage(); } if (cacheOption == 1) { if (args.length == 4) { System.out.println("Must enter a cache size when cache option is 1.\n"); printUsage(); } else { cacheSize = Integer.parseInt(args[4]); if ( cacheSize < 100 || cacheSize > 500 ) { System.out.println("Cache size must be an integer between 100 and 500 (inclusive)\n"); printUsage(); } if (args.length == 6) { debugLevel = Integer.parseInt(args[5]); } cache = new Cache<Sequence>(cacheSize); } } else { if (args.length == 5) { debugLevel = Integer.parseInt(args[4]); } else if (args.length == 6) { System.out.println("Too many arguments for when cache option is 0.\n"); printUsage(); } } if (debugLevel != 0 && debugLevel != 1) { System.out.println("Debug option must be either 0 or 1.\n"); printUsage(); } Scanner lineScan = new Scanner(gbkFile); String currentLine = ""; while (lineScan.hasNextLine()) { currentLine = lineScan.nextLine(); while (!currentLine.contains("ORIGIN") && !currentLine.contains("//")) { currentLine = lineScan.nextLine(); } StringBuilder build = new StringBuilder(); String sequence = ""; currentLine = lineScan.nextLine(); System.out.println(currentLine.length()); int linePosition = 0; System.out.println(currentLine); for ( int i = 0; build.length() < seqLength; i++) { char c = currentLine.charAt(i); if (c == 'a' || c == 'c' || c == 'g' || c == 't' || c == 'n') { build.append(currentLine.charAt(i)); } linePosition++; } int startPos = linePosition; sequence = build.toString(); // gives the first valid sequence System.out.print(sequence + "\t"); btreeFile.write(sequence + " "); // used for testing int testCount = 1; while (!currentLine.contains("//")) { // get all the sequences for (int i = linePosition; i < currentLine.length(); i++) { char c = currentLine.charAt(i); if (c == 'a' || c == 'c' || c == 'g' || c == 't' || c == 'n') { if (i < currentLine.length()-1) { build.append(c); //hopefully at the end of the line it will hold onto valid chars build.deleteCharAt(0); //should take off the first letter of the string sequence = build.toString(); //this should happen only with valid dna letters btreeFile.write(sequence + " "); if (testCount <= 10000) { if (testCount % 10 == 9) { System.out.println(sequence + "," + i); } else { System.out.print(sequence + "," + i + "\t"); } testCount ++; } } else if ( i == currentLine.length()-1 ) { build.append(c); //hopefully at the end of the line it will hold onto valid chars build.deleteCharAt(0); //should take off the first letter of the string sequence = build.toString(); //this should happen only with valid dna letters System.out.println(sequence + "," + i); testCount ++; btreeFile.write(sequence + " "); currentLine = lineScan.nextLine(); System.out.println(currentLine); int pos = 0; c = currentLine.charAt(pos); while (!(c == 'a' || c == 'c' || c == 'g' || c == 't' || c == 'n')) { if (c != '/') { pos++; c = currentLine.charAt(pos); } else return; } for ( int j = pos; j < pos + seqLength; j++) { c = currentLine.charAt(j); if (c == 'a' || c == 'c' || c == 'g' || c == 't' || c == 'n') { build.append(currentLine.charAt(j)); build.deleteCharAt(0); //should take off the first letter of the string sequence = build.toString(); //this should happen only with valid dna letters btreeFile.write(sequence + " "); if (testCount <= 10000) { if (testCount % 10 == 0) { System.out.println(sequence + "," + j); } else { System.out.print(sequence + "," + j + "\t"); } testCount ++; } } } linePosition = startPos; } //if (!sequence.contains("n")) { // try { // Sequence seqContinuous = new Sequence(sequence); // btree.insert(seqContinuous); // cache.search(seqContinuous); // search method finds and moves // //to front or just adds to front, if full // //removes last and adds to front // if (debugLevel == 1) { // // write to "dump" file. // } // } catch (SequenceException e) { // // should continuously make Sequence objects with valid strings // e.printStackTrace(); // } //} } } } } btreeFile.flush(); lineScan.close(); dump.close(); btreeFile.close(); } catch (NumberFormatException e) { System.out.println("\nNumberFormatException:"); System.out.println("\n\tCache option, degree, sequence length, cache size, and debug level must be integer values.\n"); printUsage(); } catch (FileNotFoundException e) { System.out.println("File \"" + gbkFile.getName() + "\" could not be opened. Check spelling or pathname"); System.out.println(e.getMessage()); System.exit(1); } catch (IOException e) { System.out.println("Something is wrong with the buffered writer"); System.exit(1); } }
0a1e9893-2561-4bfe-bda7-273babdf2906
private static void printUsage() { System.out .println( "USAGE: $ java GeneBankCreateBtree <0 (no cache) | 1 (cache)> <degree> <gbk.file>\n" + " <sequence_length> [<cache_size>] [<debug_level>]\n\n" + "-<0 (no cache) | 1 (cache)> -- specifies if program should use cache;\n" + " if cache value is 1, <cache_value> has to be specified.\n" + "-<degree> -- degree used for BTree. Enter 0 for optimial degree usage.\n" + "-<gbk.file> -- any gene bank file( *.gbk) containing input DNA sequences.\n" + "-<sequence_length> -- integer value between 1 and 31 (inclusive)\n" + "-[<cache-size>] -- integer between 100 and 500 (inclusive)\n" + " only needed if 1 is entered for cache\n" + "-[<debug_level>] -- [optional] 0 (default) or 1.\n"); System.exit(1); }
60bcce4e-a59b-43a8-bf1a-b9141af9b35f
public static void main(String[] args) { try { BTree<Integer> ya = new BTree<Integer>(12, "blah", null); ya.toString(); ya.insert(1); System.out.println(ya.toString()); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
049fb9b6-9649-411f-8c7b-e257d7391dec
public SequenceException(String message) { super(message); }
69b70b0d-2321-473a-87ce-9d7474f7045a
public static void main(String[] args) { // TODO Auto-generated method stub int cacheOption = 0; int degree = 0; int seqLength = 0; int cacheSize = 0; int debugLevel = 0; String gbkFileName = args[2]; File gbkFile = new File (gbkFileName); //BTree btree; Cache<Sequence> cache; BufferedWriter btreeFile; BufferedWriter dump; try { if (args.length < 4 || args.length > 6) { System.out.println("Incorrect command line usage. 4, 5, or 6 argments required.\n"); printUsage(); } cacheOption = Integer.parseInt(args[0]); degree = Integer.parseInt(args[1]); seqLength = Integer.parseInt(args[3]); //btree = new BTree(degree); String btreeFileName = gbkFileName + "." + seqLength + "." + degree; btreeFile = new BufferedWriter(new FileWriter(btreeFileName)); dump = new BufferedWriter(new FileWriter("dump")); if (cacheOption != 0 && cacheOption != 1) { System.out.println("Cache options must be either 0 or 1.\n"); printUsage(); } if (degree == 0) { // calculate optimal degree using formula } else if (degree < 0) { System.out.println("Degree must be a positive integer value.\n"); printUsage(); } // should we place a max value on degree?? if (seqLength <= 1 || seqLength > 31) { System.out.println("Sequence length must be an integer value between 1 and 31 (inclusive)\n"); printUsage(); } if (cacheOption == 1) { if (args.length == 4) { System.out.println("Must enter a cache size when cache option is 1.\n"); printUsage(); } else { cacheSize = Integer.parseInt(args[4]); if ( cacheSize < 100 || cacheSize > 500 ) { System.out.println("Cache size must be an integer between 100 and 500 (inclusive)\n"); printUsage(); } if (args.length == 6) { debugLevel = Integer.parseInt(args[5]); } cache = new Cache<Sequence>(cacheSize); } } else { if (args.length == 5) { debugLevel = Integer.parseInt(args[4]); } else if (args.length == 6) { System.out.println("Too many arguments for when cache option is 0.\n"); printUsage(); } } if (debugLevel != 0 && debugLevel != 1) { System.out.println("Debug option must be either 0 or 1.\n"); printUsage(); } Scanner lineScan = new Scanner(gbkFile); String currentLine = ""; while (lineScan.hasNextLine()) { currentLine = lineScan.nextLine(); while (!currentLine.contains("ORIGIN") && !currentLine.contains("//")) { currentLine = lineScan.nextLine(); } StringBuilder build = new StringBuilder(); String sequence = ""; currentLine = lineScan.nextLine(); System.out.println(currentLine.length()); int linePosition = 0; System.out.println(currentLine); for ( int i = 0; build.length() < seqLength; i++) { char c = currentLine.charAt(i); if (c == 'a' || c == 'c' || c == 'g' || c == 't' || c == 'n') { build.append(currentLine.charAt(i)); } linePosition++; } int startPos = linePosition; sequence = build.toString(); // gives the first valid sequence System.out.print(sequence + "\t"); btreeFile.write(sequence + " "); // used for testing int testCount = 1; while (!currentLine.contains("//")) { // get all the sequences for (int i = linePosition; i < currentLine.length(); i++) { char c = currentLine.charAt(i); if (c == 'a' || c == 'c' || c == 'g' || c == 't' || c == 'n') { if (i < currentLine.length()-1) { build.append(c); //hopefully at the end of the line it will hold onto valid chars build.deleteCharAt(0); //should take off the first letter of the string sequence = build.toString(); //this should happen only with valid dna letters btreeFile.write(sequence + " "); if (testCount <= 10000) { if (testCount % 10 == 9) { System.out.println(sequence + "," + i); } else { System.out.print(sequence + "," + i + "\t"); } testCount ++; } } else if ( i == currentLine.length()-1 ) { build.append(c); //hopefully at the end of the line it will hold onto valid chars build.deleteCharAt(0); //should take off the first letter of the string sequence = build.toString(); //this should happen only with valid dna letters System.out.println(sequence + "," + i); testCount ++; btreeFile.write(sequence + " "); currentLine = lineScan.nextLine(); System.out.println(currentLine); int pos = 0; c = currentLine.charAt(pos); while (!(c == 'a' || c == 'c' || c == 'g' || c == 't' || c == 'n')) { if (c != '/') { pos++; c = currentLine.charAt(pos); } else return; } for ( int j = pos; j < pos + seqLength; j++) { c = currentLine.charAt(j); if (c == 'a' || c == 'c' || c == 'g' || c == 't' || c == 'n') { build.append(currentLine.charAt(j)); build.deleteCharAt(0); //should take off the first letter of the string sequence = build.toString(); //this should happen only with valid dna letters btreeFile.write(sequence + " "); if (testCount <= 10000) { if (testCount % 10 == 0) { System.out.println(sequence + "," + j); } else { System.out.print(sequence + "," + j + "\t"); } testCount ++; } } } linePosition = startPos; } //if (!sequence.contains("n")) { // try { // Sequence seqContinuous = new Sequence(sequence); // btree.insert(seqContinuous); // cache.search(seqContinuous); // search method finds and moves // //to front or just adds to front, if full // //removes last and adds to front // if (debugLevel == 1) { // // write to "dump" file. // } // } catch (SequenceException e) { // // should continuously make Sequence objects with valid strings // e.printStackTrace(); // } //} } } } } btreeFile.flush(); lineScan.close(); dump.close(); btreeFile.close(); } catch (NumberFormatException e) { System.out.println("\nNumberFormatException:"); System.out.println("\n\tCache option, degree, sequence length, cache size, and debug level must be integer values.\n"); printUsage(); } catch (FileNotFoundException e) { System.out.println("File \"" + gbkFile.getName() + "\" could not be opened. Check spelling or pathname"); System.out.println(e.getMessage()); System.exit(1); } catch (IOException e) { System.out.println("Something is wrong with the buffered writer"); System.exit(1); } }