id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
39ff47e1-5812-4a94-b659-c5f135365e62 | public boolean isAnswer() {
return answer;
} |
873029a3-9adc-4c8d-804d-e574fb6151f6 | public void setIsAnswer(boolean val) {
this.answer = val;
} |
bc8308df-9f44-4fd1-a544-d0b5e228d951 | public static HashMap<String, CalcButton> getButtons() {
return buttons;
} |
a58ba4df-aae3-487c-bce2-bc3eec672e6b | public static CalcButton getInst(String command) {
return buttons.get(command);
} |
56013cc5-9fe0-442e-8b24-b078053086b2 | public CalcButton(String text, String command, ActionListener listener, int x, int y, int xSpan, int ySpan) {
super(text);
setActionCommand(command);
addActionListener(listener);
GridBagConstraints c = SimpleCalc.getGBConstraint();
c.gridx = x;
c.gridy = y;
c.gridwidth = xSpan;
c.gridheight = ySpan;
SimpleCalc.inst().add(this, c);
buttons.put(command, this);
} |
6bfa0b7a-9438-4cc7-964f-eab8ad527a29 | public CalcButton(String text, String command, ActionListener listener, int x, int y) {
this(text, command, listener, x, y, 1, 1);
} |
b878cbcd-9db8-4e86-a4e7-11ed4787b7b9 | @Test
public void testCalculate() {
assertEquals(Double.valueOf(2), MathUtil.calculate("1+1"));
assertEquals(Double.valueOf(10), MathUtil.calculate("2+4*2"));
assertEquals(Double.valueOf(21), MathUtil.calculate("(5+2)*3"));
assertNull(MathUtil.calculate("5**5"));
assertNull(MathUtil.calculate("5.0.1"));
assertNull(MathUtil.calculate(""));
} |
dabeca2f-1fa2-4854-a7d2-270f388a5ec6 | @Test
public void testIsTooBig() {
assertFalse(MathUtil.isTooBig(500D));
assertFalse(MathUtil.isTooBig(500.4125D));
assertFalse(MathUtil.isTooBig(1234567891234D));
assertFalse(MathUtil.isTooBig(1234567891234.5476D));
assertTrue(MathUtil.isTooBig(12345678912345D));
} |
e175888e-3cf5-4899-8105-7f708fc19a2c | @Test
public void testFormatDecimalForDisplay() {
assertEquals("500", MathUtil.formatDecimalForDisplay(500D));
assertEquals("500.234", MathUtil.formatDecimalForDisplay(500.234D));
assertEquals("1234567891234", MathUtil.formatDecimalForDisplay(1234567891234D));
assertEquals("123456789123", MathUtil.formatDecimalForDisplay(123456789123.4D));
} |
f1c34062-5f69-4402-9cc5-b1b263254dcc | public static String readString(int hkey, String key, String valueName) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
if (hkey == HKEY_LOCAL_MACHINE) {
return readString(systemRoot, hkey, key, valueName);
} else if (hkey == HKEY_CURRENT_USER) {
return readString(userRoot, hkey, key, valueName);
} else {
throw new IllegalArgumentException("hkey=" + hkey);
}
} |
9ad1cb0f-5523-4d5e-9b55-cd0847819859 | private static String readString(Preferences root, int hkey, String key, String value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
int[] handles = (int[]) regOpenKey.invoke(root, hkey, toCstr(key), KEY_READ);
if (handles[1] != REG_SUCCESS) {
return null;
}
byte[] valb = (byte[]) regQueryValueEx.invoke(root, handles[0], toCstr(value));
regCloseKey.invoke(root, handles[0]);
return (valb != null ? new String(valb).trim() : null);
} |
7998491d-52b6-4d53-a304-af89316d2827 | private static byte[] toCstr(String str) {
byte[] result = new byte[str.length() + 1];
for (int i = 0; i < str.length(); i++) {
result[i] = (byte) str.charAt(i);
}
result[str.length()] = 0;
return result;
} |
ba2adb21-d992-49dd-a7fb-af6ad37f7abc | public static void addMod(File mod) {
if (!mods.contains(mod)) {
String modName = mod.getName();
if (modName.endsWith(".zip")) {
mods.add(mod);
modName = modName.substring(0, modName.length() - 4);
listModel.addElement(modName);
TroveUtils.saveMods();
}
}
} |
c9eb0b22-bde9-45b3-b1c8-0d0f733a60d4 | public static void removeMod(int mod) {
mods.remove(mod);
listModel.removeElementAt(mod);
TroveUtils.saveMods();
} |
1f20e878-e2a5-4793-817b-4793160545c3 | public static ArrayList<File> getMods() {
return mods;
} |
fe8cbb7c-a085-4a96-b470-4702a0809303 | public static DefaultListModel<String> getListModel() {
return listModel;
} |
e808f3a3-cd31-45ca-b8be-f488016ad9db | public static void main(String[] args) {
File troveModLoaderDirectory = new File(System.getenv("APPDATA") + File.separator + "Trove-Mod-Loader-Java");
File loadModsFile = new File(troveModLoaderDirectory + File.separator + "loadmods.txt");
troveModLoaderGUI = new TroveModLoaderGUI();
troveModLoaderGUI.setVisible(true);
troveModLoaderGUI.setSize(450, 190);
TroveUtils.setTroveFolderLocationAtStart(troveModLoaderDirectory);
TroveUtils.addModsFromTextFile(loadModsFile, true);
} |
47ba456a-a105-4d8c-9a5d-ba9b408e0b57 | public static TroveModLoaderGUI getTroveModLoaderGUI() {
return troveModLoaderGUI;
} |
d27e37ea-888b-40f5-b194-6bf7911851fd | public static void init() {
timer = new Timer();
TroveTimerTask troveTimerTask = new TroveTimerTask();
timer.schedule(troveTimerTask, 0, 2 * 1000);
} |
9b2eadbc-a7cd-4f55-ad2f-a6dbd9669ab5 | @Override
public void run() {
if (TroveUtils.getTroveInstallLocation() == null) {
TroveModLoader.getTroveModLoaderGUI().disableButtons(false);
}
boolean isTroveRunning = TroveUtils.isProcessRunning("Trove.exe");
TroveModLoader.getTroveModLoaderGUI().setTroveStatusLabel("Trove is " + (isTroveRunning ? "" : "not ") + "running");
if (!troveRan && isTroveRunning && TroveUtils.getTroveInstallLocation() != null) {
TroveUtils.addModsToInstallation();
}
troveRan = isTroveRunning;
} |
4959e7d3-4547-426a-9c3c-13a97c8e6494 | public static void stop() {
timer.cancel();
} |
e2a15e06-7c82-48e9-8b1a-29128996f79e | public TroveModLoaderGUI() {
initComponents();
list1.setModel(TroveMods.getListModel());
TroveTimer.init();
} |
e99ac1f6-dc29-4cf0-ad6a-affcf1136652 | private void thisWindowClosing(WindowEvent event) {
TroveTimer.stop();
System.exit(0);
} |
600f2c98-e0c3-45a1-a903-4348986d93dc | private void button1MousePressed(MouseEvent event) {
if (!button1.isEnabled()) {
return;
}
FileFilter filter = new FileNameExtensionFilter(null, "zip");
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
chooser.setFileFilter(filter);
int response = chooser.showOpenDialog(null);
if (response == JFileChooser.APPROVE_OPTION) {
TroveMods.addMod(chooser.getSelectedFile());
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
String textLabel = simpleDateFormat.format(date) + " - 1 mod added!";
setModLabel(textLabel);
}
} |
e5659808-5d57-4da0-89a6-d008e7f910a0 | private void button2MousePressed(MouseEvent event) {
if (!button2.isEnabled()) {
return;
}
if (list1.getSelectedIndex() >= 0) {
TroveMods.removeMod(list1.getSelectedIndex());
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
String textLabel = simpleDateFormat.format(date) + " - 1 mod removed!";
setModLabel(textLabel);
}
} |
f77e7de1-44e5-410b-969f-cd750894fbe6 | private void button5MousePressed(MouseEvent event) {
if (!button5.isEnabled()) {
return;
}
FileFilter filter = new FileNameExtensionFilter(null, "txt");
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Specify a mod list to load");
chooser.setCurrentDirectory(new File("."));
chooser.setFileFilter(filter);
int response = chooser.showOpenDialog(null);
if (response == JFileChooser.APPROVE_OPTION) {
TroveUtils.addModsFromTextFile(chooser.getSelectedFile(), false);
}
} |
5f13a3e5-55e7-46e2-936a-8cdd8773129d | private void button4MousePressed(MouseEvent event) {
if (!button4.isEnabled()) {
return;
}
FileFilter filter = new FileNameExtensionFilter(null, "txt");
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Specify a mod list to save");
chooser.setCurrentDirectory(new File("."));
chooser.setFileFilter(filter);
int response = chooser.showSaveDialog(null);
if (response == JFileChooser.APPROVE_OPTION) {
TroveUtils.saveModsToTextFile(chooser.getSelectedFile());
}
} |
95cb3649-ea35-455e-8759-4e8063ee9188 | private void button3MousePressed(MouseEvent event) {
if (!button3.isEnabled()) {
return;
}
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogTitle("Trove Install Location");
if (TroveUtils.getTroveInstallLocation() != null) {
chooser.setCurrentDirectory(new File(TroveUtils.getTroveInstallLocation()));
} else {
chooser.setCurrentDirectory(new File("."));
}
int response = chooser.showOpenDialog(null);
if (response == JFileChooser.OPEN_DIALOG) {
File folder = chooser.getSelectedFile();
if (folder.isDirectory()) {
if (!((new File(folder + File.separator + "Trove.exe")).exists())) {
int dialogOption = JOptionPane.showOptionDialog(null, "Trove.exe is not found in this directory!\nAre you sure you want to change it to this directory?", "Trove Mod Loader", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);
if (dialogOption == JOptionPane.OK_OPTION) {
setDirectory(folder);
}
} else {
setDirectory(folder);
}
}
}
} |
b51f6406-df87-4667-87b4-7f52afe2e525 | private void button6MousePressed(MouseEvent event) {
if (!button6.isEnabled()) {
return;
}
TroveUtils.addModsToInstallation();
} |
5808605b-3ced-449f-80df-ab745801be99 | private void button7MousePressed(MouseEvent event) {
if (!button7.isEnabled()) {
return;
}
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogTitle("Trove Mods Folder Location");
int response = chooser.showOpenDialog(null);
if (response == JFileChooser.OPEN_DIALOG) {
TroveUtils.loadModsFromFolder(chooser.getSelectedFile());
}
} |
398db7c9-91cc-4f44-a7bc-1baac2ba25fb | private void setDirectory(File directory) {
File troveModLoaderDirectory = new File(System.getenv("APPDATA") + File.separator + "Trove-Mod-Loader-Java");
File file = new File(troveModLoaderDirectory + File.separator + "settings.txt");
TroveUtils.setTroveInstallLocation(directory.getPath());
TroveUtils.saveTextToFile(TroveUtils.getTroveInstallLocation(), file);
enabledButtons();
JOptionPane.showMessageDialog(null, "Trove custom directory saved.", "Trove Mod Loader", JOptionPane.INFORMATION_MESSAGE);
} |
ec5ed36c-1a71-4569-a737-cfc3131e4dc3 | public void enabledButtons() {
button1.setEnabled(true);
button2.setEnabled(true);
button3.setEnabled(true);
button4.setEnabled(true);
button5.setEnabled(true);
button6.setEnabled(true);
button7.setEnabled(true);
} |
3997bf1d-b800-429e-a08d-a90a41ac01fe | public void disableButtons(boolean disableChangeFolder) {
button1.setEnabled(false);
button2.setEnabled(false);
if (disableChangeFolder) {
button3.setEnabled(false);
}
button4.setEnabled(false);
button5.setEnabled(false);
button6.setEnabled(true);
button7.setEnabled(true);
} |
674fa765-5103-4bc2-96cc-636aadac3f1c | public void setTroveStatusLabel(String text) {
label2.setText(text);
} |
876a3daf-7d82-4adb-95a6-2448f062e315 | public void setModLabel(String text) {
label1.setText(text);
} |
17b2d867-d177-487e-826f-c7d587343730 | private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
// Generated using JFormDesigner Evaluation license - Cameron Weaver
button3 = new JButton();
scrollPane1 = new JScrollPane();
list1 = new JList();
button1 = new JButton();
button2 = new JButton();
button4 = new JButton();
button5 = new JButton();
label1 = new JLabel();
label2 = new JLabel();
button6 = new JButton();
button7 = new JButton();
//======== this ========
setResizable(false);
setTitle("Trove Mod Loader v1.4.1");
setMinimumSize(new Dimension(545, 225));
setIconImage(new ImageIcon(getClass().getResource("/com/xigbclutchix/trove/icon.png")).getImage());
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
thisWindowClosing(e);
}
});
Container contentPane = getContentPane();
contentPane.setLayout(null);
//---- button3 ----
button3.setText("Change Trove Folder");
button3.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
button3MousePressed(e);
}
});
contentPane.add(button3);
button3.setBounds(305, 95, 225, button3.getPreferredSize().height);
//======== scrollPane1 ========
{
//---- list1 ----
list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list1.setMinimumSize(new Dimension(295, 147));
list1.setMaximumSize(new Dimension(295, 147));
scrollPane1.setViewportView(list1);
}
contentPane.add(scrollPane1);
scrollPane1.setBounds(5, 5, 295, 150);
//---- button1 ----
button1.setText("Add Mod");
button1.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
button1MousePressed(e);
}
});
contentPane.add(button1);
button1.setBounds(305, 5, 110, button1.getPreferredSize().height);
//---- button2 ----
button2.setText("Remove Mod");
button2.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
button2MousePressed(e);
}
});
contentPane.add(button2);
button2.setBounds(420, 5, 110, button2.getPreferredSize().height);
//---- button4 ----
button4.setText("Save List");
button4.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
button4MousePressed(e);
}
});
contentPane.add(button4);
button4.setBounds(420, 65, 110, button4.getPreferredSize().height);
//---- button5 ----
button5.setText("Load List");
button5.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
button5MousePressed(e);
}
});
contentPane.add(button5);
button5.setBounds(305, 65, 110, button5.getPreferredSize().height);
//---- label1 ----
label1.setHorizontalAlignment(SwingConstants.CENTER);
label1.setBorder(new EtchedBorder());
contentPane.add(label1);
label1.setBounds(5, 160, 295, 25);
//---- label2 ----
label2.setHorizontalAlignment(SwingConstants.CENTER);
label2.setBorder(new EtchedBorder());
contentPane.add(label2);
label2.setBounds(305, 160, 225, 25);
//---- button6 ----
button6.setText("Force Mod Inject");
button6.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
button6MousePressed(e);
}
});
contentPane.add(button6);
button6.setBounds(305, 125, 225, button6.getPreferredSize().height);
//---- button7 ----
button7.setText("Add Mods From Folder");
button7.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
button7MousePressed(e);
}
});
contentPane.add(button7);
button7.setBounds(305, 35, 225, button7.getPreferredSize().height);
{ // compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < contentPane.getComponentCount(); i++) {
Rectangle bounds = contentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = contentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
contentPane.setMinimumSize(preferredSize);
contentPane.setPreferredSize(preferredSize);
}
setSize(545, 220);
setLocationRelativeTo(getOwner());
// JFormDesigner - End of component initialization //GEN-END:initComponents
} |
0b200921-748e-4ddc-bc03-3949aaa66c62 | @Override
public void windowClosing(WindowEvent e) {
thisWindowClosing(e);
} |
ce5bd684-38bb-43ef-8c3e-53c85f9a54fe | @Override
public void mousePressed(MouseEvent e) {
button3MousePressed(e);
} |
8533971b-ec48-4e8d-92b8-cac520f4ab16 | @Override
public void mousePressed(MouseEvent e) {
button1MousePressed(e);
} |
107a28c7-4c91-48ad-9b37-a9217a527900 | @Override
public void mousePressed(MouseEvent e) {
button2MousePressed(e);
} |
4c7a043b-75f9-432a-82f7-e5a6112ca8e0 | @Override
public void mousePressed(MouseEvent e) {
button4MousePressed(e);
} |
167142f4-174d-46bd-8fd8-ace93836b6dd | @Override
public void mousePressed(MouseEvent e) {
button5MousePressed(e);
} |
99cb521d-11fd-4982-92d5-495c9ccc82de | @Override
public void mousePressed(MouseEvent e) {
button6MousePressed(e);
} |
afbbc33b-3dcc-44df-ac23-32ac6fa49b47 | @Override
public void mousePressed(MouseEvent e) {
button7MousePressed(e);
} |
52653670-6868-4eeb-b4d0-31b354289976 | public static void saveMods() {
File troveModLoaderDirectory = new File(System.getenv("APPDATA") + File.separator + "Trove-Mod-Loader-Java");
File loadModsFile = new File(troveModLoaderDirectory + File.separator + "loadmods.txt");
saveModsToTextFile(loadModsFile);
} |
3d5d8476-c2dc-45da-88bd-a8458a2fdaed | public static void setTroveModText() {
if (TroveMods.getMods().size() <= 0) {
return;
}
if (TroveModLoader.getTroveModLoaderGUI() == null) {
return;
}
setModLabel(TroveMods.getMods().size() + (TroveMods.getMods().size() == 1 ? " mod" : " mods") + " added!");
} |
91498cd9-8248-4e56-ac4e-9984f250ca44 | public static void addModsFromTextFile(File modList, boolean firstTime) {
String modListName = modList.getName();
if (modListName.endsWith(".txt")) {
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(modList));
String line;
while ((line = bufferedReader.readLine()) != null) {
if (!line.isEmpty() && line.endsWith(".zip")) {
File file = new File(line);
if (file.exists()) {
TroveMods.addMod(file);
}
}
}
bufferedReader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
if (firstTime) {
return;
}
setTroveModText();
} |
7c3214a3-a69f-497e-aeb2-d08a8b7790a1 | public static void saveModsToTextFile(File file) {
String filePath = String.valueOf(file);
if (!filePath.endsWith(".txt")) {
filePath = filePath + ".txt";
}
File saveFile = new File(filePath);
StringBuilder stringBuilder = new StringBuilder();
for (File mod : TroveMods.getMods()) {
stringBuilder.append(mod);
stringBuilder.append(System.getProperty("line.separator"));
}
try {
PrintStream out = new PrintStream(new FileOutputStream(saveFile));
out.print(stringBuilder);
out.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
} |
c2354a64-acb5-4b84-9178-75be46738d42 | public static void addModsToInstallation() {
TroveModLoader.getTroveModLoaderGUI().disableButtons(true);
if (getTroveInstallLocation() != null && !getTroveInstallLocation().isEmpty()) {
File installDirectory = new File(getTroveInstallLocation());
for (File mod : TroveMods.getMods()) {
try {
unzipFileIntoDirectory(new ZipFile(mod), installDirectory);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
TroveModLoader.getTroveModLoaderGUI().enabledButtons();
if (TroveMods.getMods().size() <= 0) {
return;
}
saveMods();
setTroveModText();
} |
1c3badd6-c7c9-4cca-8165-86b370825cff | public static boolean isProcessRunning(String process) {
boolean found = false;
try {
File file = File.createTempFile("checkIfRunning", ".vbs");
file.deleteOnExit();
FileWriter fileWriter = new java.io.FileWriter(file);
String vbs = "Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
+ "Set locator = CreateObject(\"WbemScripting.SWbemLocator\")\n"
+ "Set service = locator.ConnectServer()\n"
+ "Set processes = service.ExecQuery _\n"
+ " (\"select * from Win32_Process where name='" + process + "'\")\n"
+ "For Each process in processes\n"
+ "wscript.echo process.Name \n"
+ "Next\n"
+ "Set WSHShell = Nothing\n";
fileWriter.write(vbs);
fileWriter.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
line = input.readLine();
if (line != null) {
if (line.equals(process)) {
found = true;
}
}
input.close();
} catch (IOException ex) {
ex.printStackTrace();
}
return found;
} |
0ff4095b-8191-4feb-9074-a8cb5b41db98 | public static void unzipFileIntoDirectory(ZipFile zipFile, File directory) {
Enumeration files = zipFile.entries();
while (files.hasMoreElements()) {
try {
ZipEntry entry = (ZipEntry) files.nextElement();
InputStream inputStream = zipFile.getInputStream(entry);
byte[] buffer = new byte[1024];
int bytesRead;
File file = new File(directory.getAbsolutePath() + File.separator + entry.getName());
if (entry.isDirectory()) {
file.mkdirs();
continue;
} else {
file.getParentFile().mkdirs();
file.createNewFile();
}
FileOutputStream fileOutputStream = new FileOutputStream(file);
while ((bytesRead = inputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, bytesRead);
}
fileOutputStream.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
try {
zipFile.close();
} catch (IOException ex) {
ex.printStackTrace();
}
} |
db4f4a1d-d1d5-4b44-8df6-972aafbaed32 | public static String getInstallLocation64() throws InvocationTargetException, IllegalAccessException {
return WinRegistry.readString(WinRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Glyph Trove", "InstallLocation");
} |
fcc32668-d195-4ef7-b34e-2331535abf4b | public static String getInstallLocation32() throws InvocationTargetException, IllegalAccessException {
return WinRegistry.readString(WinRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Glyph Trove", "InstallLocation");
} |
812d400e-9d3e-4bca-9b1c-f884eeec6490 | public static void setTroveInstallLocation(String newTroveInstallLocation) {
troveInstallLocation = newTroveInstallLocation;
} |
0f2e807b-58c2-48b3-81eb-92ef8e706756 | public static String getTroveInstallLocation() {
return troveInstallLocation;
} |
dae87cb5-7942-4422-9f6b-7e5dc1eaf0f2 | public static void saveTextToFile(String text, File file) {
try {
PrintStream out = new PrintStream(new FileOutputStream(file));
out.print(text);
out.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
} |
9360d42f-2ed9-48a9-b225-6e95a1d1c401 | public static String readTextFromFile(File file) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
return reader.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
} |
b4e078d3-8bf0-49c9-b1d8-cbed9f69e41a | public static void createFolderAndEmptyFiles(File directory) {
if (!directory.exists()) {
directory.mkdir();
}
File loadModsFile = new File(directory + File.separator + "loadmods.txt");
if (!loadModsFile.exists()) {
try {
loadModsFile.createNewFile();
} catch (IOException ex) {
ex.printStackTrace();
}
}
} |
529d19ba-c54a-4836-bb16-389e3fe9db56 | public static void setTroveFolderLocationAtStart(File troveModLoaderDirectory) {
createFolderAndEmptyFiles(troveModLoaderDirectory);
File settingsFile = new File(troveModLoaderDirectory + File.separator + "settings.txt");
if (!settingsFile.exists()) {
try {
settingsFile.createNewFile();
lookForInstallLocation(troveModLoaderDirectory);
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
String loadedText = readTextFromFile(settingsFile);
if (loadedText == null) {
lookForInstallLocation(troveModLoaderDirectory);
} else {
setTroveInstallLocation(loadedText);
setModLabel("Install location loaded");
TroveModLoader.getTroveModLoaderGUI().enabledButtons();
}
}
} |
88a92fbb-ac48-411f-8e39-8f3059c846a0 | public static void lookForInstallLocation(File troveModLoaderDirectory) {
File file = new File(troveModLoaderDirectory + File.separator + "settings.txt");
String installLocation;
try {
installLocation = getInstallLocation32();
if (installLocation == null) {
installLocation = getInstallLocation64();
if (installLocation != null) {
saveTextToFile(installLocation, file);
setTroveInstallLocation(installLocation);
setModLabel("Install location set to 64 bit");
TroveModLoader.getTroveModLoaderGUI().enabledButtons();
}
} else {
saveTextToFile(installLocation, file);
setTroveInstallLocation(installLocation);
setModLabel("Install location set to 32 bit");
TroveModLoader.getTroveModLoaderGUI().enabledButtons();
}
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (InvocationTargetException ex) {
ex.printStackTrace();
}
} |
6bce529e-3b42-46b1-b9e4-4f6f01201621 | public static void loadModsFromFolder(File directory) {
if (!directory.isDirectory()) {
return;
}
ArrayList<File> files = new ArrayList<File>();
File[] filesAndDirectories = directory.listFiles();
if (filesAndDirectories != null) {
for (File file : filesAndDirectories) {
if (file.isFile()) {
if (file.getName().endsWith(".zip")) {
TroveMods.addMod(file);
files.add(file);
}
}
}
}
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
String textLabel = simpleDateFormat.format(date) + " - " + files.size() + (files.size() == 1 ? " mod" : " mods") + " added!";
setModLabel(textLabel);
} |
e39b8604-3070-480e-a1a8-929d25172b63 | public static void setModLabel(String text) {
if (TroveModLoader.getTroveModLoaderGUI() == null) {
return;
}
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
String textLabel = simpleDateFormat.format(date) + " - " + text;
TroveModLoader.getTroveModLoaderGUI().setModLabel(textLabel);
} |
70a08f22-3bb2-4f80-9f62-878e63338683 | public static void main(String[] args) {
linq1();
linq2();
linq3();
linq4();
linq5();
} |
7bf509ce-258f-40f9-a0f7-8c462e0df5ff | public static void linq1() {
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
IntStream stream = Arrays.stream(numbers).filter(x -> x < 5);
System.out.println("Numbers < 5:");
stream.forEach(System.out::println);
} |
e795d076-9b48-4d87-9ded-00401ffb4fc4 | public static void linq2() {
List<Product> products = Objects.getProductList();
Stream<Product> stream = products.stream().filter(x -> x.unitsInStock == 0);
System.out.println("Sold out products:");
stream.map(x -> x.productName).forEach(System.out::println);
} |
13c13b0c-3fa7-40ec-8b5f-0966e7af3288 | public static void linq3() {
List<Product> products = Objects.getProductList();
Stream<Product> stream = products.stream().filter(x -> x.unitsInStock > 0 && x.unitPrice > 3.00);
System.out.println("In-stock products that cost more than 3.00:");
stream.map(x -> String.format("%s is in stock and costs more than 3.00.", x.productName))
.forEach(System.out::println);
} |
b851c1c6-cfa4-4618-a995-56a864641ab7 | public static void linq4() {
System.out.println("Customers from Washington and their orders:");
Stream<Customer> stream = Objects.getCustomerList()
.stream()
.filter(x -> x.region != null && x.region.equals("WA"));
stream.forEach(x -> {
System.out.println(String.format("Customer %s: %s", x.customerID, x.companyName));
for (Order y : x.orders) {
System.out.println(String.format(" Order %s: %s", y.orderID, y.orderDate));
}
});
} |
1a56a4bb-c003-46f3-9700-196cce098f5d | public static void linq5() {
String[] digits = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
System.out.println("Short digits:");
IntStream.range(0, digits.length)
.filter(i -> digits[i].length() < i)
.mapToObj(i -> String.format("The word %s is shorter than its value.", digits[i]))
.forEach(System.out::println);
} |
6d83df7e-a88a-4c81-9636-e4c95db44386 | public static void main(String[] args) {
linq20();
linq21();
} |
fe0c80a9-5693-44f3-90e5-91fc2e314a56 | static void linq20() {
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
System.out.println("First 3 numbers:");
Arrays.stream(numbers).limit(3).forEach(System.out::println);
} |
55eee835-e6c3-45aa-9683-d94e8bd92c54 | static void linq21() {
List<Customer> customerList = Objects.getCustomerList();
System.out.println("First 3 orders in WA:");
customerList.stream().filter(c -> "WA".equals(c.region))
.flatMap(c -> c.orders.stream()
.map(o -> new HashMap<String, Object>() {{
put("customerID", c.customerID);
put("orderID", o.orderID);
put("orderDate", o.orderDate);
}})).limit(3)
.forEach(ObjectDumper::dump);
} |
59ddff59-0a4f-4aeb-9499-2bd555269b21 | static void linq22() {
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
System.out.println("All but first 4 numbers:");
Arrays.stream(numbers).skip(4).forEach(System.out::println);
} |
45b61418-85c4-469d-b2e3-ef34617f74b8 | static void linq23() {
List<Customer> customerList = Objects.getCustomerList();
System.out.println("All but first 2 orders in WA:");
customerList.stream().filter(c -> "WA".equals(c.region))
.flatMap(c -> c.orders.stream()
.map(o -> new HashMap<String, Object>() {{
put("customerID", c.customerID);
put("orderID", o.orderID);
put("orderDate", o.orderDate);
}})).skip(2)
.forEach(ObjectDumper::dump);
} |
43e26e0b-2799-4c32-8378-2c576aaf4ecd | static void linq24() {
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
System.out.println("First numbers less than 6:");
} |
b66f5e19-fab8-4438-a6b0-864414ba2837 | public static void dump(HashMap<String, Object> map) {
String result = map.entrySet().stream()
.map(x -> String.format(":%s %s", x.getKey(), x.getValue()))
.collect(Collectors.joining(" "));
System.out.println(result);
} |
828ec69f-b224-4518-b8a1-aaae8d6ae99e | public static void main(String[] args) {
RestrictionOperators.main(args);
ProjectionOperators.main(args);
PartitioningOperators.main(args);
} |
309fdcf3-b267-4787-a944-03f9f0a096f8 | public static void main(String[] args) {
linq6();
linq7();
linq8();
linq9();
linq10();
linq11();
linq12();
linq13();
linq14();
linq15();
linq16();
linq17();
linq18();
linq19();
} |
bec88159-b4f5-4c78-a416-d5b2dedef2a5 | private static void linq6() {
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
System.out.println("Numbers + 1:");
Arrays.stream(numbers).map(x -> x + 1).forEach(System.out::println);
} |
df9c3e98-d853-471f-ab08-0a7de6065c94 | private static void linq7() {
System.out.println("Product Names:");
Objects.getProductList().stream().map(x -> x.productName).forEach(System.out::println);
} |
d01c1bb2-3901-4bc3-a197-5202ef104656 | private static void linq8() {
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
String[] strings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
System.out.println("Number strings:");
Arrays.stream(numbers).mapToObj(x -> strings[x]).forEach(System.out::println);
} |
d8962e3d-22c7-45de-b05b-41325449300d | private static void linq9() {
String[] words = {"aPPLE", "BlUeBeRrY", "cHeRry"};
Arrays.stream(words).map(s -> new HashMap<String, String>() {{
put("Upper", s.toUpperCase());
put("Lower", s.toLowerCase());
}}).forEach(map -> System.out.println(
String.format("Uppercase : %s, Lowercase : %s", map.get("Upper"), map.get("Lower"))));
} |
fe3756f7-49de-4628-b8f0-4b97271e7b67 | private static void linq10() {
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
String[] strings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
Arrays.stream(numbers).mapToObj(number -> new HashMap<String, Object>() {{
put("Digit", strings[number]);
put("Even", number % 2 == 0);
}}).map(x -> String.format("The digit %s is %s.", x.get("Digit"), x.get("Even").equals(Boolean.FALSE) ? "odd" : "even"))
.forEach(System.out::println);
} |
ea93e5f5-0a1b-4cd7-8ed6-542e26fab8f5 | private static void linq11() {
System.out.println("Product Info:");
Objects.getProductList().stream().map(x -> new HashMap<String, Object>() {{
put("ProductName", x.productName);
put("Category", x.category);
put("Price", x.unitPrice);
}}).map(x -> String.format("%s is in the category %s and costs %f per unit.",
x.get("ProductName"), x.get("Category"), x.get("Price"))).forEach(System.out::println);
} |
e0717b70-6af9-455b-a448-c0e9431d2a18 | private static void linq12() {
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
System.out.println("Number: In-place?");
IntStream.range(0, numbers.length).mapToObj(i -> new HashMap<String, Object>() {{
put("Num", numbers[i]);
put("InPlace", numbers[i] == i);
}}).map(map -> map.get("Num") + ": " + map.get("InPlace")).forEach(System.out::println);
} |
c34f451e-3c2d-450d-b35d-d1ad31142c9b | private static void linq13() {
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
String[] digits = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
System.out.println("Numbers < 5:");
Arrays.stream(numbers).filter(x -> x < 5).mapToObj(x -> digits[x])
.forEach(System.out::println);
} |
b215a9b8-ca0f-49d0-9746-44e141d81eb1 | private static void linq14() {
int[] numbersA = {0, 2, 4, 5, 6, 8, 9};
int[] numbersB = {1, 3, 5, 7, 8};
System.out.println("Pairs where a < b:");
Arrays.stream(numbersA)
.mapToObj(a -> Arrays.stream(numbersB)
.filter(b -> a < b)
.mapToObj(b -> new HashMap<String, Object>() {{
put("A", a);
put("B", b);
}}))
.flatMap(x -> x)
.map(x -> String.format("%d is less than %d", x.get("A"), x.get("B")))
.forEach(System.out::println);
} |
ac32a5dc-73e6-4baa-b04a-8efca4e93617 | private static void linq15() {
List<Customer> customerList = Objects.getCustomerList();
customerList.stream().flatMap(c -> c.orders.stream()
.filter(o -> o.total < 500.0)
.map(o -> new HashMap<String, Object>() {{
put("customerID", c.customerID);
put("orderID", o.orderID);
put("total", o.total);
}})).forEach(ObjectDumper::dump);
} |
8c6b108d-8fe2-4068-ab10-39278acf62f6 | private static void linq16() {
List<Customer> customerList = Objects.getCustomerList();
customerList.stream().flatMap(c -> c.orders.stream()
.filter(o -> o.orderDate.isAfter(LocalDateTime.of(1998, 1, 1, 0, 0, 0)))
.map(o -> new HashMap<String, Object>() {{
put("customerID", c.customerID);
put("orderID", o.orderID);
put("orderDate", o.orderDate);
}})).forEach(ObjectDumper::dump);
} |
1421b78a-cb86-4cbd-8987-24bdb2c3db57 | private static void linq17() {
List<Customer> customerList = Objects.getCustomerList();
customerList.stream().flatMap(c -> c.orders.stream()
.filter(o -> o.total >= 2000.0)
.map(o -> new HashMap<String, Object>() {{
put("customerID", c.customerID);
put("orderID", o.orderID);
put("total", o.total);
}})).forEach(ObjectDumper::dump);
} |
f42d4df5-39e8-4278-88d9-51bfa8a8b951 | private static void linq18() {
List<Customer> customerList = Objects.getCustomerList();
LocalDateTime cutoffDate = LocalDateTime.of(1997, 1, 1, 0, 0, 0);
customerList.stream()
.filter(c -> "WA".equals(c.region))
.flatMap(c -> c.orders.stream()
.filter(o -> o.orderDate.isAfter(cutoffDate))
.map(o -> new HashMap<String, Object>() {{
put("customerID", c.customerID);
put("orderID", o.orderID);
}})).forEach(ObjectDumper::dump);
} |
b178f2b5-84aa-4e22-aaef-6c1c4ffe18cf | private static void linq19() {
List<Customer> customerList = Objects.getCustomerList();
IntStream.range(0, customerList.size())
.mapToObj(i -> customerList.get(i).orders.stream().map(o ->
"Customer #" + (i + 1) + " has an order with OrderID " + o.orderID))
.flatMap(x -> x).forEach(System.out::println);
} |
3bf43680-7416-4b27-a194-928acc33f377 | public Customer(String customerID, String companyName, String address, String city, String region,
String postalCode, String country, String phone, String fax, List<Order> orders) {
this.customerID = customerID;
this.companyName = companyName;
this.address = address;
this.city = city;
this.region = region;
this.postalCode = postalCode;
this.country = country;
this.phone = phone;
this.fax = fax;
this.orders = orders;
} |
6d6af76d-303e-4acd-a607-0ac86a8f86ce | @Override
public String toString() {
return "Customer{" +
"customerID='" + customerID + '\'' +
", companyName='" + companyName + '\'' +
", address='" + address + '\'' +
", city='" + city + '\'' +
", region='" + region + '\'' +
", postalCode='" + postalCode + '\'' +
", country='" + country + '\'' +
", phone='" + phone + '\'' +
", fax='" + fax + '\'' +
", orders=" + (orders == null ? 0 : orders.size()) +
'}';
} |
17e3c132-653b-43ed-838e-c0ddc60e3ebf | public static List<Product> getProductList() {
return Arrays.asList(
new Product(1, "Chai", "Beverages", 18.0000, 39),
new Product(2, "Chang", "Beverages", 19.0000, 17),
new Product(3, "Aniseed Syrup", "Condiments", 10.0000, 13),
new Product(4, "Chef Anton's Cajun Seasoning", "Condiments", 22.0000, 53),
new Product(5, "Chef Anton's Gumbo Mix", "Condiments", 21.3500, 0),
new Product(6, "Grandma's Boysenberry Spread", "Condiments", 25.0000, 120),
new Product(7, "Uncle Bob's Organic Dried Pears", "Produce", 30.0000, 15),
new Product(8, "Northwoods Cranberry Sauce", "Condiments", 40.0000, 6),
new Product(9, "Mishi Kobe Niku", "Meat/Poultry", 97.0000, 29),
new Product(10, "Ikura", "Seafood", 31.0000, 31),
new Product(11, "Queso Cabrales", "Dairy Products", 21.0000, 22),
new Product(12, "Queso Manchego La Pastora", "Dairy Products", 38.0000, 86),
new Product(13, "Konbu", "Seafood", 6.0000, 24),
new Product(14, "Tofu", "Produce", 23.2500, 35),
new Product(15, "Genen Shouyu", "Condiments", 15.5000, 39),
new Product(16, "Pavlova", "Confections", 17.4500, 29),
new Product(17, "Alice Mutton", "Meat/Poultry", 39.0000, 0),
new Product(18, "Carnarvon Tigers", "Seafood", 62.5000, 42),
new Product(19, "Teatime Chocolate Biscuits", "Confections", 9.2000, 25),
new Product(20, "Sir Rodney's Marmalade", "Confections", 81.0000, 40),
new Product(21, "Sir Rodney's Scones", "Confections", 10.0000, 3),
new Product(22, "Gustaf's Knäckebröd", "Grains/Cereals", 21.0000, 104),
new Product(23, "Tunnbröd", "Grains/Cereals", 9.0000, 61),
new Product(24, "Guaraná Fantástica", "Beverages", 4.5000, 20),
new Product(25, "NuNuCa Nuß-Nougat-Creme", "Confections", 14.0000, 76),
new Product(26, "Gumbär Gummibärchen", "Confections", 31.2300, 15),
new Product(27, "Schoggi Schokolade", "Confections", 43.9000, 49),
new Product(28, "Rössle Sauerkraut", "Produce", 45.6000, 26),
new Product(29, "Thüringer Rostbratwurst", "Meat/Poultry", 123.7900, 0),
new Product(30, "Nord-Ost Matjeshering", "Seafood", 25.8900, 10),
new Product(31, "Gorgonzola Telino", "Dairy Products", 12.5000, 0),
new Product(32, "Mascarpone Fabioli", "Dairy Products", 32.0000, 9),
new Product(33, "Geitost", "Dairy Products", 2.5000, 112),
new Product(34, "Sasquatch Ale", "Beverages", 14.0000, 111),
new Product(35, "Steeleye Stout", "Beverages", 18.0000, 20),
new Product(36, "Inlagd Sill", "Seafood", 19.0000, 112),
new Product(37, "Gravad lax", "Seafood", 26.0000, 11),
new Product(38, "Côte de Blaye", "Beverages", 263.5000, 17),
new Product(39, "Chartreuse verte", "Beverages", 18.0000, 69),
new Product(40, "Boston Crab Meat", "Seafood", 18.4000, 123),
new Product(41, "Jack's New England Clam Chowder", "Seafood", 9.6500, 85),
new Product(42, "Singaporean Hokkien Fried Mee", "Grains/Cereals", 14.0000, 26),
new Product(43, "Ipoh Coffee", "Beverages", 46.0000, 17),
new Product(44, "Gula Malacca", "Condiments", 19.4500, 27),
new Product(45, "Rogede sild", "Seafood", 9.5000, 5),
new Product(46, "Spegesild", "Seafood", 12.0000, 95),
new Product(47, "Zaanse koeken", "Confections", 9.5000, 36),
new Product(48, "Chocolade", "Confections", 12.7500, 15),
new Product(49, "Maxilaku", "Confections", 20.0000, 10),
new Product(50, "Valkoinen suklaa", "Confections", 16.2500, 65),
new Product(51, "Manjimup Dried Apples", "Produce", 53.0000, 20),
new Product(52, "Filo Mix", "Grains/Cereals", 7.0000, 38),
new Product(53, "Perth Pasties", "Meat/Poultry", 32.8000, 0),
new Product(54, "Tourtière", "Meat/Poultry", 7.4500, 21),
new Product(55, "Pâté chinois", "Meat/Poultry", 24.0000, 115),
new Product(56, "Gnocchi di nonna Alice", "Grains/Cereals", 38.0000, 21),
new Product(57, "Ravioli Angelo", "Grains/Cereals", 19.5000, 36),
new Product(58, "Escargots de Bourgogne", "Seafood", 13.2500, 62),
new Product(59, "Raclette Courdavault", "Dairy Products", 55.0000, 79),
new Product(60, "Camembert Pierrot", "Dairy Products", 34.0000, 19),
new Product(61, "Sirop d'érable", "Condiments", 28.5000, 113),
new Product(62, "Tarte au sucre", "Confections", 49.3000, 17),
new Product(63, "Vegie-spread", "Condiments", 43.9000, 24),
new Product(64, "Wimmers gute Semmelknödel", "Grains/Cereals", 33.2500, 22),
new Product(65, "Louisiana Fiery Hot Pepper Sauce", "Condiments", 21.0500, 76),
new Product(66, "Louisiana Hot Spiced Okra", "Condiments", 17.0000, 4),
new Product(67, "Laughing Lumberjack Lager", "Beverages", 14.0000, 52),
new Product(68, "Scottish Longbreads", "Confections", 12.5000, 6),
new Product(69, "Gudbrandsdalsost", "Dairy Products", 36.0000, 26),
new Product(70, "Outback Lager", "Beverages", 15.0000, 15),
new Product(71, "Flotemysost", "Dairy Products", 21.5000, 26),
new Product(72, "Mozzarella di Giovanni", "Dairy Products", 34.8000, 14),
new Product(73, "Röd Kaviar", "Seafood", 15.0000, 101),
new Product(74, "Longlife Tofu", "Produce", 10.0000, 4),
new Product(75, "Rhönbräu Klosterbier", "Beverages", 7.7500, 125),
new Product(76, "Lakkalikööri", "Beverages", 18.0000, 57),
new Product(77, "Original Frankfurter grüne Soße", "Condiments", 13.0000, 32)
);
} |
f21e118d-e8df-4590-a9a7-5bc1a15f831a | public static List<Customer> getCustomerList() {
File file;
try {
file = new File(Objects.class.getResource("/Customers.xml").toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
throw new RuntimeException("blah");
}
try {
return $(file).find("customer").map(ctx -> new Customer(
$(ctx).children("id").text()
, $(ctx).children("name").text()
, $(ctx).children("address").text()
, $(ctx).children("city").text()
, $(ctx).children("region").text()
, $(ctx).children("postalcode").text()
, $(ctx).children("country").text()
, $(ctx).children("phone").text()
, $(ctx).children("fax").text()
, $(ctx).find("order").map(orderCtx -> new Order(
Integer.parseInt($(orderCtx).children("id").text()),
LocalDateTime.parse($(orderCtx).children("orderdate").text()),
Double.parseDouble($(orderCtx).children("total").text())
))
));
} catch (SAXException | IOException e) {
throw new RuntimeException("blah");
}
} |
6dfe84fd-7e13-4d66-bac7-66f6a005602d | public Product(int productID, String productName, String category, double unitPrice, int unitsInStock) {
this.productID = productID;
this.productName = productName;
this.category = category;
this.unitPrice = unitPrice;
this.unitsInStock = unitsInStock;
} |
f714d08c-61ee-47e8-a277-d0de3426a3bc | public Order(int orderID, LocalDateTime orderDate, double total) {
this.orderID = orderID;
this.orderDate = orderDate;
this.total = total;
} |
f0655e4e-e511-4910-a64e-bcf2abca096c | public static int[] addToArray(String inputString) {
// Add to String array
String[] strArray = inputString.split("");
// Set int array to length of ISBN
int[] intArray = new int[strArray.length];
// Move values from String array to int array
for(int i = 0; i < strArray.length; i++) {
intArray[i] = Integer.parseInt(strArray[i]);
}
return intArray;
} |
f60b13b4-d4fc-4d21-a57c-f738cc6d57f3 | public static String getFixedLengthNumber(int length) {
Scanner scan = new Scanner(System.in);
String inputNum = "";
boolean validInput = false;
// Ensure input is valid.
while (!validInput) {
System.out.print("Enter a " + length + " digit number: ");
inputNum = scan.nextLine();
// If characters are correct
if (inputNum.matches("([0-9]+)")) {
// If length is correct
if (inputNum.length() == length) {
validInput = true;
} else {
System.out.print("Invalid input. Ensure the value contains " + length + " numbers.\n\n");
}
} else {
System.out.print("Invalid input. Contains incorrect characters\n");
}
}
return inputNum;
} |
a47e1764-055c-4577-a627-094987581e5a | public static String getVariableLengthNumber() {
Scanner scan = new Scanner(System.in);
String inputNum = "";
boolean validInput = false;
// Ensure input is valid.
while (!validInput) {
System.out.print("Enter an integer: ");
inputNum = scan.nextLine();
// If characters are correct
if (inputNum.matches("(([-]?[0-9]+))")) {
validInput = true;
} else {
System.out.print("Invalid input. Contains incorrect characters\n");
}
}
return inputNum;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.