/** * Sets a mnemomic for the specified button. * * @param b button * @param mnem mnemonics that have already been assigned */ public static void setMnemonic(final AbstractButton b, final StringBuilder mnem) { // do not set mnemonics for Mac! Alt+key used for special characters. if (Prop.MAC) return; // find and assign unused mnemomic final String label = b.getText(); final int ll = label.length(); for (int l = 0; l < ll; l++) { final char ch = Character.toLowerCase(label.charAt(l)); if (!letter(ch) || mnem.indexOf(Character.toString(ch)) != -1) continue; b.setMnemonic(ch); mnem.append(ch); break; } }
public static void main(String args[]) throws IOException { DataInputStream ip = new DataInputStream(System.in); String S1 = new String(); String temp; String S2 = new String(); int i; System.out.print("Enter expression : "); temp = ip.readLine(); for (i = 0; i < temp.length(); i++) { if (temp.charAt(i) == '*') { // System.out.println(temp.substring(0,i)); //i because of gorm [,) // System.out.println(temp.substring(i+1,temp.length())); S1 = temp.substring(0, i); // i because of gorm [,) S2 = temp.substring(i + 1, temp.length()); } } int a1[] = new int[100]; int a2[] = new int[100]; int k = 0; for (i = S1.length() - 1; i >= 0; i--) { String temp2 = Character.toString(S1.charAt(i)); a1[99 - k] = Integer.parseInt(temp2); k++; } k = 0; for (i = S2.length() - 1; i >= 0; i--) { String temp2 = Character.toString(S2.charAt(i)); a2[99 - k] = Integer.parseInt(temp2); k++; } int a3[] = new int[100]; /* * write multiplication code here */ int temp3 = 0; for (i = 99; i > 99 - S1.length(); i--) // change here { int temp2 = a1[i] * a2[99] + temp3; temp3 = 0; // addition to correct code since it was not being set to zero it was causing errors if (temp2 < 10 || i == 99 - S1.length() + 1) // change made here so that if last result is >=10 { // it should be written directly a3[i] = temp2; } else { a3[i] = temp2 % 10; temp3 = ((temp2 - temp2 % 10) / 10); // unneccessary+a3[i-1]; } } for (i = 0; i < 100; i++) { System.out.print(a3[i]); } }
public static void findTExtLetters(String letterToFind, String filePath) throws IOException { BufferedReader br = new BufferedReader(new FileReader(new File(filePath))); boolean foundIt = false; int i = 1; String[] letterToFindarray = letterToFind.split(""); for (String line = br.readLine(); line != null; line = br.readLine()) { String[] letterarray = line.split(""); for (int j = 0; j < letterarray.length; j++) { for (int x = 0; x < letterToFindarray.length; x++) { if (letterToFindarray[x].equals(letterarray[j])) { System.out.println("Egyezes a(z)" + i + ". sor, " + (j + 1) + ". karakterrel"); foundIt = true; } else { char m = letterToFindarray[x].charAt(0); int o = (int) m; if (o < 95) { // nagy betűt keresek és kis betű a keresendőben char n = letterarray[j].charAt(0); int p = (int) n; p = p - 32; n = (char) p; String backToString = Character.toString(n); if (letterToFindarray[x].equals(backToString)) { System.out.println("Egyezes a(z)" + i + ". sor, " + (j + 1) + ". karakterrel"); foundIt = true; } } else { //// kis betűt keresek és nagy betű a keresendőben char n = letterarray[j].charAt(0); int p = (int) n; p = p + 32; n = (char) p; String backToString = Character.toString(n); if (letterToFindarray[x].equals(backToString)) { System.out.println("Egyezes a(z)" + i + ". sor, " + (j + 1) + ". karakterrel"); foundIt = true; } } } } } i++; } if (!foundIt) { System.out.println("Nincs ilyen szo"); } }
private String ask(String cmd) { BufferedWriter out = null; BufferedReader in = null; Socket sock = null; String ret = ""; try { System.out.println(server); sock = new Socket(server, ServerListener.PORT); out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); out.write(cmd, 0, cmd.length()); out.flush(); in = new BufferedReader(new InputStreamReader(sock.getInputStream())); int inr = in.read(); while (inr != ';') { ret += Character.toString((char) inr); inr = in.read(); } } catch (IOException io) { io.printStackTrace(); } finally { try { out.close(); in.close(); sock.close(); } catch (IOException io) { io.printStackTrace(); } } return ret; }
private void fixTabs(int tabSize) { int rowIndex = 0; for (StringBuilder row1 : rows) { String row = row1.toString(); StringBuilder newRow = new StringBuilder(); char[] chars = row.toCharArray(); for (char c : chars) { if (c == '\t') { int spacesLeft = tabSize - newRow.length() % tabSize; if (DEBUG) { System.out.println("Found tab. Spaces left: " + spacesLeft); } String spaces = StringUtils.repeatString(" ", spacesLeft); newRow.append(spaces); } else { String character = Character.toString(c); newRow.append(character); } } rows.set(rowIndex, newRow); rowIndex++; } }
private void invalidNamedArgument(String[] args) throws ArgumentDoesNotExistException { for (int i = 0; i < args.length; i++) { if (args[i].startsWith("--")) { String[] splitLongNamedArg = new String[2]; splitLongNamedArg = args[i].split("--"); NamedArgument tempArg = getNamedArgument(splitLongNamedArg[1]); if (tempArg == null) { invalidNamedArgument = splitLongNamedArg[1]; throw new ArgumentDoesNotExistException( argumentDoesNotExistMessage(invalidNamedArgument)); } } else if (args[i].startsWith("-")) { String[] splitShortNamedArg = new String[2]; splitShortNamedArg = args[i].split("-"); if (splitShortNamedArg[1].length() == 1) { // single char NamedArgument tempArg = getNamedArgument(splitShortNamedArg[1].charAt(0)); if (tempArg == null) { invalidNamedArgument = splitShortNamedArg[1]; throw new ArgumentDoesNotExistException( argumentDoesNotExistMessage(invalidNamedArgument)); } } else { for (int k = 0; k < splitShortNamedArg[1].length(); k++) { NamedArgument tempArg = getNamedArgument(splitShortNamedArg[1].charAt(k)); if (tempArg == null) { invalidNamedArgument = Character.toString(splitShortNamedArg[1].charAt(k)); throw new ArgumentDoesNotExistException( argumentDoesNotExistMessage(invalidNamedArgument)); } } } } } }
/** @return Expr */ Expr read() { try { while (_tokens.nextToken() != _tokens.TT_EOF) { if (_tokens.ttype == -2) { Numeral a = new Numeral(_tokens.nval); return a; } else if (_tokens.ttype == -3) { String a = new String(_tokens.sval); return new Symbol(a); } else if (_tokens.ttype == (int) '(') { _tokens.nextToken(); String s; if (_tokens.ttype == -3) { s = _tokens.sval; } else { s = Character.toString((char) _tokens.ttype); } System.out.println("operator: " + s); return Combination.create(s, getOperands()); } } } catch (IOException e) { System.err.println("error: " + e.getMessage()); System.exit(1); } System.out.println("end of file reached"); return null; }
/** Ensures an arc's label is indeed printable (dot uses US-ASCII). */ private static String printableLabel(int label) { if (label >= 0x20 && label <= 0x7d) { return Character.toString((char) label); } else { return "0x" + Integer.toHexString(label); } }
/** * finds all possible separation chars * * @param lineWithAttributes * @return */ protected HashMap<String, Integer> getSeparationCandidates(String lineWithAttributes) { HashMap<String, Integer> result = new HashMap<>(); String s; for (char c : lineWithAttributes.toCharArray()) { s = Character.toString(c); Map.add(result, s, 1); } return result; }
private static void findMines(int r, int c) { for (int x = 0; x < r; x++) { for (int y = 0; y < c; y++) { if (currentMap[x][y] == '*') printedMap[x][y] = Character.toString(currentMap[x][y]); else printedMap[x][y] = countSurrounding(x, y, r, c); } } }
protected final String getQuoteCharacter(TableDefinition tableDefinition) { String quoteCharVal = tableDefinition.getProperty("quotechar", this.getDefaultQuoteCharVal()); if (quoteCharVal.equals("")) { return ""; } else { return Character.toString((char) Integer.valueOf(quoteCharVal).intValue()); } }
/* this method draws a board(not the screen). if the first parameter is true, an example board (filled with numbers) is drawn. false draws a board filled with moves[] */ public static void drawBoard(boolean example, char[] moves) { for (int i = 0; i < 9; i++) { System.out.print(example ? i + 1 : Character.toString(moves[i])); if (i == 2 || i == 5) { System.out.println(); System.out.println("---------"); } else if (i != 8) System.out.print(" | "); } }
/** * Outputs this <code>State</code> as though it came from the text input file. * * @return a <code>String</code> describing this <code>State</code>. */ public String toString() { return STATE + " " + Integer.toString(index) + " " + Character.toString(c) + " " + Integer.toString(qtrue) + " " + Integer.toString(qfalse); }
public static String getRandomPwd() { Random rd = new Random(); String n = ""; int getNum; do { getNum = Math.abs(rd.nextInt()) % 10 + 48; // 产生数字0-9的随机数 // getNum = Math.abs(rd.nextInt())%26 + 97;//产生字母a-z的随机数 char num1 = (char) getNum; String dn = Character.toString(num1); n += dn; } while (n.length() < 8); return n; }
private boolean asciiEqual(String[] letterToFindarray, String[] letterarray, int stepcount) { char m = letterToFindarray[stepcount].charAt(0); int o = (int) m; char n = letterarray[stepcount].charAt(0); int p = (int) n; if (o < 95) { // nagy betűt keresek és kis betű a keresendőben p = p - 32; } else { //// kis betűt keresek és nagy betű a keresendőben p = p + 32; } n = (char) p; String backToString = Character.toString(n); return letterToFindarray[stepcount].equals(backToString); }
/** * This util method is used to retrieve the string tokens resides in a particular udt parameter. * * @param param Name of the parameter * @return */ public static Queue<String> getTokens(String param) { boolean isString = false; Queue<String> tokens = new LinkedBlockingQueue<String>(); char[] chars = param.toCharArray(); StringBuilder columnName = new StringBuilder(); for (int i = 0; i < chars.length; i++) { Character c = chars[i]; if (!".".equals(c.toString()) && !"[".equals(c.toString()) && !"]".equals(c.toString())) { isString = true; columnName.append(c.toString()); if (i == chars.length - 1) { tokens.add(columnName.toString()); } } else { if (isString) { tokens.add(columnName.toString()); columnName = new StringBuilder(); isString = false; } tokens.add(c.toString()); } } return tokens; }
// Initialize Board public void init() { // Create cells and handlers cells = new JTextField[gameBoard.boardSize * gameBoard.boardSize + 1]; // Redraw Panel boardPanel.removeAll(); boardPanel.setLayout(new GridLayout(gameBoard.boardSize, gameBoard.boardSize)); // Set layout JTextFilter TextFilter = new JTextFilter(3); JTextDocumentListener JTextDocFilter = new JTextDocumentListener(); for (int i = 1; i <= gameBoard.boardSize * gameBoard.boardSize; i++) { cells[i] = new JTextField(); ((AbstractDocument) cells[i].getDocument()).setDocumentFilter(TextFilter); ((AbstractDocument) cells[i].getDocument()).addDocumentListener(JTextDocFilter); ((AbstractDocument) cells[i].getDocument()).putProperty("index", i); cells[i].setHorizontalAlignment(JTextField.CENTER); cells[i].setFont(new Font("Agency FB", Font.BOLD, 24)); // Add elements to the grid content pane boardPanel.add(cells[i]); } // Initialize booleans gameOver = false; // Clear Board for (int i = 1; i <= (gameBoard.boardSize * gameBoard.boardSize); i++) { String ch = Integer.toString(this.gameBoard.cells[i]); char chr = '-'; if (ch.compareTo("0") == 0 || ch == Character.toString(chr)) { cells[i].setText(""); } else { cells[i].setText(ch); cells[i].setBackground(Color.lightGray); } } // gameBoard.out(); setVisible(true); this.boardPanel.repaint(); this.gameTimer.reset(); jButtonSOLVE.setEnabled(true); }
public static ArrayList<String> validateSamplesDirectoryStructureIdentifyVersions( String samplesDirPath, ArrayList<String> versionArr) { String samplesDir[] = getDirectoryNames(samplesDirPath); StringBuilder builder = new StringBuilder(); ArrayList<String> tempArr = new ArrayList<String>(); Pattern numeric = Pattern.compile("[0-9_.-]"); for (String dir : samplesDir) { for (int item = dir.length() - 1; item >= 0; item--) { char singleChar = dir.charAt(item); Matcher matcher = numeric.matcher(Character.toString(singleChar)); // Find all matches if (matcher.find()) { // Get the matching string builder.append(singleChar); } else { if (builder.length() > 1) { tempArr.add(builder.toString()); builder.setLength(0); } else { builder.setLength(0); } } if (item == 0 && builder.length() != 0) { tempArr.add(builder.toString()); builder.setLength(0); } } int max; int previousMax = 0; String[] version = new String[1]; for (String element : tempArr) { max = element.length(); if (max > previousMax) { previousMax = max; version[0] = element; } } if (version[0] != null) { if (version[0].length() >= 2) { versionArr.add(dir); } } tempArr.clear(); } return versionArr; }
private Map<Character, Double> normalizeSymbolMap(Map<Character, Double> letterFrequency) { Double freq; Double mostFrequent = new Double(0); Character textCharacter; Set symbolsInMap = letterFrequency.entrySet(); Iterator iterateSymbols = symbolsInMap.iterator(); while (iterateSymbols.hasNext()) { Map.Entry symbolEntries = (Map.Entry) iterateSymbols.next(); textCharacter = (Character) symbolEntries.getKey(); freq = letterFrequency.get(textCharacter); letterFrequency.put(textCharacter, (freq / text.length())); if (freq != null && freq > mostFrequent) { mostFrequent = freq; mostFrequentLetter = textCharacter.toString(); } } mostFrequentLetterFrequency = mostFrequent / text.length(); return letterFrequency; }
private ArrayList<String> getPositionalArgs(String[] args) { ArrayList<String> posArgList = new ArrayList<String>(); for (int i = 0; i < args.length; i++) { // going through args from CLI if (!args[i].startsWith("-") && i == 0) { // test if the first arg is a positional arg posArgList.add(args[i]); } else if (!args[i].startsWith("-")) { // arg from CLI doesn't have a dash if (!args[i - 1].startsWith( "-")) { // if the one before it doesn't have a dash, then it's a pos arg posArgList.add(args[i]); } else { String[] tempNamedArg = new String[2]; if (args[i - 1].startsWith("--")) { tempNamedArg = args[i - 1].split("--"); for (int j = 0; j < namedArgumentList.size(); j++) { // g NamedArgument currentNamedArg = namedArgumentList.get(j); if (currentNamedArg.getName().equals(tempNamedArg[1])) { if (currentNamedArg.getType().equals("boolean")) { // to pos args posArgList.add(args[i]); } } } } else { tempNamedArg = args[i - 1].split("-"); if (tempNamedArg[1].length() == 1) { for (int j = 0; j < namedArgumentList.size(); j++) { NamedArgument currentNamedArg = namedArgumentList.get(j); if (Character.toString(currentNamedArg.getShortFormName()) .equals(tempNamedArg[1])) { if (currentNamedArg.getType().equals("boolean")) { posArgList.add(args[i]); } } } } else { posArgList.add(args[i]); } } } } } return posArgList; }
@EventHandler public void onTick(TickEvent event) { if (!bot.hasSpawned() || !bot.isConnected()) return; if (tickDelay > 0) { tickDelay--; return; } MainPlayerEntity player = bot.getPlayer(); if (player == null || !bot.hasSpawned() || spamMessage == null) return; if (nextMessage > 0) { nextMessage--; return; } try { String message = spamMessage; MessageFormatter formatter = new MessageFormatter(); synchronized (bots) { if (bots.size() > 0) { DarkBotMCSpambot bot = bots.get(++nextBot >= bots.size() ? nextBot = 0 : nextBot); if (bot != null && bot.bot != null && bot.bot.getSession() != null) formatter.setVariable("bot", bot.bot.getSession().getUsername()); } } if (spamList.length > 0) { formatter.setVariable( "spamlist", spamList[++nextSpamList >= spamList.length ? nextSpamList = 0 : nextSpamList]); } formatter.setVariable("rnd", Util.generateRandomString(15 + random.nextInt(6))); formatter.setVariable( "msg", Character.toString( msgChars[++nextMsgChar >= msgChars.length ? nextMsgChar = 0 : nextMsgChar])); message = formatter.format(message); bot.say(message); } catch (Exception e) { e.printStackTrace(); } nextMessage = messageDelay; }
/** * Calculates the phone list for a given word. If a phone list cannot be determined, <code>null * </code> is returned. This particular implementation ignores the part of speech. * * @param word the word to find * @param partOfSpeech the part of speech. * @return the list of phones for word or <code>null</code> */ public String[] getPhones(String word, String partOfSpeech) { if (RiTa.PRINT_LTS_INFO && !RiTa.SILENT) System.out.println("[INFO] Using LTS for '" + word + "'"); List phoneList = new ArrayList(); State currentState; Integer startIndex; int stateIndex; char c; // Create "000#word#000" char[] full_buff = getFullBuff(word); // For each character in the word, create a WINDOW_SIZE // context on each size of the character, and then ask the // state machine what's next. Its magic for (int pos = 0; pos < word.length(); pos++) { for (int i = 0; i < WINDOW_SIZE; i++) { fval_buff[i] = full_buff[pos + i]; fval_buff[i + WINDOW_SIZE] = full_buff[i + pos + 1 + WINDOW_SIZE]; } c = word.charAt(pos); startIndex = (Integer) letterIndex.get(Character.toString(c)); if (startIndex == null) { continue; } stateIndex = startIndex.intValue(); currentState = getState(stateIndex); while (!(currentState instanceof FinalState)) { stateIndex = ((DecisionState) currentState).getNextState(fval_buff); currentState = getState(stateIndex); } ((FinalState) currentState).append((ArrayList) phoneList); // RiTa.out("phoneList: "+phoneList); } return (String[]) phoneList.toArray(new String[0]); }
private void setShortFormNamedArgValues(String[] args) throws NumberFormatException { for (int i = 0; i < args.length; i++) { String[] tempNamedArg = new String[2]; if (args[i].startsWith("-")) { tempNamedArg = args[i].split("-"); for (int k = 0; k < namedArgumentList.size(); k++) { incorrectDataTypeIndex = k; incorrectArgumentType = "named"; NamedArgument currentNamedArg = namedArgumentList.get(k); if (tempNamedArg[1].length() == 1) { // single char if (Character.toString(currentNamedArg.getShortFormName()).equals(tempNamedArg[1])) { if (!currentNamedArg.getType().equals("boolean")) { incorrectArgValueForSpecifiedDataType = args[i + 1]; if (currentNamedArg.getType().equals("integer")) { int argValue = Integer.parseInt(args[i + 1]); currentNamedArg.setValue(args[i + 1]); } else if (currentNamedArg.getType().equals("float")) { float argValue = Float.parseFloat(args[i + 1]); currentNamedArg.setValue(args[i + 1]); } else if (currentNamedArg.getType().equals("string")) { currentNamedArg.setValue(args[i + 1]); } } else { currentNamedArg.setValue("true"); } } } else { // multiple flags in one specification for (int j = 0; j < tempNamedArg[1].length(); j++) { if (currentNamedArg.getShortFormName() == tempNamedArg[1].charAt(j)) { currentNamedArg.setValue("true"); } } } } } } }
/** * Writes the r-field of an instruction in the form "l<I>reg</I>r", where l and r are the bracket * characters to use. * * @param leftbracket the character to print before the register. * @param r the number of the register. * @param rightbracket the character to print after the register. */ private void writeR(char leftbracket, int r, char rightbracket) { asmWrite(Character.toString(leftbracket)); asmWrite(Machine.intToReg[r].toString()); asmWrite(Character.toString(rightbracket)); }
public boolean readSrecCode(String fName) { FileInputStream fis = null; srec = new short[SREC_MAX_LINES][PKT_PAYLOAD_SIZE]; numLines = 1; numPkts = 0; try { BufferedReader dis = new BufferedReader(new InputStreamReader(fis = new FileInputStream(fName))); System.out.println("--------------------------------------------------"); System.out.println("Reading file: " + fName); // WARNING int curByte = 0; // 16; // account for S0 line which is not parsed while (true) { char bline[] = dis.readLine().toUpperCase().toCharArray(); if (bline[1] == '1') { numLines++; if (bline.length > SREC_MAX_LINE_LEN) { System.out.println("ERROR: SREC Read: Too many byes on line: " + numLines); return false; } // srec length int length = Integer.parseInt(Character.toString(bline[2]) + Character.toString(bline[3]), 16) - 3; // data for (int i = 0, j = 8; i < length; i++, j += 2) { if (curByte >= PKT_PAYLOAD_SIZE) { numPkts++; curByte = 0; } srec[numPkts][curByte++] = (short) Integer.parseInt( Character.toString(bline[j]) + Character.toString(bline[j + 1]), 16); imgSize++; } } else if (bline[1] == '2') { numLines++; if (bline.length > SREC_MAX_LINE_LEN) { System.out.println("ERROR: SREC Read: Too many byes on line: " + numLines); return false; } // srec length int length = Integer.parseInt(Character.toString(bline[2]) + Character.toString(bline[3]), 16) - 4; // data for (int i = 0, j = 10; i < length; i++, j += 2) { if (curByte >= PKT_PAYLOAD_SIZE) { numPkts++; curByte = 0; } srec[numPkts][curByte++] = (short) Integer.parseInt( Character.toString(bline[j]) + Character.toString(bline[j + 1]), 16); imgSize++; } } } } catch (FileNotFoundException e) { System.out.println("ERROR: (SREC Read) " + e); return false; } catch (Exception e) { numPgs = (short) (((imgSize - 1) / BYTES_PER_PAGE) + 1); System.out.println( "Read END: (Lines=" + numLines + ",Pages=" + numPgs + ",Pkts=" + numPkts + ",Size=" + imgSize + ")"); System.out.println("--------------------------------------------------"); } try { if (fis != null) fis.close(); } catch (Exception e) { e.printStackTrace(); } return true; }
private void blockDataFile(DataFile dataFile, RetailerSite retailerSite, int blockSize) { File filePath = null; PreprocessorHandlerContext context = null; try { dataFile.setStartTime(new Date()); // TODO srfisk 2012/07/31 Only split CSV, might split images zip // when they are very large. if (dataFile.getImportType().compareTo(ImportType.images_zip.getTableName()) != 0) { filePath = configurationService.getFileSystem().getDirectory(dataFile.getFilePath(), true); TableDefinition tableDefinition = this.getTableDefinition(retailerSite, dataFile); ImportType importType = ImportType.getTypeFromTableName(dataFile.getImportType()); String encoding = this.getDataImportEncoding(tableDefinition, filePath); String separator = Character.toString( (char) Integer.valueOf(tableDefinition.getProperty("separator", "9")).intValue()); String quotechar = this.getQuoteCharacter(tableDefinition); int blockCount = 1; int totalRowCount = 0; boolean noSplit = false; boolean done = false; context = this.createContext( retailerSite, dataFile, filePath, tableDefinition, encoding, separator, quotechar); while (!done) { context.startWriters(blockCount); context.writeHeader(); Row row = null; while ((row = context.reader.readNext()) != null && context.rowCount < blockSize) { context.writeRow(row); } context.closeWriters(); blockCount++; if (context.isEmptyBlock()) { done = true; continue; } context.createDataFiles( retailerSite, importType.getTableName(), importType.getPriority()); context.inQueueDataFiles(); } dataFile.setHost(null); dataFile.setNumRows(totalRowCount); if (!noSplit) { dataFile.setEndDate(new Date()); dataFile.setEndTime(new Date()); dataFile.setStatus(this.getEndStatus()); } else { dataFile.setStatus(FileStatus.IN_QUEUE); } } else { dataFile.setHost(null); dataFile.setStatus(FileStatus.IN_QUEUE); } dataFileRepository.update(dataFile); } catch (IOException e) { logger.error(String.format("Failed to reading %s data file", filePath), e); dataFile.setStatus(FileStatus.ERROR_READ); dataFileRepository.update(dataFile); } catch (CSVReaderException e) { logger.error(String.format("Failed to reading %s data file", filePath), e); dataFile.setStatus(FileStatus.ERROR_WRITE); dataFileRepository.update(dataFile); } catch (CSVWriterException e) { logger.error(String.format("Failed to reading %s data file", filePath), e); dataFile.setStatus(FileStatus.ERROR_READ); dataFileRepository.update(dataFile); } catch (Throwable t) { logger.error(String.format("Failed to unknown %s data file", filePath), t); dataFile.setStatus(FileStatus.ERROR_UNKNOWN); dataFileRepository.update(dataFile); } finally { if (context != null) { try { context.cleanup(); } catch (IOException e) { // Ignore, did everything we could to close it. } } } }
private String firstCharToUpperCase(String name) { return Character.toString(Character.toUpperCase(name.charAt(0))) + name.substring(1); }
public static void identifyDuplicateJars( List<File> jarFileListInDistribution, File distributionVersion, HashSet<String> distributionDuplicateJarList, ArrayList<String> unidentifiedVersionJars) { Iterator<File> itJarList = jarFileListInDistribution.iterator(); ArrayList<String> tempArr = new ArrayList<String>(); ArrayList<File> pathListForAddedJarToJarVersions = new ArrayList<File>(); HashMap<String, String> jarVersions = new HashMap<String, String>(); StringBuilder builder = new StringBuilder(); Pattern numeric = Pattern.compile("[^0-9_.-]"); Pattern nonNumeric = Pattern.compile("[a-zA-Z]"); while (itJarList.hasNext()) { File jarFilePath = itJarList.next(); String jarName = (jarFilePath).getName(); if (!jarFilePath .getAbsolutePath() .contains( distributionVersion.getName().replaceAll(".zip", "") + File.separator + TEMP_DIRECTORY + File.separator)) { for (int letter = jarName.length() - 1; letter >= 0; letter--) { char singleChar = jarName.charAt(letter); Matcher matcher = numeric.matcher(Character.toString(singleChar)); // Find all matches if (!matcher.find()) { // Get the matching string builder.append(singleChar); } else if (nonNumeric.matcher(Character.toString(singleChar)).find()) { if (builder.length() > 1) { tempArr.add(builder.toString()); builder.setLength(0); } else { builder.setLength(0); } } } int max; int previousMax = 0; String[] version = new String[1]; for (String element : tempArr) { max = element.length(); if (max > previousMax) { previousMax = max; version[0] = element; } } tempArr.clear(); if (version[0] != null) { String jar = jarName.split((StringUtils.reverse(version[0])))[0]; if (jar.length() >= 2) { if (jarVersions.containsKey(jar)) { if (!jarVersions.get(jar).equals(jarName.split(jar)[1])) { // removing patches - plugins duplication if (distributionDuplicateJarList.toString().contains(jarName)) { for (String itemDistributionDuplicateJarList : distributionDuplicateJarList) { if (itemDistributionDuplicateJarList.contains(jarName) && (itemDistributionDuplicateJarList.contains("patches") || itemDistributionDuplicateJarList.contains("plugins"))) { if (!(jarFilePath.getAbsolutePath().contains("patches") || jarFilePath.getAbsolutePath().contains("plugins"))) { distributionDuplicateJarList.add(jarFilePath.getAbsolutePath()); } } } } else { distributionDuplicateJarList.add(jarFilePath.getAbsolutePath()); } for (File pathListForAddedJarToJarVersion : pathListForAddedJarToJarVersions) { String path = pathListForAddedJarToJarVersion.toString(); if (path.contains(jar + jarVersions.get(jar))) { distributionDuplicateJarList.add(path); break; } } } } else { jarVersions.put(jar, jarName.split(jar)[1]); pathListForAddedJarToJarVersions.add(jarFilePath); } } else { log.info("Unable to identify the version " + jar); unidentifiedVersionJars.add(jarFilePath.getAbsolutePath()); } } else { jarVersions.put(jarName, null); pathListForAddedJarToJarVersions.add(jarFilePath); } } } }
/** * Writes the given char in XML format. <br> * <b>Note: Java specific type</b> * * @param c to write */ public void writeChar(char c) { this.writeValue(CharacterStrategy.NAME, Character.toString(c)); }
public void nextLex() throws ParseException, IOException { token = ""; char currentChar; int currentCharAsInt; skipComments(); skipWhiteSpace(); try { currentCharAsInt = input.read(); } catch (IOException e1) { throw new ParseException(0); } currentChar = (char) currentCharAsInt; if (currentCharAsInt == -1 || currentCharAsInt == EOF_RETURN) { token = "<eof>"; tokenType = endOfInput; } else if (Character.isDigit(currentChar)) { tokenType = intToken; // by default token = token + currentChar; while (true) { try { currentChar = (char) input.read(); } catch (IOException e) { throw new ParseException(0); } if (Character.isDigit(currentChar)) { token = token + currentChar; } else if (currentChar == '.') { if (token.indexOf('.') == -1) { tokenType = realToken; token = token + currentChar; } else { try { input.unread(currentChar); } catch (IOException e) { throw new ParseException(0); } break; } } else { try { input.unread(currentChar); } catch (IOException e) { throw new ParseException(0); } break; } } } else if (Character.isLetter(currentChar)) { token = token + currentChar; while (true) { try { currentChar = (char) input.read(); } catch (IOException e) { throw new ParseException(0); } if (Character.isLetterOrDigit(currentChar)) { token = token + currentChar; } else { input.unread(currentChar); tokenType = identifierToken; for (String current : keywords) { if (match(current)) { tokenType = keywordToken; break; } } break; } } } else { switch (currentChar) { case '"': tokenType = stringToken; while (true) { try { currentCharAsInt = input.read(); currentChar = (char) currentCharAsInt; } catch (IOException e) { throw new ParseException(0); } if (currentCharAsInt == -1 || currentCharAsInt == EOF_RETURN) { throw new ParseException(2); } else if (currentChar == '"') { break; } token = token + currentChar; } break; case '<': tokenType = otherToken; token = token + currentChar; char secondChar = (char) input.read(); if (secondChar == '<') { token = token + secondChar; break; } else { input.unread(secondChar); } case '>': case '=': case '!': tokenType = otherToken; if (currentChar != '<') { token = token + currentChar; } secondChar = (char) input.read(); if (secondChar == '=') { token = token + secondChar; break; } else { input.unread(secondChar); } break; default: token = Character.toString(currentChar); tokenType = otherToken; } } return; }