id
stringlengths
36
36
text
stringlengths
1
1.25M
0391cb2b-db33-412f-9475-de2cc3523145
public Image draw(APIResponse response) { if (response.getStatus() != 0) return null; ByteArrayInputStream bis = new ByteArrayInputStream(data); try { BufferedImage image = ImageIO.read(bis); Graphics2D g2d = image.createGraphics(); FontMetrics fm = g2d.getFontMetrics(); BasicStroke bs = new BasicS...
b50cbd85-1cbd-45bc-be0b-617386c2bcb0
public void save(String path) throws IOException { BufferedOutputStream bos = null; FileOutputStream fos = new FileOutputStream(new File(path)); bos = new BufferedOutputStream(fos); bos.write(data); }
b170d46b-3192-4322-9461-876a04e62639
public APIResponse(String jsonToParse) { objects = new ArrayList<APIObject>(); try { JSONObject resp = new JSONObject(jsonToParse); this.status= resp.getInt("status"); if (status != 0) { this.message = resp.getString("message"); return; } JSONArray obj = resp.getJSONArray("objects"); for (...
b46e6913-09c8-4875-abe3-31b8b8c43f94
public APIResponse(int status) { this.status = status; }
c9fc9c26-9d3b-4f14-9bef-03d130d31381
public int getStatus() { return status; }
28a62ed0-0b32-48df-b2d5-fe6bbd3cfd07
public String getMessage() { return message; }
fd42876b-61e5-4698-8f3b-532b1dd69146
public ArrayList<APIObject> getObjects() { return objects; }
16135d70-fbc0-4f53-abe8-4486be7574ef
public void setStatus(int status) { this.status = status; }
3f985dc5-2a21-4e87-88c7-6b2adc3c1d84
public void setMessage(String message) { this.message = message; }
61bab3d9-9e7a-4013-ac36-5f58d4ad3869
public void setObjects(ArrayList<APIObject> objects) { this.objects = objects; }
b299c803-29a9-4fa5-b537-7d6b9855d96e
@Override public String toString() { if (status < 0) return "Internal error: " + this.getMessage(); if (status > 0) return this.getMessage(); String text = "Found " + this.objects.size() + " objects: {"; for (APIObject obj: this.objects) { text += obj.getName() + ", "; } text = text.substring(0, t...
3f1fac53-1636-4d3d-bade-8b42e6442e6d
public APIObject(JSONObject object) throws JSONException { location = new ArrayList<Point>(); this.id = object.getString("id"); this.name = object.getString("name"); JSONArray loc = object.getJSONArray("location"); for (int i = 0; i < loc.length(); ++i) { location.add(new Point(loc.getJSONObject(i))); } ...
b54aadd5-6244-4e73-bd73-8c5750ac3de8
public String getId() { return id; }
34905c4a-862e-4a3c-9723-abb264193316
public String getName() { return name; }
5833bca7-e910-429f-8997-c39f443b4bd5
public void setId(String id) { this.id = id; }
20fd34ca-8fad-469b-91ed-8363653b11a9
public void setName(String name) { this.name = name; }
90677130-ecf1-4e8a-b9d2-b32211497faa
public ArrayList<Point> getLocation() { return location; }
c86cde8e-19cb-422c-9033-2664433b12e3
public void setLocation(ArrayList<Point> location) { this.location = location; }
073acfb5-1a5c-43f4-a1da-653bcd9a3055
public static void main(String[] args) { Image image = readImageData("joker.jpg"); if (image == null || image.getData() == null) { System.err.println("Given image could not be read"); return; } try { // initialize proxy class (this perform authorisation) ITraffSoapProxy iTraffSoap = new ITraffSoap...
cebff233-d7a9-420b-93c5-05113da24870
private static Image readImageData(String imageName) { byte[] imgData = null; BufferedImage img = null; try { //read image data InputStream imgIs = new FileInputStream(imageName); imgData = new byte[imgIs.available()]; imgIs.read(imgData); imgIs.close(); //read image dimensions img = Imag...
b00d1c9a-0f3f-4bad-b6d2-fce88e5fd00e
public static APIResponse recognizeReturnBest(Image image) throws IOException, JSONException { String recognizeMode = "single"; URL url = new URL(SERVER_ADDRESS + "v2/recognize/single/" + clientId); return recognize(image, url, recognizeMode); }
76e3656c-3a7f-4782-a757-d48f93d2fbd7
public static APIResponse recognizeReturnAll(Image image) throws IOException, JSONException { String recognizeMode = "single"; URL url = new URL(SERVER_ADDRESS + "v2/recognize/single/all/" + clientId); return recognize(image, url, recognizeMode); }
e5897baf-90d5-46bb-b8d1-318b79c9224c
public static APIResponse recognizeMulti(Image image) throws IOException, JSONException { String recognizeMode = "multi"; URL url = new URL(SERVER_ADDRESS + "v2/recognize/multi/" + clientId); return recognize(image, url, recognizeMode); }
93d19d46-d802-49e6-b955-6daca365b68c
public static APIResponse recognizeMultiAllInstances(Image image) throws IOException, JSONException { String recognizeMode = "multi"; URL url = new URL(SERVER_ADDRESS + "v2/recognize/multi/all/" + clientId); return recognize(image, url, recognizeMode); }
46813402-5313-42c8-8a8e-de913afe7ea5
private static APIResponse recognize(Image image, URL url, String recognizeMode) throws IOException, JSONException { APIResponse response = new APIResponse(-1); if (!checkImageLimits(image, recognizeMode)) { System.err.println("Image does not fulfill the requirements, terminating."); response.setMessage("Imag...
a8db410b-1181-424c-b272-dd9b4742ac8a
private static boolean checkImageLimits(Image image, String recognizeMode) { final float imageSurface = (float)(image.getHeight() * image.getWidth()) / 1000000.f; //Mpix final float fileSize = (float)image.getData().length / 1000.f; //KBytes if (recognizeMode.equalsIgnoreCase("single")) { if (file...
adece35b-6a59-4b58-8ba8-e82e3023449a
private static String getMD5FromKeyAndImage(String clientKey, byte[] image) { String hash = null; try { java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); md.reset(); md.update(clientKey.getBytes("UTF-8")); md.update(image); byte[] array = md.digest(); StringBuffer sb...
3c7d7537-8d1e-4540-921b-386f390b7762
private static String getResponseJson(BufferedReader in) throws IOException { StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); return sb.toString(); }
d3d56284-13b9-41ba-b9df-5898259f0a8a
public Point(JSONObject jsonObject) throws JSONException { this.x = jsonObject.getInt("x"); this.y = jsonObject.getInt("y"); }
1014f0c2-937d-427e-95f9-d47fa29d1592
public int getX() { return x; }
99f1052e-fa90-46bc-98f4-5c739f427a11
public int getY() { return y; }
5e93e631-c98f-4ef1-8a87-7f0259a18106
public void setX(int x) { this.x = x; }
9955128f-38af-4808-a947-e71c768ea3d1
public void setY(int y) { this.y = y; }
987466b8-b5c5-4934-bf35-a2336d2794ef
@Test public void testAprValidator() { assertTrue(Validators.getAprValidator().isValid(0.3)); assertTrue(Validators.getAprValidator().isValid(0.000001)); assertTrue(Validators.getAprValidator().isValid(1d)); assertTrue(Validators.getAprValidator().isValid(50d)); assertTrue(Validators.getAprValidator().isVal...
1fc2709d-6995-4a54-a515-0ceb53417b29
@Test public void testTermValidator() { assertTrue(Validators.getTermValidator().isValid(1d)); assertTrue(Validators.getTermValidator().isValid(5d)); assertTrue(Validators.getTermValidator().isValid(999999d)); assertTrue(Validators.getTermValidator().isValid(1000000d)); assertTrue(Validators.getTermValidato...
461fc12a-ea3f-4f8c-a08d-88b455b073d1
public AmortizationScheduleItem(final int paymentNumber, final BigDecimal paymentAmount, final BigDecimal paymentInterest, final BigDecimal currentBalance, final BigDecimal totalPayments, final BigDecimal totalInterestPaid) { super(); this.paymentNumber = paymentNumber; this.paymentAmount = paymentAmount; ...
3f94ccc9-fc8a-4262-898c-4a46b7ad77e3
public int getPaymentNumber() { return paymentNumber; }
b13f0df2-b820-4d31-8fa3-78f68f43cc39
public void setPaymentNumber(final int paymentNumber) { this.paymentNumber = paymentNumber; }
61dac940-b7d8-4669-adc5-0f109760cd78
public BigDecimal getPaymentAmount() { return paymentAmount; }
3deefa02-6ebd-497c-9388-96419762d266
public void setPaymentAmount(final BigDecimal paymentAmount) { this.paymentAmount = paymentAmount; }
d5e25cf2-7f4c-4b09-a373-a1dd8ee7250b
public BigDecimal getPaymentInterest() { return paymentInterest; }
7b209b69-766d-4271-b93c-8d370f353adb
public void setPaymentInterest(final BigDecimal paymentInterest) { this.paymentInterest = paymentInterest; }
ca5c06e4-eb9a-4d3d-8700-c7d1ffbf0576
public BigDecimal getCurrentBalance() { return currentBalance; }
d0afd240-6651-4bde-a11c-fde6e7bc68aa
public void setCurrentBalance(final BigDecimal currentBalance) { this.currentBalance = currentBalance; }
33ccd7de-bf91-4d23-ad62-c4fb4590c147
public BigDecimal getTotalPayments() { return totalPayments; }
b504b6e1-de0a-4731-863a-cb01cf0a41fd
public void setTotalPayments(final BigDecimal totalPayments) { this.totalPayments = totalPayments; }
67cf3396-50aa-464d-8fba-2f094ea9ddc6
public BigDecimal getTotalInterestPaid() { return totalInterestPaid; }
8ac24577-8ff2-47ac-949d-b48d1f6e599a
public void setTotalInterestPaid(final BigDecimal totalInterestPaid) { this.totalInterestPaid = totalInterestPaid; }
6a6911c9-8381-4f7e-b5da-1a9e161e7a82
private long calculateMonthlyPayment() { // M = P * (J / (1 - (Math.pow(1/(1 + J), N)))); // // Where: // P = Principal // I = Interest // J = Monthly Interest in decimal form: I / (12 * 100) // N = Number of months of loan // M = Monthly Payment Amount // // calculate J monthlyInterest = apr...
3613911d-0653-418d-b43d-9f406f152833
public void outputAmortizationSchedule() { // // To create the amortization table, create a loop in your program and follow these steps: // 1. Calculate H = P x J, this is your current monthly interest // 2. Calculate C = M - H, this is your monthly payment minus your monthly interest, so it is the a...
05d95835-e577-4ea0-bec5-94e790d0750f
public AmortizationScheduleOrig(double amount, double interestRate, int years) throws IllegalArgumentException { if ((isValidBorrowAmount(amount) == false) || (isValidAPRValue(interestRate) == false) || (isValidTerm(years) == false)) { throw new IllegalArgumentException(); } amountBorrowed = Math.rou...
ab25de61-d00d-4b44-964d-8f7fdb1698b7
public static boolean isValidBorrowAmount(double amount) { double range[] = getBorrowAmountRange(); return ((range[0] <= amount) && (amount <= range[1])); }
d3e175fe-3c1e-4098-8943-c4838274c10a
public static boolean isValidAPRValue(double rate) { double range[] = getAPRRange(); return ((range[0] <= rate) && (rate <= range[1])); }
b402965e-6b76-46a3-99f0-382233b7fefb
public static boolean isValidTerm(int years) { int range[] = getTermRange(); return ((range[0] <= years) && (years <= range[1])); }
10e9078e-c5ad-4326-97a2-5f014b08f6cd
public static final double[] getBorrowAmountRange() { return borrowAmountRange; }
960e0cff-0afd-4c94-9ec5-39e0d319df76
public static final double[] getAPRRange() { return aprRange; }
7d1a8828-3f4f-4d63-95a3-08e96e30d598
public static final int[] getTermRange() { return termRange; }
834a3e8d-5d54-494b-b67d-bbb813f49926
private static void printf(String formatString, Object... args) { try { if (console != null) { console.printf(formatString, args); } else { System.out.print(String.format(formatString, args)); } } catch (IllegalFormatException e) { System.err.print("Error printing...\n"); } }
4d7252e5-ef12-46c4-8bf2-25262239b54c
private static void print(String s) { printf("%s", s); }
6274f317-edfa-462a-a70f-94d99fe0abfd
private static String readLine(String userPrompt) throws IOException { String line = ""; if (console != null) { line = console.readLine(userPrompt); } else { // print("console is null\n"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); print(userPrompt); l...
c31ef0cb-4577-4054-8fe7-116a956e605f
public static void main(String [] args) { String[] userPrompts = { "Please enter the amount you would like to borrow: ", "Please enter the annual percentage rate used to repay the loan: ", "Please enter the term, in years, over which the loan is repaid: " }; String line = ""; double amount = 0...
6e8f29c4-3c4d-4e30-8f9e-f5e87d934633
public static Validatable<Double> getBorrowAmountValidator() { return BORROW_AMOUT_VALIDATOR; }
cfc515b1-fdbd-49dc-84bd-f2f211c624b6
public static Validatable<Double> getAprValidator() { return APR_VALIDATOR; }
33353d3d-b170-492d-9a52-25583c7a2060
public static Validatable<Double> getTermValidator() { return TERM_VALIDATOR; }
e6b7051b-4415-43c0-a455-31b15e9bc2fc
private Validators() { // no-op }
133274a2-f398-4f66-a1fb-ca30fdf77eb8
@Override public boolean isValid(final Double value) { return value == value.intValue() && TERM_RANGE_VALIDATOR.isValid(value.intValue()); }
ec3700c5-c4c2-4e58-b887-604dea55a891
public RangeValidator(final Range<T> range) { this.range = range; }
c486f6d6-d2b1-466f-bed6-75e3d522e9a6
@Override public boolean isValid(final T amount) { return amount.compareTo(range.getMin()) >= 0 && amount.compareTo(range.getMax()) <= 0; }
f6f73a42-1e32-4507-8bb9-88b0eac728e0
boolean isValid(T value);
2cfe0642-26b8-43a3-9f5b-0ac65c0c969f
private long calculateMonthlyPayment() { // M = P * (J / (1 - (Math.pow(1/(1 + J), N)))); // // Where: // P = Principal // I = Interest // J = Monthly Interest in decimal form: I / (12 * 100) // N = Number of months of loan // M = Monthly Payment Amount ...
4edd836d-1e53-4382-b816-13853a84d8c7
public List<AmortizationScheduleItem> outputAmortizationSchedule() { // // To create the amortization table, create a loop in your program and // follow these steps: // 1. Calculate H = P x J, this is your current monthly interest // 2. Calculate C = M - H, this is your monthly p...
30cf5c35-53f3-41c2-8877-e4f520d789ab
public AmortizationSchedule(final double amount, final double interestRate, final int years) { if (!Validators.getBorrowAmountValidator().isValid(amount) || !Validators.getAprValidator().isValid(interestRate) || !Validators.getTermValidator().isValid((double) years)) { ...
42183144-452a-48e2-8999-ad5a40034a2b
public static void main(String[] args) { final String[] userPrompts = { "Please enter the amount you would like to borrow: ", "Please enter the annual percentage rate used to repay the loan: ", "Please enter the term, in years, over which the loan is repaid: " };...
40cf1207-f3b9-4a43-ba05-cbf9b17db5d8
private static Double getValue(final String promptMessage, final Validatable<Double> validator, final String invalidMessage) throws IOException { boolean isValid = false; double amount = 0; while (!isValid) { String line = IOUtils.readLine(promptMessage); ...
b8592724-504f-4de7-9f0b-f64bb23954c7
private IOUtils() { }
11fde327-8761-4fc8-b4e1-d11a3a2fed37
public static void printf(String formatString, Object... args) { try { if (console != null) { console.printf(formatString, args); } else { System.out.print(String.format(formatString, args)); } } catch (IllegalFormatException e) { System.err.print("Error printing...\n"); } }
cce11874-6f79-4c56-b874-962994f9a2ed
public static void print(String s) { printf("%s", s); }
65e1feee-4a70-4669-9d93-f1b085e98dcc
public static String readLine(final String userPrompt) throws IOException { String line = ""; if (console != null) { line = console.readLine(userPrompt); } else { // print("console is null\n"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); print(userPrompt);...
4a7ba388-785a-4148-9828-52ae03d53e6c
public static void printSchedule(List<AmortizationScheduleItem> items) { String formatString = "%1$-20s%2$-20s%3$-20s%4$-20s%5$-30s%6$-30s\n"; printf(formatString, "PaymentNumber", "PaymentAmount", "PaymentInterest", "CurrentBalance", "TotalPayments", "TotalInterestPaid"); // output is in dollars forma...
187a7f0d-78ca-4eda-a966-3880f03599ec
public Range(final T min, final T max) { this.min = min; this.max = max; }
9220e9d2-7bc1-46f2-855a-f6e3695e6609
public T getMin() { return min; }
552192e5-f6f7-430b-9979-fcd4dde3ed9a
public T getMax() { return max; }
85ef7270-4d9e-4432-ba73-4e0621a2c2cc
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((max == null) ? 0 : max.hashCode()); result = prime * result + ((min == null) ? 0 : min.hashCode()); return result; }
e93b496d-5d32-4b57-b2aa-081297ab75b7
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Range other = (Range) obj; if (max == null) { if (other.max != null) { return false; } } else if (!max.equals...
0e71f337-b57e-453c-853f-4f25f5502bb0
public static String leerFichero(String nombreFichero) throws IOException { File fichero = new File (nombreFichero); // Crea un objeto File a partir del nombre del fichero a leer Scanner scan = new Scanner(fichero); //Crea un Scanner para recorrer el fichero y recuperar el contenido StringBuffer texto=new String...
5f428e8b-c988-427b-882b-0ad7a55e02ad
public static void escribirFichero(String texto,String nombreFichero) throws FileNotFoundException { File fichero = new File (nombreFichero); // Crea un objeto File a partir del nombre de fichero a guardar PrintWriter escritor = new PrintWriter(fichero); escritor.print(texto); // escribe el texto en fichero...
a5a19d4c-7307-46de-b722-654840487946
public static void main(String[] args) { Scanner consola = new Scanner(System.in); //Crea Scanner para leer por consola System.out.println("Nombre del fichero a leer> "); String nombreFichIn=consola.nextLine(); //lee la l�nea con el nombre de fichero desde consola String contenido=null; //para guardar...
942120fd-5ef7-45e9-bb85-0aaf42e29f13
public static void main(String[] args) throws IOException { Scanner consola = new Scanner(System.in); //Construye objeto Scanner para leer desde consola (entrada est�ndar) String linea; //para almacenar una l�nea de texto por consola System.out.println("Introduzca su nombre> "); linea=consola.nextLine();...
204c06fe-2bea-4b93-aef1-ecc795b6ca7a
static void ejemComparaCadenas(){ System.out.println("\nSALIDA método ejemComparaCadenas.\n"); System.out.println("*** Compara cadenas con equals"); String saludo1="hola"; String saludo2="Hola"; boolean coincide= saludo1.equals(saludo2); if (coincide) System.out.println("Las cadenas \""+ saludo1 + "\" y...
54bd4282-05bc-4442-b64e-e6b6fa7068ea
public static void ejemTrimToEntero() { System.out.println("\nSALIDA método ejemTrimToEntero.\n"); String cadena=" 725 "; System.out.println("*** Elimina espacios con trim"); cadena=cadena.trim(); //elimina espacios de prefijo y sufijo en la cadena System.out.println("Tras aplicar trim la cadena e...
8da4fd9a-f075-44fb-9040-b9f7b4899f3a
static void ejemRecorridoString(){ String[] listaCadenas={"hola","mundo",""}; //inicializa array de 3 Strings, la última es la cadena vacía String cadena; //para almacenar cadena extraída de un array de Strings int longitudCadena; // para guardar longitud de cadena extraída System.out.println("\nSALIDA m...
a385dc70-ba31-42cd-911a-6ee3a4e865ce
static void ejemSplitSimple(){ System.out.println("\nSALIDA método ejemSplitSimple."); String saludo="123,45,2"; String[] listaCadenas=saludo.split(","); //obtiene las cadenas leídas en la línea System.out.println("***Cadenas extraídas con split con ; como separador:"); System.out.println("Texto: ...
dc28436f-e59c-469d-be73-5d3cc06366fb
static void ejemSplitER(){ System.out.println("\nSALIDA método ejemSplitER."); String saludo="123..45,2"; String erSeparador = "[,.]+"; // ER para secuencia de coma/punto como posible separador String [] troceo1 = saludo.split(erSeparador); // las cadenas extraídas se quedan en array troceo System.out.pri...
2bc22f63-130a-4af8-b1f7-dd292acd7493
public static void main(String[] args) throws IOException { ejemComparaCadenas(); ejemTrimToEntero(); ejemRecorridoString(); ejemSplitSimple(); ejemSplitER(); }
65842108-e4b5-4725-967c-9354a7225c05
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { JLabel lbl = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); if(value.toString().equals("Sent Items")) { lbl.setIcon(SEN...
556a44be-aba0-4771-9694-d9896fc2016a
public static void makeTreeIcons() { getTreeIcons().add("Email"); getTreeIcons().add("Timeout"); getTreeIcons().add("Sent Items"); }
7e8d79f4-9328-44ef-a9cf-dfc9c6272c9d
public static ArrayList<Object> getTreeIcons() { return treeIcons; }
9f9d03f1-e2c3-4064-94c2-af20e55d5b3f
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { EstimateClasses frame = new EstimateClasses(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
acf2b139-d1db-43f2-ac6b-08cec08634b6
public void run() { try { EstimateClasses frame = new EstimateClasses(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } }
96387638-b46a-4cda-9c7a-24688fd66475
public EstimateClasses() { setTitle("Estimated Classes"); setIconImage(Toolkit.getDefaultToolkit().getImage(EstimateClasses.class.getResource("/net/lotusdev/medusa/client/res/JavaClass.gif"))); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); cont...