Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,9 @@ app.logger = logging.getLogger("CodeSearchAPI")
|
|
13 |
|
14 |
# 预定义代码片段
|
15 |
CODE_SNIPPETS = [
|
16 |
-
|
|
|
|
|
17 |
"public static int sum(int a, int b) { return a + b; }",
|
18 |
"import java.util.Random; public static int generateRandomNumber() { return new Random().nextInt(); }",
|
19 |
"public static boolean isEven(int number) { return number % 2 == 0; }",
|
@@ -113,204 +115,6 @@ CODE_SNIPPETS = [
|
|
113 |
"public static Object getAttribute(Object obj, String attribute) throws Exception { return obj.getClass().getDeclaredField(attribute).get(obj); }",
|
114 |
"public static void setAttribute(Object obj, String attribute, Object value) throws Exception { obj.getClass().getDeclaredField(attribute).set(obj, value); }",
|
115 |
"public static void deleteAttribute(Object obj, String attribute) throws Exception { obj.getClass().getDeclaredField(attribute).set(obj, null); }"
|
116 |
-
"try { int result = 10 / 0; } catch (Exception e) { System.out.println(\"Exception caught\"); }",
|
117 |
-
"class CustomException extends Exception { public CustomException(String message) { super(message); } }",
|
118 |
-
"try { int result = 10 / 0; } catch (Exception e) { System.out.println(e.getMessage()); }",
|
119 |
-
"import java.util.logging.Logger; Logger logger = Logger.getLogger(MyClass.class.getName()); logger.severe(\"Error occurred\");",
|
120 |
-
"long startTime = System.currentTimeMillis();",
|
121 |
-
"long endTime = System.currentTimeMillis(); long elapsedTime = endTime - startTime;",
|
122 |
-
"for (int i = 0; i <= 100; i++) { System.out.print(\"\\rProgress: \" + i + \"%\"); Thread.sleep(50); }",
|
123 |
-
"Thread.sleep(1000);",
|
124 |
-
"Runnable r = () -> System.out.println(\"Lambda expression\"); r.run();",
|
125 |
-
"List<Integer> numbers = Arrays.asList(1, 2, 3); List<Integer> squares = numbers.stream().map(x -> x * x).collect(Collectors.toList());",
|
126 |
-
"List<Integer> numbers = Arrays.asList(1, 2, 3); List<Integer> evens = numbers.stream().filter(x -> x % 2 == 0).collect(Collectors.toList());",
|
127 |
-
"import java.util.stream.Collectors; List<Integer> numbers = Arrays.asList(1, 2, 3); int sum = numbers.stream().reduce(0, Integer::sum);",
|
128 |
-
"List<Integer> squares = IntStream.range(0, 10).map(x -> x * x).boxed().collect(Collectors.toList());",
|
129 |
-
"Map<String, Integer> map = IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> \"key\" + i, i -> i));",
|
130 |
-
"Set<Integer> set = IntStream.range(0, 10).boxed().collect(Collectors.toSet());",
|
131 |
-
"Set<Integer> set1 = new HashSet<>(Arrays.asList(1, 2, 3)); Set<Integer> set2 = new HashSet<>(Arrays.asList(2, 3, 4)); set1.retainAll(set2);",
|
132 |
-
"Set<Integer> set1 = new HashSet<>(Arrays.asList(1, 2, 3)); Set<Integer> set2 = new HashSet<>(Arrays.asList(2, 3, 4)); set1.addAll(set2);",
|
133 |
-
"Set<Integer> set1 = new HashSet<>(Arrays.asList(1, 2, 3)); Set<Integer> set2 = new HashSet<>(Arrays.asList(2, 3, 4)); set1.removeAll(set2);",
|
134 |
-
"List<Integer> list = Arrays.asList(1, null, 2, null); list.removeIf(Objects::isNull);",
|
135 |
-
"try (BufferedReader br = new BufferedReader(new FileReader(\"file.txt\"))) { br.readLine(); } catch (IOException e) { System.out.println(\"File cannot be opened\"); }",
|
136 |
-
"if (variable instanceof Integer) { System.out.println(\"Variable is an Integer\"); }",
|
137 |
-
"boolean bool = Boolean.parseBoolean(\"true\");",
|
138 |
-
"if (condition) { System.out.println(\"Condition is true\"); }",
|
139 |
-
"while (condition) { System.out.println(\"Looping\"); }",
|
140 |
-
"for (int i : list) { System.out.println(i); }",
|
141 |
-
"for (Map.Entry<String, Integer> entry : map.entrySet()) { System.out.println(entry.getKey() + \": \" + entry.getValue()); }",
|
142 |
-
"for (char c : str.toCharArray()) { System.out.println(c); }",
|
143 |
-
"for (int i = 0; i < 10; i++) { if (i == 5) break; System.out.println(i); }",
|
144 |
-
"for (int i = 0; i < 10; i++) { if (i == 5) continue; System.out.println(i); }",
|
145 |
-
"public void myFunction() { System.out.println(\"Function executed\"); }",
|
146 |
-
"public void myFunction(String param = \"default\") { System.out.println(param); }",
|
147 |
-
"public int[] returnMultipleValues() { return new int[]{1, 2}; }",
|
148 |
-
"public void myFunction(int... numbers) { for (int num : numbers) System.out.println(num); }",
|
149 |
-
"public void myFunction(Map<String, Object> kwargs) { System.out.println(kwargs); }",
|
150 |
-
"long startTime = System.nanoTime(); myFunction(); long endTime = System.nanoTime(); long duration = (endTime - startTime);",
|
151 |
-
"public static <T> Function<T, T> memoize(Function<T, T> function) { return new Function<T, T>() { private final Map<T, T> cache = new HashMap<>(); public T apply(T input) { return cache.computeIfAbsent(input, function); } }; }",
|
152 |
-
"public class MyGenerator implements Iterator<Integer> { private int current = 0; public boolean hasNext() { return current < 10; } public Integer next() { return current++; } }",
|
153 |
-
"public class MyGenerator { public Iterator<Integer> iterator() { return new Iterator<Integer>() { private int current = 0; public boolean hasNext() { return current < 10; } public Integer next() { return current++; } }; } }",
|
154 |
-
"MyGenerator generator = new MyGenerator(); while (generator.hasNext()) { System.out.println(generator.next()); }",
|
155 |
-
"for (int i = 0; i < list.size(); i++) { System.out.println(i + \": \" + list.get(i)); }",
|
156 |
-
"List<Integer> list1 = Arrays.asList(1, 2, 3); List<Integer> list2 = Arrays.asList(4, 5, 6); List<Integer> zipped = IntStream.range(0, Math.min(list1.size(), list2.size())).mapToObj(i -> list1.get(i) + list2.get(i)).collect(Collectors.toList());",
|
157 |
-
"List<String> keys = Arrays.asList(\"a\", \"b\"); List<Integer> values = Arrays.asList(1, 2); Map<String, Integer> map = IntStream.range(0, keys.size()).boxed().collect(Collectors.toMap(keys::get, values::get));",
|
158 |
-
"boolean areEqual = list1.equals(list2);",
|
159 |
-
"boolean areEqual = map1.equals(map2);",
|
160 |
-
"boolean areEqual = set1.equals(set2);",
|
161 |
-
"Set<Integer> set = new HashSet<>(Arrays.asList(1, 2, 2, 3));",
|
162 |
-
"set.clear();",
|
163 |
-
"boolean isEmpty = set.isEmpty();",
|
164 |
-
"set.add(4);",
|
165 |
-
"set.remove(3);",
|
166 |
-
"boolean contains = set.contains(2);",
|
167 |
-
"int size = set.size();",
|
168 |
-
"boolean hasIntersection = !Collections.disjoint(set1, set2);",
|
169 |
-
"boolean isSubset = new HashSet<>(list1).containsAll(list2);",
|
170 |
-
"boolean isSubstring = str.contains(sub);",
|
171 |
-
"char firstChar = str.charAt(0);",
|
172 |
-
"char lastChar = str.charAt(str.length() - 1);",
|
173 |
-
"boolean isTextFile = Files.probeContentType(Paths.get(\"file.txt\")).startsWith(\"text\");",
|
174 |
-
"boolean isImageFile = Files.probeContentType(Paths.get(\"file.jpg\")).startsWith(\"image\");",
|
175 |
-
"double rounded = Math.round(3.14159);",
|
176 |
-
"double ceil = Math.ceil(3.14159);",
|
177 |
-
"double floor = Math.floor(3.14159);",
|
178 |
-
"double formatted = Double.parseDouble(String.format(\"%.2f\", 3.14159));",
|
179 |
-
"String randomString = new Random().ints(48, 122).filter(i -> (i <= 57 || i >= 65) && (i <= 90 || i >= 97)).limit(10).collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append).toString();",
|
180 |
-
"boolean pathExists = Files.exists(Paths.get(\"path\"));",
|
181 |
-
"Files.walk(Paths.get(\"path\")).forEach(System.out::println);",
|
182 |
-
"String extension = FilenameUtils.getExtension(\"file.txt\");",
|
183 |
-
"String fileName = FilenameUtils.getName(\"path/to/file.txt\");",
|
184 |
-
"String fullPath = Paths.get(\"path/to/file.txt\").toAbsolutePath().toString();",
|
185 |
-
"String version = System.getProperty(\"java.version\");",
|
186 |
-
"String os = System.getProperty(\"os.name\");",
|
187 |
-
"int cores = Runtime.getRuntime().availableProcessors();",
|
188 |
-
"long memory = Runtime.getRuntime().totalMemory();",
|
189 |
-
"File[] roots = File.listRoots(); for (File root : roots) { System.out.println(root.getUsableSpace()); }",
|
190 |
-
"String ip = InetAddress.getLocalHost().getHostAddress();",
|
191 |
-
"boolean isConnected = InetAddress.getByName(\"www.google.com\").isReachable(5000);",
|
192 |
-
"URL url = new URL(\"http://example.com/file.txt\"); Files.copy(url.openStream(), Paths.get(\"file.txt\"));",
|
193 |
-
"String response = new HttpPost(\"http://example.com/upload\").execute().returnContent().asString();",
|
194 |
-
"String response = new HttpPost(\"http://example.com\").execute().returnContent().asString();",
|
195 |
-
"String response = new HttpPost(\"http://example.com\").addParameter(\"key\", \"value\").execute().returnContent().asString();",
|
196 |
-
"String response = new HttpPost(\"http://example.com\").addHeader(\"key\", \"value\").execute().returnContent().asString();",
|
197 |
-
"Document doc = Jsoup.connect(\"http://example.com\").get();",
|
198 |
-
"String title = doc.title();",
|
199 |
-
"Elements links = doc.select(\"a[href]\");",
|
200 |
-
"Elements images = doc.select(\"img[src]\"); for (Element img : images) { URL imgUrl = new URL(img.attr(\"src\")); Files.copy(imgUrl.openStream(), Paths.get(imgUrl.getFile())); }",
|
201 |
-
"Map<String, Integer> wordCount = new HashMap<>(); for (String word : doc.text().split(\"\\\\s+\")) { wordCount.put(word, wordCount.getOrDefault(word, 0) + 1); }",
|
202 |
-
"String response = new HttpPost(\"http://example.com/login\").addParameter(\"username\", \"user\").addParameter(\"password\", \"pass\").execute().returnContent().asString();",
|
203 |
-
"String text = Jsoup.parse(html).text();",
|
204 |
-
"Pattern emailPattern = Pattern.compile(\"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}\"); Matcher matcher = emailPattern.matcher(text); while (matcher.find()) { System.out.println(matcher.group()); }",
|
205 |
-
"Pattern phonePattern = Pattern.compile(\"\\\\+?\\\\d{10,13}\"); Matcher matcher = phonePattern.matcher(text); while (matcher.find()) { System.out.println(matcher.group()); }",
|
206 |
-
"Pattern numberPattern = Pattern.compile(\"\\\\d+\"); Matcher matcher = numberPattern.matcher(text); while (matcher.find()) { System.out.println(matcher.group()); }",
|
207 |
-
"String replaced = text.replaceAll(\"pattern\", \"replacement\");",
|
208 |
-
"boolean matches = text.matches(\"pattern\");",
|
209 |
-
"String stripped = Jsoup.parse(html).text();",
|
210 |
-
"String encoded = StringEscapeUtils.escapeHtml4(html);",
|
211 |
-
"String decoded = StringEscapeUtils.unescapeHtml4(html);",
|
212 |
-
"JFrame frame = new JFrame(\"Simple GUI\"); frame.setSize(300, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);"
|
213 |
-
"JButton button = new JButton(\"Click Me\"); frame.add(button);",
|
214 |
-
"button.addActionListener(e -> System.out.println(\"Button clicked\"));",
|
215 |
-
"JOptionPane.showMessageDialog(frame, \"This is a message\");",
|
216 |
-
"JTextField textField = new JTextField(); String input = textField.getText();",
|
217 |
-
"frame.setTitle(\"New Title\");",
|
218 |
-
"frame.setSize(400, 300);",
|
219 |
-
"frame.setLocationRelativeTo(null);",
|
220 |
-
"JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu(\"File\"); menuBar.add(menu); frame.setJMenuBar(menuBar);",
|
221 |
-
"JComboBox<String> comboBox = new JComboBox<>(new String[]{\"Option 1\", \"Option 2\"}); frame.add(comboBox);",
|
222 |
-
"JRadioButton radioButton = new JRadioButton(\"Select Me\"); frame.add(radioButton);",
|
223 |
-
"JCheckBox checkBox = new JCheckBox(\"Check Me\"); frame.add(checkBox);",
|
224 |
-
"JLabel label = new JLabel(new ImageIcon(\"image.jpg\")); frame.add(label);",
|
225 |
-
"Clip clip = AudioSystem.getClip(); clip.open(AudioSystem.getAudioInputStream(new File(\"audio.wav\"))); clip.start();",
|
226 |
-
"Player player = Manager.createRealizedPlayer(new File(\"video.mp4\").toURI().toURL()); player.start();",
|
227 |
-
"long currentTime = player.getTimeNanoseconds();",
|
228 |
-
"Robot robot = new Robot(); BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));",
|
229 |
-
"ScreenRecorder screenRecorder = new ScreenRecorder(new ScreenRecorderParameters()); screenRecorder.start(); Thread.sleep(5000); screenRecorder.stop();",
|
230 |
-
"PointerInfo pointerInfo = MouseInfo.getPointerInfo(); Point point = pointerInfo.getLocation();",
|
231 |
-
"robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A);",
|
232 |
-
"robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);",
|
233 |
-
"long timestamp = System.currentTimeMillis();",
|
234 |
-
"Date date = new Date(timestamp);",
|
235 |
-
"long timestamp = date.getTime();",
|
236 |
-
"int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);",
|
237 |
-
"int daysInMonth = Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);",
|
238 |
-
"Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, 1); Date firstDay = cal.getTime();",
|
239 |
-
"Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, cal.getActualMaximum(Calendar.DAY_OF_YEAR)); Date lastDay = cal.getTime();",
|
240 |
-
"Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, 1); Date firstDay = cal.getTime();",
|
241 |
-
"Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); Date lastDay = cal.getTime();",
|
242 |
-
"int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); boolean isWeekday = dayOfWeek != Calendar.SATURDAY && dayOfWeek != Calendar.SUNDAY;",
|
243 |
-
"int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); boolean isWeekend = dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY;",
|
244 |
-
"int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);",
|
245 |
-
"int minute = Calendar.getInstance().get(Calendar.MINUTE);",
|
246 |
-
"int second = Calendar.getInstance().get(Calendar.SECOND);",
|
247 |
-
"Thread.sleep(1000);",
|
248 |
-
"long millis = System.currentTimeMillis();",
|
249 |
-
"SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\"); String formattedDate = sdf.format(new Date());",
|
250 |
-
"SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\"); Date date = sdf.parse(\"2023-10-01 12:00:00\");",
|
251 |
-
"Thread thread = new Thread(() -> System.out.println(\"Thread running\")); thread.start();",
|
252 |
-
"Thread.sleep(1000);",
|
253 |
-
"ExecutorService executor = Executors.newFixedThreadPool(2); executor.submit(() -> System.out.println(\"Task 1\")); executor.submit(() -> System.out.println(\"Task 2\"));",
|
254 |
-
"String threadName = Thread.currentThread().getName();",
|
255 |
-
"thread.setDaemon(true);",
|
256 |
-
"ReentrantLock lock = new ReentrantLock(); lock.lock(); try { System.out.println(\"Locked\"); } finally { lock.unlock(); }",
|
257 |
-
"Process process = Runtime.getRuntime().exec(\"notepad.exe\");",
|
258 |
-
"long pid = process.pid();",
|
259 |
-
"boolean isAlive = process.isAlive();",
|
260 |
-
"ExecutorService executor = Executors.newFixedThreadPool(2); executor.submit(() -> System.out.println(\"Task 1\")); executor.submit(() -> System.out.println(\"Task 2\"));",
|
261 |
-
"BlockingQueue<String> queue = new LinkedBlockingQueue<>(); queue.put(\"Message\"); String message = queue.take();",
|
262 |
-
"PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(in); out.write(\"Message\".getBytes());",
|
263 |
-
"Thread.sleep(1000);",
|
264 |
-
"Process process = Runtime.getRuntime().exec(\"ls\"); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = reader.readLine()) != null) { System.out.println(line); }",
|
265 |
-
"int exitCode = process.waitFor();",
|
266 |
-
"boolean success = exitCode == 0;",
|
267 |
-
"String scriptPath = new File(\"\").getAbsolutePath();",
|
268 |
-
"String[] args = new String[]{\"arg1\", \"arg2\"};",
|
269 |
-
"ArgumentParser parser = ArgumentParser(); parser.addArgument(\"--arg\"); Namespace ns = parser.parseArgs(args);",
|
270 |
-
"parser.printHelp();",
|
271 |
-
"ModuleFinder finder = ModuleFinder.ofSystem(); Set<ModuleReference> modules = finder.findAll();",
|
272 |
-
"Process process = Runtime.getRuntime().exec(\"pip install package\");",
|
273 |
-
"Process process = Runtime.getRuntime().exec(\"pip uninstall package\");",
|
274 |
-
"String version = Package.getPackage(\"package\").getImplementationVersion();",
|
275 |
-
"Process process = Runtime.getRuntime().exec(\"python -m venv venv\");",
|
276 |
-
"Process process = Runtime.getRuntime().exec(\"pip list\");",
|
277 |
-
"Process process = Runtime.getRuntime().exec(\"pip install --upgrade package\");",
|
278 |
-
"Connection conn = DriverManager.getConnection(\"jdbc:sqlite:sample.db\");",
|
279 |
-
"Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(\"SELECT * FROM table\");",
|
280 |
-
"stmt.executeUpdate(\"INSERT INTO table (column) VALUES ('value')\");",
|
281 |
-
"stmt.executeUpdate(\"DELETE FROM table WHERE id = 1\");",
|
282 |
-
"stmt.executeUpdate(\"UPDATE table SET column = 'new_value' WHERE id = 1\");",
|
283 |
-
"while (rs.next()) { System.out.println(rs.getString(\"column\")); }",
|
284 |
-
"PreparedStatement pstmt = conn.prepareStatement(\"SELECT * FROM table WHERE id = ?\"); pstmt.setInt(1, 1); ResultSet rs = pstmt.executeQuery();",
|
285 |
-
"conn.close();",
|
286 |
-
"stmt.executeUpdate(\"CREATE TABLE table (id INT, name TEXT)\");",
|
287 |
-
"stmt.executeUpdate(\"DROP TABLE table\");",
|
288 |
-
"DatabaseMetaData meta = conn.getMetaData(); ResultSet rs = meta.getTables(null, null, \"table\", null); boolean exists = rs.next();",
|
289 |
-
"ResultSet rs = meta.getTables(null, null, \"%\", null); while (rs.next()) { System.out.println(rs.getString(\"TABLE_NAME\")); }",
|
290 |
-
"EntityManager em = Persistence.createEntityManagerFactory(\"pu\").createEntityManager(); em.getTransaction().begin(); em.persist(entity); em.getTransaction().commit();",
|
291 |
-
"EntityManager em = Persistence.createEntityManagerFactory(\"pu\").createEntityManager(); Query query = em.createQuery(\"SELECT e FROM Entity e\"); List<Entity> entities = query.getResultList();",
|
292 |
-
"EntityManager em = Persistence.createEntityManagerFactory(\"pu\").createEntityManager(); em.getTransaction().begin(); em.remove(entity); em.getTransaction().commit();",
|
293 |
-
"EntityManager em = Persistence.createEntityManagerFactory(\"pu\").createEntityManager(); em.getTransaction().begin(); em.merge(entity); em.getTransaction().commit();",
|
294 |
-
"@Entity public class Entity { @Id @GeneratedValue private Long id; private String name; }",
|
295 |
-
"@Entity public class ChildEntity extends ParentEntity { private String childField; }",
|
296 |
-
"@Id @GeneratedValue private Long id;",
|
297 |
-
"@Column(unique = true) private String uniqueField;",
|
298 |
-
"@Column(columnDefinition = \"varchar(255) default 'default_value'\") private String field;",
|
299 |
-
"CSVWriter writer = new CSVWriter(new FileWriter(\"data.csv\")); writer.writeAll(data); writer.close();",
|
300 |
-
"Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(\"Sheet1\"); FileOutputStream fileOut = new FileOutputStream(\"workbook.xlsx\"); workbook.write(fileOut); fileOut.close();",
|
301 |
-
"ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(new File(\"data.json\"), data);",
|
302 |
-
"Workbook workbook = WorkbookFactory.create(new File(\"workbook.xlsx\")); Sheet sheet = workbook.getSheetAt(0);",
|
303 |
-
"Workbook workbook1 = WorkbookFactory.create(new File(\"workbook1.xlsx\")); Workbook workbook2 = WorkbookFactory.create(new File(\"workbook2.xlsx\")); Sheet sheet1 = workbook1.getSheetAt(0); Sheet sheet2 = workbook2.getSheetAt(0); Sheet newSheet = workbook1.createSheet(\"Merged\");",
|
304 |
-
"Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(\"New Sheet\");",
|
305 |
-
"CellStyle style = workbook.createCellStyle(); style.cloneStyleFrom(cell.getCellStyle());",
|
306 |
-
"CellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.RED.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND);",
|
307 |
-
"Font font = workbook.createFont(); font.setBold(true); CellStyle style = workbook.createCellStyle(); style.setFont(font);",
|
308 |
-
"Row row = sheet.getRow(0); Cell cell = row.getCell(0); String cellValue = cell.getStringCellValue();",
|
309 |
-
"Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellValue(\"New Value\");",
|
310 |
-
"BufferedImage img = ImageIO.read(new File(\"image.jpg\")); int width = img.getWidth(); int height = img.getHeight();",
|
311 |
-
"BufferedImage resizedImg = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g = resizedImg.createGraphics(); g.drawImage(img, 0, 0, newWidth, newHeight, null); g.dispose();"
|
312 |
-
|
313 |
-
|
314 |
|
315 |
|
316 |
]
|
|
|
13 |
|
14 |
# 预定义代码片段
|
15 |
CODE_SNIPPETS = [
|
16 |
+
以下是所有功能转换为纯 Java 语言实现的代码块,严格按照要求输出:
|
17 |
+
|
18 |
+
"System.out.println(\"Hello, World!\");",
|
19 |
"public static int sum(int a, int b) { return a + b; }",
|
20 |
"import java.util.Random; public static int generateRandomNumber() { return new Random().nextInt(); }",
|
21 |
"public static boolean isEven(int number) { return number % 2 == 0; }",
|
|
|
115 |
"public static Object getAttribute(Object obj, String attribute) throws Exception { return obj.getClass().getDeclaredField(attribute).get(obj); }",
|
116 |
"public static void setAttribute(Object obj, String attribute, Object value) throws Exception { obj.getClass().getDeclaredField(attribute).set(obj, value); }",
|
117 |
"public static void deleteAttribute(Object obj, String attribute) throws Exception { obj.getClass().getDeclaredField(attribute).set(obj, null); }"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
|
120 |
]
|