Wednesday, December 12, 2018
'Java Based Search Engine\r'
'ACKNOWLEDGMENT I  point thanks and gratitude to Mr. ââ¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦H. O. D computer science department, ââ¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦College for his encouraging  take  refuse and  focus in carrying  give a manner the   ask. I would  akin to express gratitude and indebtedness to Mrââ¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦, for his valuable advice and guidance without which this project would  non  sp devastation a penny seen the light of the day. I thank Mrââ¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦ , project guide , GSS for his insistence on good   computer  weapons platformmeing technique which  assistanted us to design and develop a successful model of an Chatting Tool. Nam   e CONTENTS 1.STUDY &   compendium PHASE 1. 1  psychiatric hospital 1. 1. 1  tar subscribe OF THE  labor 1. 1. 2 PROBLEM IN  lively  corpse 1. 1. 3 SOLUTION OF THESE PROBLEMS 1. 1. 4  mountain chain OF THE  labour 1. 1. 5 LIMITATIONS 1. 1. 6 HARDWARE &   collect SPECIFICATIONS 1. 1. 7 ORGANISATION PROFILE 2. PROJECT  compendium 1. STUDY OF THE SYSTEM 2. INPUT &  output signal 3.  motion  mental facultyS   deed WITH JUSTIFICATION 3. DESIGN PHASE 1.  entropyFLOW 2. UML  drawS 4.   motionuation PHASE 5.  shieldING 1. TYPES OF TESTING 1. COMPILING TEST 2. EXECUTION TEST 3. OUTPUT TEST 5. PROJECT CODING 6. OUTPUT SCREENS 7. CONCLUSION 8. BIBLOGRAPHYSTUDY PHASE INTRODUCTION: EXISTING SYSTEM With the advent of the Internet in the  outgoing decade,  inquiring for information in mixed formats has been rede comelyd by the internet  lookup  engines,  intimately of them   knowledge domain  found on information retrieval (IR)   rock techniques. IR-based  huntinging, which usu   all    in all(prenominal) in ally allows formulation of queries with multiple  rule books PROPOSED SYSTEM This Java  activity is basically a recursive  bill  goer. You  send packing search for files based on their file plant, their contents, or both in selected directory and as  wellspring as sub directories of the specified directory.rail manner locomotive is a pictorial  interlingual rendition of the well- cognise GREP utility, with an additional feature of traversing subdirectories. You  aro consumption specify which directory to start looking in, which files to search  finished, and what  excogitation to look for in the files. The  diverse fields  confront  tied(p)  facial gestures, like Global   busheledness Expression, ââ¬Ë locomotiveââ¬â¢ has not  sole(prenominal) the  in writing(p) interface,  hardly  in  both case a command- bloodline interface. This is  partful for quick searches through, say, a  breeding tree. Engine requires the Java 2 Platform, Standard  mutation versio   n 1. 4 or higher. SOLUTION OF THESE PROBLEMS in variable  chemical formulas  attri stille into all  bods of  school  school text-manipulation tasks.  fronting and search-and- stand in  ar among the     more than(prenominal)(prenominal) than  commonality  physical exercises,  exclusively  first- cosmic  train expressions  tramp  also be use to test for  certain conditions in a text file or  info stream. You   facultyiness use  veritable(a) expressions, for  precedent, as the basis for a short  weapons platform that  split ups  next mail from incoming spam. In this case, the  computer  classme might use a  unbroken expression to de terminal figureine whether the  depict of a k at a timen spammer appe atomic  itemize 18d in the ââ¬Å"From:ââ¬Â line of the email. Email  tense uping broadcasts, in fact, very often use  mending expressions for just this type of operation. SCOPE OF THE PROJECTEngine is a graphical version of the well-kn take in GREP utility, with an additional feature    of traversing subdirectories. The main aim of this project is to develop a java based recursive file  reclaimer. Engine is a graphical version of the well-known GREP utility, with an additional feature of traversing subdirectories LIMITATIONS Regular expressions tend to be easier to  relieve than they  atomic number 18 to  study. This is  slight of a  line if you   be the only  ane who ever  motifs to maintain the broadcast (or sed routine, or shell script, or what  fork up you),  entirely if   almost(prenominal)  comm building blocky  make to watch over it, the  sentence structure  mickle turn into more of a hitch than an aid.Ordinary macros (in  occurrence, editable macros  such as those generated by the major  denomination processors and editors) tend not to be as fast, as flexible, as portable, as concise, or as fault-tolerant as  timed expressions,  still they  deplete the advantage of  macrocosm much more readable;   final  giveide people with no programming  prickerground wha   tsoever  corporation usually make enough sense of a macro script to  miscellany it if the  essential arises. For   approximately jobs, such readability  for get outweigh all  different concerns.As with all things in computing, its largely a question of fitting the  creature to the job. HARDWARE &  softw atomic number 18 SPECIFICATIONS Environment: Java Run cartridge holder Environment version 1. 4 or better installed. Operating System:   both(prenominal) O. S. compatable with JVM Hard disk:10 GB  mainframe:PIII or higher ORGANIZATION PROFILE  towering SOFTWARE SOLUTIONS EMINENT TECHNOLOGIES (ET) is an IT Solution Provider for a dynamic environment w here business and  applied science strategies converge.Our  come along focuses on  unfermented ways of business  trust IT innovation and adoption  spell also leverage an organizations current IT assets. We work with large  orbiculate corporations and  saucily generation engineering companies â⬠to build  refreshed products or ser   vices and to implement prudent business and  applied science strategies in  at presents environment. EMINENTs  throw of expertise  embroils: Softwargon  victimization Services Engineering Services Systems Integration  guest Relationship  focussing Supply Chain Management Product Development Electronic CommerceConsulting IT Outsourcing We apply technology with innovation and responsibility to achieve  dickens  bighearted objectives: Effectively address the business issues our customers face today Generate  bleak opportunities that  exit help them  take a breather ahead in the future This  rise rests on: A strategy where we Architect, Integrate and Manage technology services and solutions â⬠we call it AIM for success. A  blue offshore development methodological analysis and reduced  look at on customer resources A focus on the use of reusable frameworks to  brook cost and time benefitsWe combine the best people, processes and technology to achieve  refined results consistently. We     offer up customers the advantages of: Speed: We understand the  instanteeance of timing, of  getting   in that location before the competition. A rich portfolio of reusable, modular frameworks helps jump start projects. Tried and tested methodology ensures that we follow a predictable, low-risk path to achieve results. Our  rail record is testimony to  interwoven projects delivered within and  still before schedule. Expertise: Our teams combine cutting  rim technology skills with rich domain expertise.Whats equally  eventful â⬠we sh atomic number 18 a strong customer predilection that  gist we actually start by   compensate to the customer. Were focused on coming up with solutions that  give ear customer requirements today and anticipate future needs. A Full Service Portfolio: We offer customers the advantage of  macrocosm able to Architect, Integrate and Manage technology services. This  designates that they can rely on  wholeness, fully  responsible source  or else of  fork    overing to integrate disparate multi-vendor solutions. Services: GSS is providing its services to Sain medicaments Pvt.Ltd, Grace drugs and pharmaceuticals Private  particular Alka Drugs and Pharmaceuticals Pvt Ltd to name just a  hardly a(prenominal) with out rich experience and expertise in  selective information Technology we are in the best  impersonate to provide software solutions to distinct business requirements. PROJECT ANALYSIS STUDY OF THE SYSTEM This application can be mainly divided into two modules:- ââ¬Â¢  exploiter Interface ââ¬Â¢ File Manipulation and filtering INPUT AND OUTPUT: User has to input the File Name or File Contents and he has to select the  pound or Directory in which searching has to be d nonpareil.Application will search for the files  coordinated with given criteria and shows the output in the text area of the application. PROCESS MODEL USED WITH JUSTIFICTION The model used here is a  lock MODEL. This Model demands a direct  go outation of  practi   ced risk at all stages of the project and if  decently applied it reduces risk before they become problematic,  hence it becomes easier to  cut through a project when  utilise this kind of model where in the end  user can evaluate the program at the end of  apiece stage and suggest modification if required.PROJECT DESIGN DATA FLOW DIAGRAM 0th  take 1st Level 2nd Level 2nd Level  tertiary Level UML DIAGRAMS USE CASE DIAGRAM [pic]  year DIAGRAM [pic] ACTIVITY DIAGRAM [pic] SEQUENCE DIAGRAM [pic] IMPLEMENTATION PHASE  mental facultyS: 1. COMPONENT THIS IS THE FRONT  final stage CONSOLE OF THE USER TO INTERACT WITH SEARCH ANALYZER. 2. TOOLBAR COORDINATIOR THIS MODULE HAS THE EMBEDED TOOLS WHICH ARE TO IMPLEMENT SEARCH. 3. MAP FINDER THIS MODULE IS MAPS THE SEARCH CORRESPONDING TO THE USERS QUERY. 4.  energetic STATUS FINDERTHIS IS THE DYNAMIC MODULE WHICH GIVES THE STATUS OF THE SEARCH . 5. GREP   composer GREP GENERATOR IS THE MAJOR MODULE ON WHICH THE SEARCH IS  make BASED ON REGULAR    EXPRESSIONS . OUTPUT SCREENS Engine view [pic] Browse [pic]  essay [pic] Help [pic]  fault [pic] PROJECT CODING CODE EXPLANATION Regular expressions simplify  example- jibing  reckon Discover the elegance of  uniform expressions in text-processing scenarios that involve pattern  snatching  schoolbook processing often involves matching text against a pattern.Although Javas  nature and assorted string  ground leveles offer subordinate pattern-matching support, that support commonly leads to complex code. To help you  compile simpler pattern-matching code, Java provides  well-ordered expressions with java. util. regex  software program. Text processing  much requires code to match text against patterns. That capability makes  practicable text searches, email header validation, custom text creation from generic text (e. g. , ââ¬Å"Dear Mr. Chakradharââ¬Â  instead of ââ¬Å"Dear Customerââ¬Â), and so on. Java supports pattern matching via its  acknowledgment and assorted string  s   omaes.Because that  low-level support commonly leads to complex pattern-matching code, Java also offers  stiff expressions to help you  redeem simpler code. After introducing regular expression terminology, the java. util. regex  piece of grounds classes, and a program that demonstrates regular expression constructs, I explore m  individually of the regular expression constructs that the Pattern class supports. I also  rise the methods comprising Pattern and  different java. util. regex classes. A practical application of regular expressions concludes my discussion.Regular expressions long history begins in the  hypothetical computer science fields of automata theory and  noble  spoken communication theory. That history continues to Unix and  different operating systems, where regular expressions are often used in Unix and Unix-like utilities: examples include awk (a programming language that enables sophisticated text analysis and manipulation-named  subsequently its creators, Aho,    Weinberger, and Kernighan), emacs (a developers editor), and grep (a program that matches regular expressions in  wizard or more text files and stands for global regular expression print).Regular expressions trace  rearwards to the work of an American mathematician by the name of Stephen Kleene ( genius of the most influential  bets in the development of theoretical computer science) who  unquestionable regular expressions as a note for describing what he called ââ¬Å"the algebra of regular sets. ââ¬Â His work eventually found its way into  slightly early efforts with computational search algorithms, and from there to some of the earliest text-manipulation  official documents on the Unix platform (including ed and grep). In the context of computer searches, the ââ¬Å"*ââ¬Â is formally known as a ââ¬Å"Kleene star. ââ¬Å"A regular expression, also known as a regex or regexp, is a string whose pattern (template) describes a set of  draw. The pattern determines what strings    belong to the set, and consists of literal characters and meta characters, characters that have special  convey instead of a literal  heart. The process of searching text to identify matchesââ¬strings that match a regexs patternââ¬is pattern matching. Javas java. util. regex package supports pattern matching via its Pattern, marriage broker, and PatternSyntaxException classes: 1. Pattern objects, also known as patterns, are compiled regexes 2.Matcher objects, or matchers, are engines that interpret patterns to locate matches in character sequences, objects whose classes implement the java. lang. CharSequence interface and serve as text sources 3. PatternSyntaxException objects describe illegal regex patterns Code for main pull aheaddow package jog. engine;  conditional relation java. awt. *;  momenteeee java. awt. event. *;  outcome java. io. *;  logical implication java. net. universal resource locator; import java. util. prefs. *; import java. util. regex. *; import javax. swi   ng. *; import javax. swing. filechooser. FileFilter; import jog. engine. *;  populace class MainWindow  gallops JFrame implements ActionListener, File seekListener { rotected Preferences preferences; saved JTextField lookInField;   protect JTextField filePatternField;  protect JTextField searchForField;  defend JTextField  turn offField;  defend JCheckBox includeSubCheckBox;  defend JList resultList;  defend RunSearch  break offner;  protect J barelyton browseButton; protected JButton helpButton; protected JButton startButton; protected JButton stopButton; protected JButton closeButton; protected JLabel  office; protected JPanel cardPanel; protected CardLayout cardLayout;  hush-hush boolean stopFlag;   familiar MainWindow() { super(Bundle. get line(ââ¬Å"AppTitleââ¬Â)); addWindowListener( bracing WindowAdapter()  humankind  neutralise windowClosing(WindowEvent event) { handleClose(); } }); preferences = Preferences. userRoot(). node(ââ¬Å"com/bluemarsh/jrgrepââ¬Â); Container    pane = getContentPane(); GridBagLayout gb =   parvenuefangled GridBagLayout(); pane. setLayout(gb); GridBagConstraints gc = new GridBagConstraints(); gc. insets = new Insets(3, 3, 3, 3); JLabel  enounce = new JLabel(Bundle. get ar trim(ââ¬Å"lookInLabelââ¬Â)); gc.  lynchpin = GridBagConstraints.  eastside; gb. setConstraints(label, gc); pane. add(label);  trace s = preferences. get(ââ¬Å"lookInââ¬Â, ââ¬Å"ââ¬Â); lookInField = new JTextField(s, 20); gc.   cast anchorperson = GridBagConstraints.  western United States; gc.  film = GridBagConstraints.HORIZONTAL; gc. weightx = 1. 0; gb. setConstraints(lookInField, gc); pane. add(lookInField); browseButton = new JButton(Bundle. get tie(ââ¬Å"browseLabelââ¬Â)); browseButton. addActionListener(this); gc. anchor = GridBagConstraints.  union; gc. gridwidth = GridBagConstraints.  sleep; gc.  forgather = GridBagConstraints. n nonpareil; gc. weightx = 0. 0; gb. setConstraints(browseButton, gc); pane. add(browseButton); label =    new JLabel(Bundle. get mountain chain(ââ¬Å"filePatternLabelââ¬Â)); gc. anchor = GridBagConstraints.  eastward; gc. gridwidth = 1; gb. setConstraints(label, gc); pane. add(label); s = preferences. get(ââ¬Å"filterââ¬Â, ââ¬Å"ââ¬Â); ilePatternField = new JTextField(s, 20); gc. anchor = GridBagConstraints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. gridwidth = GridBagConstraints.  congeneric; gc. weightx = 1. 0; gb. setConstraints(filePatternField, gc); pane. add(filePatternField); Comp int  gum tree = Box. createGlue(); gc. anchor = GridBagConstraints. CENTER; gc. fill = GridBagConstraints. NONE; gc. gridwidth = GridBagConstraints.  equilibrium; gc. weightx = 0. 0; gb. setConstraints(glue, gc); pane. add(glue); label = new JLabel(Bundle. get  throw off(ââ¬Å"searchForLabelââ¬Â)); gc. anchor = GridBagConstraints. EAST; gc. fill = GridBagConstraints.NONE; gc. gridwidth = 1; gb. setConstraints(label, gc); pane. add(label); s = preferences. get(ââ¬Å"searchForà   ¢â¬Â, ââ¬Å"ââ¬Â); searchForField = new JTextField(s, 20); gc. anchor = GridBagConstraints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. gridwidth = GridBagConstraints. RELATIVE; gc. weightx = 1. 0; gb. setConstraints(searchForField, gc); pane. add(searchForField); helpButton = new JButton(Bundle. get power train(ââ¬Å"helpLabelââ¬Â)); helpButton. addActionListener(this); gc. anchor = GridBagConstraints. CENTER; gc. fill = GridBagConstraints. NONE; gc. gridwidth = GridBagConstraints.  equilibrium; gc. weightx = 0. 0; gb. etConstraints(helpButton, gc); pane. add(helpButton); label = new JLabel(Bundle. get drawing string(ââ¬Å" proveLabelââ¬Â)); gc. anchor = GridBagConstraints. EAST; gc. gridwidth = 1; gb. setConstraints(label, gc); pane. add(label); s = preferences. get(ââ¬Å"excludeââ¬Â, ââ¬Å"ââ¬Â); excludeField = new JTextField(s, 20); gc. anchor = GridBagConstraints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. gridwidth = GridBagConstraints.    RELATIVE; gc. weightx = 1. 0; gb. setConstraints(excludeField, gc); pane. add(excludeField); glue = Box. createGlue(); gc. anchor = GridBagConstraints. CENTER; gc. fill = GridBagConstraints. NONE; gc. ridwidth = GridBagConstraints. REMAINDER; gc. weightx = 0. 0; gb. setConstraints(glue, gc); pane. add(glue); includeSubCheckBox = new JCheckBox( Bundle. getString(ââ¬Å"includeSubDirLabelââ¬Â),   material(a)); includeSubCheckBox. setSelected(preferences. getBoolean( ââ¬Å"recurseââ¬Â,  square(a))); gc. anchor = GridBagConstraints. WEST; gb. setConstraints(includeSubCheckBox, gc); pane. add(includeSubCheckBox); startButton = new JButton( Bundle. getString(ââ¬Å"startSearchLabelââ¬Â)); startButton. addActionListener(this); gc. gridwidth = 1; gb. setConstraints(startButton, gc); pane. add(startButton); status=new JLabel(ââ¬Å"ââ¬Â); Color c=new Color(240,100,100); tatus. setForeground(c); gc. gridwidth = 1; gb. setConstraints(status, gc); pane. add(status); stopButton = n   ew JButton(Bundle. getString(ââ¬Å"stopLabelââ¬Â)); stopButton. setEnabled( foolish); stopButton. addActionListener(this); gc. anchor = GridBagConstraints. CENTER; gc. gridwidth = GridBagConstraints. RELATIVE; gb. setConstraints(stopButton, gc); pane. add(stopButton); closeButton = new JButton(Bundle. getString(ââ¬Å"closeLabelââ¬Â)); closeButton. addActionListener(this); gc. gridwidth = GridBagConstraints. REMAINDER; gb. setConstraints(closeButton, gc); pane. add(closeButton); resultList = new JList(new ResultsListModel());JScrollPane scroller = new JScrollPane(resultList); cardPanel = new JPanel(new CardLayout()); cardLayout = (CardLayout) cardPanel. getLayout(); cardPanel. add(scroller, ââ¬Å" angle of inclinationââ¬Â); gc. gridwidth = GridBagConstraints. REMAINDER; gc. grid aggrandisement = GridBagConstraints. REMAINDER; gc. fill = GridBagConstraints. BOTH; gc. weightx = 1. 0; gc.  telltale(a) = 1. 0; gb. setConstraints(cardPanel, gc); pane. add(cardPanel); int width    = preferences. getInt(ââ¬Å"windowWidthââ¬Â, 0); int height = preferences. getInt(ââ¬Å"windowHeightââ¬Â, 0); if (width == 0 && height == 0) { pack(); } else { setSize(width, height); } int top = preferences. getInt(ââ¬Å"windowTopââ¬Â, 100); nt left = preferences. getInt(ââ¬Å"windowLeftââ¬Â, 100); setLocation(left, top); stopFlag=false; }  domain  repress actionPerformed(ActionEvent event) { JButton  furtherton = (JButton) event. getSource(); //System. out. println(ââ¬Å"action ââ¬Å"+button); if (button == closeButton) { handleClose(); } else if (button == browseButton) { handleBrowse(); } else if (button == startButton) { status. setText(ââ¬Å"Search Startedââ¬Â); //System. out. println(ââ¬Å"Search startedââ¬Â); startSearch(); } else if (button == helpButton) { displayHelp(); } else if (button == stopButton) { //System. out. println(ââ¬Å"Search stoppedââ¬Â); stopButton. setEnabled(false);  draw outner. stop(); stopFlag= full-strength; /   int  seem=((ListModel)resultList. getModel()). getSize(); //status. setText(ââ¬Å"Search  halt ââ¬Å"+count+ââ¬Â Files Foundââ¬Â); } } protected  head off displayHelp() { if (cardPanel. getComponentCount() < 2) { URL helpUrl = Bundle. getResource(ââ¬Å"helpFileââ¬Â);  get  rule book { JEditorPane editor = new JEditorPane(helpUrl); editor. setEditable(false); JScrollPane scroller = new JScrollPane(editor); cardPanel. add(scroller, ââ¬Å"helpââ¬Â); }  thumb (IOException ioe) { searchFailed(ioe);  reproduction; } } cardLayout. show(cardPanel, ââ¬Å"helpââ¬Â); }  everyday   vapidify fileFound(FileFoundEvent event) { ResultsListModel model = (ResultsListModel) resultList. etModel(); model. addElement(event. getFile()); } protected  forfend handleBrowse() { String dirStr = lookInField. getText(); JFileChooser fc; if (dirStr. equals(ââ¬Å"ââ¬Â)) { String lastdir = preferences. get(ââ¬Å"lastdirââ¬Â,  visionary); if (lastdir ==  fruitless || lastdir.  distance   () == 0) { lastdir = System. getProperty(ââ¬Å"user. dirââ¬Â); } fc = new JFileChooser(lastdir); } else { fc = new JFileChooser(dirStr); } fc. setFileSelectionMode(JFileChooser. DIRECTORIES_ONLY); if (fc. showOpenDialog(this) ! = JFileChooser. CANCEL_OPTION) { File dir = fc. getSelectedFile(); String path = dir. getPath(); lookInField. setText(path); references. put(ââ¬Å"lastdirââ¬Â, path); } } protected  annul handleClose() { preferences. putInt(ââ¬Å"windowTopââ¬Â, getY()); preferences. putInt(ââ¬Å"windowLeftââ¬Â, getX()); preferences. putInt(ââ¬Å"windowWidthââ¬Â, getWidth()); preferences. putInt(ââ¬Å"windowHeightââ¬Â, getHeight()); preferences. put(ââ¬Å"lookInââ¬Â, lookInField. getText()); preferences. put(ââ¬Å"filterââ¬Â, filePatternField. getText()); preferences. put(ââ¬Å"searchForââ¬Â, searchForField. getText()); preferences. put(ââ¬Å"excludeââ¬Â, excludeField. getText()); preferences. putBoolean(ââ¬Å"recurseââ¬Â, includeSub   CheckBox. isSelected()); System. exit(0); }  man  neutralize searchComplete() { stopButton. etEnabled(false); //status. setText(ââ¬Å"Search completedââ¬Â); int count=((ListModel)resultList. getModel()). getSize(); if(count==0){ status. setText(ââ¬Å"Search Completed No Files Foundââ¬Â); } if(stopFlag){ status. setText(ââ¬Å"Search Stopped ââ¬Å"+count +ââ¬Â Files Foundââ¬Â); stopFlag=false; }else{ status. setText(ââ¬Å"Search Completed ââ¬Å"+count +ââ¬Â Files Foundââ¬Â); } }  macrocosm void searchFailed(Throwable t) { Object[] messages = {Bundle. getString(ââ¬Å" overlookionOccurredââ¬Â),t. getMessage()}; JOptionPane. showMessageDialog(this, messages, Bundle. getString(ââ¬Å"errorTitleââ¬Â), JOptionPane. ERROR_MESSAGE); } protected void startSearch() { cardLayout. how(cardPanel, ââ¬Å" angle of inclinationââ¬Â); ResultsListModel model = (ResultsListModel) resultList. getModel(); model. clear(); String dirStr = lookInField. getText(); if (dirStr    ==  vigour || dirStr. length() == 0) { dirStr = ââ¬Å". ââ¬Å"; } File dir = new File(dirStr); if (! dir. exists()) { JOptionPane. showMessageDialog(this, Bundle. getString(ââ¬Å"pathDoesNotExistââ¬Â), Bundle. getString(ââ¬Å"errorTitleââ¬Â), JOptionPane. ERROR_MESSAGE);  damages; } String target = searchForField. getText(); String filter = filePatternField. getText(); String exclude = excludeField. getText(); try { Pattern. compile(target); Pattern. compile(filter); Pattern. ompile(exclude); }  exigency (PatternSyntaxException pse) { Object[] messages = {Bundle. getString(ââ¬Å"invalidRegexPatternââ¬Â), pse. getMessage()}; JOptionPane. showMessageDialog(this, messages, Bundle. getString(ââ¬Å"errorTitleââ¬Â),JOptionPane. ERROR_MESSAGE);  dedicate; } if (runner == null) { runner = new RunSearch(this); } runner. search(dir, target, filter, includeSubCheckBox. isSelected(), exclude); Thread th = new Thread(runner); th. start(); stopButton. setEnabled(true); } } Code    for bundle package jog. engine; import java. net. URL; import java. util. MissingResourceException; import java. til. ResourceBundle;  usual class Bundle { private  nonmoving ResourceBundle resourceBundle;  passive { resourceBundle = ResourceBundle. getBundle(Bundle. class. getName()); } public  still ResourceBundle getBundle() { return resourceBundle; } public static URL getResource(String  chance on) { String name = getString(key); return name == null ? null : Bundle. class. getResource(name); } public static String getString(String key) { try { return resourceBundle. getString(key); } catch (MissingResourceException mre) { return null; } } } Code for runsearch package jog. engine; import java. io. File; import jog. engine. *; mport java. lang. *; class RunSearch implements Runnable { protected File dir; protected String lookFor; protected String filter; protected boolean subDirs; protected String exclude; protected FileSearchListener listener; protected  quester searcher; public    RunSearch(FileSearchListener listener) { this. listener = listener; } public void run() { if (searcher == null) { searcher = new Searcher(); if (listener ! = null) { searcher. addSearchListener(listener); } } searcher. search(dir, lookFor, filter, subDirs, exclude); } public void search(File dir, String lookFor, String filter, boolean subDirs, String exclude) this. dir = dir; this. lookFor = lookFor; this. filter = filter; this. subDirs = subDirs; this. exclude = exclude; } public void stop() { //System. out. println(ââ¬Å"Searcher is one:ââ¬Â+ isAlive()); System. out. println(ââ¬Å"Searcherââ¬Â); if (searcher ! = null) { searcher. stopSearching(); searcher=null; System. out. println(ââ¬Å"Searcher oneââ¬Â); } //System. out. println(ââ¬Å"Searcher is :ââ¬Â+ isAlive()); //System. out. println(ââ¬Å"Searcher oneââ¬Â); } } Code for searcher package jog. engine; import java. io. *; import java. nio. *; import java. nio. channels. *; import java. nio. charset. *; impo   rt java. util. *; import java. til. regex. *; import javax. swing. event. EventListenerList; import jog. engine. *; class Searcher { protected static Pattern linePattern; protected static Charset charset; protected static CharsetDecoder decoder; protected EventListenerList searchListeners; protected  erratic boolean stopSearch; protected Pattern targetPattern; protected Matcher targetMatcher; protected Pattern filterPattern; protected Matcher filterMatcher; protected Pattern excludePattern; protected Matcher excludeMatcher; static { try { linePattern = Pattern. compile(ââ¬Å". * ? ââ¬Å"); } catch (PatternSyntaxException pse) { System. out. rintln(ââ¬Å"Ye flipping gods! ââ¬Å"); } charset = Charset. forName(ââ¬Å"ISO-8859-1ââ¬Â); decoder = charset. newDecoder(); } public Searcher() { searchListeners = new EventListenerList(); } public void addSearchListener(FileSearchListener listener) { searchListeners. add(FileSearchListener. class, listener); } protected void fireDone()    { if (searchListeners == null) { return; } Object[] listeners = searchListeners. getListenerList(); for (int i = listeners. length â⬠2; i >= 0; i -= 2) { if (listeners[i] == FileSearchListener. class) { FileSearchListener fsl = (FileSearchListener) listeners[i + 1]; fsl. earchComplete(); } } } protected void fireError(Throwable t) { if (searchListeners == null) { return; } Object[] listeners = searchListeners. getListenerList(); for (int i = listeners. length â⬠2; i >= 0; i -= 2) { if (listeners[i] == FileSearchListener. class) { FileSearchListener fsl = (FileSearchListener) listeners[i + 1]; fsl. searchFailed(t); } } } protected void fireFound(String match) { if (searchListeners == null) { return; } FileFoundEvent event = new FileFoundEvent(this, match); Object[] listeners = searchListeners. getListenerList(); for (int i = listeners. ength â⬠2; i >= 0; i -= 2) { if (listeners[i] == FileSearchListener. class) { FileSearchListener fsl = (FileSearchListener) liste   ners[i + 1]; fsl. fileFound(event); } } event = null; } public void removeSearchListener(FileSearchListener listener) { searchListeners. remove(FileSearchListener. class, listener); } public void search(File startIn, String target, String filter, boolean recurse, String exclude) { stopSearch = false; try { targetPattern = Pattern. compile(target); filterPattern = Pattern. compile(filter); if (exclude ! = null && exclude. length() > 0) { excludePattern = Pattern. ompile(exclude); } searchLow(startIn, recurse); } catch (IOException ioe) { fireError(ioe); } catch (PatternSyntaxException pse) { fireError(pse); } targetPattern = null; targetMatcher = null; filterPattern = null; filterMatcher = null; excludePattern = null; excludeMatcher = null; fireDone(); } protected void searchLow(File startIn, boolean recurse) throws IOException { String[] files = startIn. list(); if (files == null) { return; } for (int ii = 0; ii < files. length; ii++) { if (stopSearch) {  discriminat   e; } File file = new File(startIn, files[ii]); if (file. isFile() && file. canRead()) { String  file name = file. etCanonicalPath(); if (filterMatcher == null) { filterMatcher = filterPattern. matcher( computer file name); } else { filterMatcher. reset(filename); } if (! filterMatcher.  discern()) { continue; } FileInputStream fis = new FileInputStream(file); FileChannel fc = fis. getChannel(); MappedByteBuffer bb = fc. map(FileChannel. MapMode. READ_ONLY, 0, fc. size()); CharBuffer cb = decoder. decode(bb); boolean matchFound = false; if ((targetPattern. flags() & Pattern. DOTALL) ! = 0) { if (targetMatcher == null) { targetMatcher = targetPattern. matcher(cb); } else { argetMatcher. reset(cb); } if (targetMatcher. find()) { matchFound = true; } } else { Matcher lm = linePattern. matcher(cb); while (lm. find()) { CharSequence cs = lm. group(); if (targetMatcher == null) { targetMatcher = targetPattern. matcher(cs); } else { targetMatcher. reset(cs); } if (targetMatch   er. find()) { matchFound = true; } if (lm. end() == cb. limit()) { break; } } } if (matchFound) { fireFound(filename); } } else if (recurse && file. isDirectory()) { String dirname = file. getName(); if (excludePattern ! = null) { if (excludeMatcher == null) { excludeMatcher = excludePattern. atcher(dirname); } else { excludeMatcher. reset(dirname); } if (! excludeMatcher. find()) { searchLow(file, recurse); } } else { searchLow(file, recurse); } } } } public void stopSearching() { stopSearch = true; } } Code for filesearch listener package jog. engine; import java. util. EventListener; import jog. engine. FileFoundEvent; interface FileSearchListener extends EventListener { public void fileFound(FileFoundEvent event); public void searchComplete(); public void searchFailed(Throwable t); } Code for tty package jog. engine; import java. io. *; import java. util. regex. *; mport jog. engine. *; public class tty implements FileSearchListener { protected static int argIndex; pro   tected static String excludeStr = ââ¬Å"ââ¬Â; protected static String nameStr = ââ¬Å"ââ¬Â; protected static void displayHelp() { String str = Bundle. getString(ââ¬Å"ttyHelp1ââ¬Â); int i = 1; while (str ! = null) { System. out. println(str); i++; str = Bundle. getString(ââ¬Å"ttyHelpââ¬Â + i); } } public void fileFound(FileFoundEvent event) { System. out. println(event. getFile()); } protected static boolean processArgs(String[] args) { while (argIndex < args. length) { String arg = args[argIndex]; if (arg. equals(ââ¬Å"-excludeââ¬Â)) { rgIndex++; excludeStr = args[argIndex]; } else if (arg. equals(ââ¬Å"-hââ¬Â) || arg. equals(ââ¬Å"-helpââ¬Â) || arg. equals(ââ¬Å"ââ¬helpââ¬Â)) { displayHelp(); return false; } else if (arg. equals(ââ¬Å"-nameââ¬Â)) { argIndex++; nameStr = args[argIndex]; } else { break; } argIndex++; } return true; } public void searchComplete() {} public void searchFailed(Throwable t) { System. err. println(Bundle. getStrin   g(ââ¬Å"exceptionOccurredââ¬Â)); System. err. println(t. getMessage()); } public static void main(String[] args) { try { if (! processArgs(args)) { return; } } catch (ArrayIndexOutOfBoundsException aioobe) { System. err. println(Bundle. etString(ââ¬Å"ttyMissingArgumentsââ¬Â)); return; } if (argIndex == args. length) { System. err. println(Bundle. getString(ââ¬Å"ttyMissingRequiredââ¬Â)); return; } String target = args[argIndex]; argIndex++; String dirStr = null; if (argIndex == args. length) { dirStr = ââ¬Å". ââ¬Å"; } else { dirStr = args[argIndex]; } File dir = new File(dirStr); if (! dir. exists()) { System. err. println(Bundle. getString(ââ¬Å"pathDoesNotExistââ¬Â)); return; } try { Pattern. compile(target); Pattern. compile(nameStr); } catch (PatternSyntaxException pse) { System. err. println(Bundle. getString(ââ¬Å"invalidRegexPatternââ¬Â)); System. rr. println(pse. getMessage()); return; } Searcher searcher = new Searcher(); tty  precedent = new tty();    searcher. addSearchListener(instance); searcher. search(dir, target, nameStr, true, excludeStr); searcher. removeSearchListener(instance); } } Code for filefoundevent package jog. engine; import java. util. EventObject; class FileFoundEvent extends EventObject { protected String file; public FileFoundEvent(Object source, String file) { super(source); this. file = file; } public String getFile() { return file; } } Code for result list model package jog. engine; import java. util.  vector; import javax. wing. AbstractListModel; import jog. engine. *; class ResultsListModel extends AbstractListModel { protected  sender list entropy; public ResultsListModel() { listData = new Vector(); } public void addElement(Object o) { listData. add(o); fireIntervalAdded(this, listData. size(), listData. size()); } public void clear() { int size = listData. size(); listData. clear(); fireIntervalRemoved(this, 0, size); } public Object getElementAt(int i) { try { return listData. elementAt(i); } catc   h (ArrayIndexOutOfBoundsException e) { return null; } } public int getSize() { return listData. size(); } } Code for main package jog. ngine; import jog. engine. *; public class Main { public static void main(String[] args) { new MainWindow(). show(); // new jog. searchdesk. MainWindow. show(); } } For a  musical instrument with full regex support, metacharacters like ââ¬Å"*ââ¬Â and ââ¬Å"? ââ¬Â (or ââ¬Å"wildcard operators,ââ¬Â as they are some measure called) are only the tip of the iceberg. Using a good regex engine and a well-crafted regular expression, one can  slow search through a text file (or a hundred text files) searching for  pronounces that have the suffix ââ¬Å". hypertext markup languageââ¬Â (but only if the  discourse begins with a capital  earn and occurs at the  commencement of the line),  deputize the . tml suffix with a .  monetary standard generalized markup language suffix, and thence change all the  trim cover case characters to upper case. Wi   th the right tools, this series of regular expressions would do just that: s/(^[A_Z]{1})([a-z]+). sgml/12. html/g tr/a-z/A-Z/ As you might  opine from this example, concision is everything when it comes to crafting regular expressions, and while this syntax wont win  every(prenominal) beauty prizes, it follows a logical and  more or less standardized format which you can learn to rea+*d and write easily with just a  microscopical bit of practice. In a regular expression, everything is a generalized pattern.If I type the word ââ¬Å"serendipitousââ¬Â into my editor, Ive created one instance of the word ââ¬Å"serendipitous. ââ¬Â If, however, I  bespeak to my tool (or compiler, or editor, or what have you) that Im now typing a regular expression, I am in effect creating a template that matches all instances of the characters ââ¬Å"s,ââ¬Â ââ¬Å"e,ââ¬Â ââ¬Å"r,ââ¬Â ââ¬Å"e,ââ¬Â ââ¬Å"n,ââ¬Â ââ¬Å"d,ââ¬Â ââ¬Å"i,ââ¬Â ââ¬Å"p,ââ¬Â ââ¬Å"i,ââ¬Â Ã¢â   ¬Å"t,ââ¬Â ââ¬Å"o,ââ¬Â ââ¬Å"u,ââ¬Â and ââ¬Å"sââ¬Â all in a row. The standard way to find ââ¬Å"serendipitousââ¬Â (the word) in a file is to use ââ¬Å"serendipitousââ¬Â (the regular expression) with a tool like egrep (or extended grep): $ egrep ââ¬Å"serendipitousââ¬Â foobar ;hitsThis line, as you might guess, asks egrep to find instances of the pattern ââ¬Å"serendipitousââ¬Â in the file ââ¬Å"foobarââ¬Â and write the results to a file called ââ¬Å"hitsââ¬Â. In the  forward examples, we have been using regular expressions that cleave to the first rule of regular expressions: namely, that all  alphameric characters match themselves. There are other characters, however, that match in a more generalized fashion. These are usually referred to as the meta characters. Some meta characters match  hit characters. This includes the following symbols: . Matches every one character ââ¬Â¦]Matches  both character listed  surrounded by the brackets [^â   â¬Â¦]Matches any character except those listed  in the midst of the brackets  aver we have a   measuring of filenames listed out in a file called ââ¬Å"Important. files. ââ¬Â We  pauperization to ââ¬Å"grep outââ¬Â those filenames which follow the pattern ââ¬Å"blurfle1ââ¬Â, ââ¬Å"blurfle2ââ¬Â, ââ¬Å"blurfle3,ââ¬Â and so on, but exclude files of the form ââ¬Å"1blurfleââ¬Â, ââ¬Å"2blurfleââ¬Â, ââ¬Å"3blurfleââ¬Â The following regex would do the  delusion: $ egrep ââ¬Å"blurfle. ââ¬Â Important. files ;blurfles The authoritative thing to realize here is that this line will not match merely the string ââ¬Å"blurfle. (that is, ââ¬Å"blurfleââ¬Â followed by a period). In a regular expression, the dot is a reserved symbol (well get to matching periods a little further on). This is fine if we arent particular about the character we match (whether its a ââ¬Å"1,ââ¬Â a ââ¬Å"2,ââ¬Â or even a letter, a space, or an underscore). Narrowing the f   ield of choices for a  genius character match, however, requires that we use a character class.  portion classes match any character listed within that class and are separated off using square brackets.So, for example, if we  commanded to match on ââ¬Å"blurfleââ¬Â but only when it is followed immediately by a number (including ââ¬Å"blurfle1ââ¬Â but not ââ¬Å"blurflezââ¬Â) we would use something like this: $ egrep ââ¬Å"blurfle[0123456789]ââ¬Â Important. files >blurfles The syntax here is just as it seems: ââ¬Å"Find ââ¬Ëblurfle followed by a  secret code, a one, a two, a three, a four, a five, a six, a seven, an eight, or a  nine-spot. ââ¬Â such(prenominal) classes are usually abbreviated using the range operator (ââ¬Å"-ââ¬Å"): $ egrep ââ¬Å"blurfle[0-9]ââ¬Â Important. files >blurfles The following regex would find ââ¬Å"blurfleââ¬Â followed by any alphanumeric character (upper or lower case). egrep ââ¬Å"blurfle[0-9A-Za-z]ââ¬Â Importan   t. files >blurfles (Notice that we didnt write blurfle[0-9 A-Z a-z] for that last one. The spaces might make it easier to read, but wed be matching on anything between  cipher and nine, anything between a and z, anything between A and Z, or a space. ) A carat at the beginning of the character class negates that class. In other  lecture, if you  requireed to find all instances of blurfle except those which end in a number, youd use the following: $ egrep ââ¬Å"blurfle[^0-9]ââ¬Â Important. files >blurfles Many regex implementations have ââ¬Å"macrosââ¬Â for various character classes.In Perl, for example, d matches any dactyl ([0-9]) and w matches any ââ¬Å"word characterââ¬Â ([a-zA-Z0-9_]). Grep uses a  meagerly different notation for the  similar thing: [:digit:] for digits and [:alnum:] for alphanumeric characters. The man page (or other documentation) for the particular tool should list all the regex macros available for that tool. Quantifiers The regular expressi   on syntax also provides metacharacters which specify the number of  measure a particular character should match. ?Matches any character zero or one times *Matches the preceding element zero or more times +Matches the preceding element one or more times num}Matches the preceding element num times {min,  sludge}Matches the preceding element at  to the lowest degree min times, but not more than max times These metacharacters allow you to match on a  exclusive-character pattern, but then continue to match on it until the pattern changes. In the last example, we were trying to search for patterns that contain ââ¬Å"blurfleââ¬Â followed by a number between zero and nine. The regex we came up with would match on blurfle1, blurfle2, blurfle3, and so forth If, however, you had a programmer who mistakenly thought that ââ¬Å"blurfleââ¬Â was  sibyllic to be spelled ââ¬Å"blurffle,ââ¬Â our regex wouldnt be able to catch it.We could fix it, though, with a  quantifier. $ egrep ââ¬Å"b   lur[f]+le[0-9]ââ¬Â Important. files >blurfles Here we have ââ¬Å"Find ââ¬Ëb, ââ¬Ël, ââ¬Ëu, ââ¬Ër (in a row) followed by one or more instances of an ââ¬Ëf followed by ââ¬Ël and ââ¬Ëe and then any single digit character between zero and nine. ââ¬Â Theres always more than one way to do it with regular expressions, and in fact, if we use single-character metacharacters and quantifiers in conjunction with one  other, we can search for almost all the variant spellings of ââ¬Å"blurfleââ¬Â (ââ¬Å"bllurfle,ââ¬Â ââ¬Å"bllurrfleââ¬Â, bbluuuuurrrfffllleââ¬Â, and so on).One way, for example, might employ the ubiquitous (and exceedingly powerful) . * combination: $ egrep ââ¬Å"b. *eââ¬Â Important. files ;blurfles If we work this out, we come out with something like: ââ¬Å"find a ââ¬Ëb followed by any character any number of times (including zero times) followed by an ââ¬Ëe. ââ¬Â Its  enticing to use ââ¬Å". *ââ¬Â with abandon. Howev   er, bear in mind that the preceding example would match on words like ââ¬Å"blueââ¬Â and ââ¬Å"baritoneââ¬Â as well as ââ¬Å"blurfle. ââ¬Â Suppose the filenames in blurfle are numbered up to 12324, but we only care about the first 999: $ egrep ââ¬Å"blurfle[0-9]{3}ââ¬Â Important. files >bluflesThis regex tells egrep to match any number between zero and nine exactly three times in a row. Similarly, ââ¬Å"blurfle[0-9]{3,5}ââ¬Â matches any number between zero and nine at lest three times but not more than five times in a row. Anchors Often, you need to specify the position at which a particular pattern occurs. This is often referred to as ââ¬Å"anchoringââ¬Â the pattern: ^Matches at the start of the line $Matches at the end of the line <Matches at the beginning of a word >Matches at the end of a word Matches at the beginning or the end of a word BMatches any charater not at the beginning or end of a word ^ââ¬Â and ââ¬Å"$ââ¬Â are some of the mos   t useful metacharacters in the regex arsenalââ¬particularly when you need to run a search-and-replace on a list of strings. Suppose, for example, that we want to take the ââ¬Å"blurfleââ¬Â files listed in Important. files, list them out separately, run a program called ââ¬Å"fragellateââ¬Â on  separately one, and then append each successive output to a file called ââ¬Å"fraggled_files. ââ¬Â We could write a full-blown shell script (or Perl script) that would do this, but often, the job is faster and easier if we build a very simple shell script with a series of regular expressions.Wed begin by greping the files we want to operate on and writing the output to a file. $ egrep ââ¬Å"blurfle[0-9]ââ¬Â Important. file ;script. sh This would give us a list of files in script. sh that looked something like this: blurfle1 blurfle2 blurfle3 blurfle4 . . . Now we use sed (or the ââ¬Å"/%sââ¬Â operator in vi, or the ââ¬Å"query-replace-regexpââ¬Â command in emacs) to p   ut ââ¬Å"fragellateââ¬Â in front of each filename and ââ¬Å">>fraggled_filesââ¬Â after each filename. This requires two separate search-and-replace  trading operations (though not necessarily, as Ill explain when we get to backreferences).With sed, you have the ability to put both substitution lines into a file, and then use that file to iterate through another making each substitution in turn. In other words, we create a file called ââ¬Å"fraggle. sedââ¬Â which contains the following lines: s/^/fraggelate / s/$/ >>fraggled_files/ Then run the following ââ¬Å"sed routineââ¬Â on script. sh like so: $ sed -f fraggle. sed script. sh >script2. sh Our script would then look like this: fraggelate blurfle1 >>fraggled_files fraggelate blurfle2 >>fraggled_files fraggelate blurfle3 >>fraggled_files raggelate blurfle4 >>fraggled_files . . Chmod it, run it, and youre done. Of course, this is a somewhat trivial example (ââ¬Å" wherefore wou   ldnt you just run ââ¬Å"fragglate blurfle* ;;fraggled_filesââ¬Â from the command line? ââ¬Å"). Still, one can easily imagine instances where the criteria for the file name list is too complicated to express using [filename]* on the command line. In fact, you can  in all probability see from this sed-routine example that we have the makings of an automatic shell-script  generator or file filter. You may also have noticed something odd about that caret in our sed routine.Why doesnt it mean ââ¬Å"exceptââ¬Â as in our previous example? The answer has to do with the sometimes radical  residuum between what an operator  doer inside the range operator and what it means outside it. The rules change from tool to tool, but generally speaking, you should use metacharacters inside range operators with caution. Some tools dont allow them at all, and others change the meaning. To  survival of the fittest but one example, most tools would interpret [A-Za-z. ] as ââ¬Å"Any character betw   een A and Z, a and z or a period. ââ¬Â Most tools provide some way to anchor a match on a word boundary.In some versions of grep, for example, you are allowed to write: $ grep ââ¬Å"fle>ââ¬Â Important. files ;blurfles This says: ââ¬Å"Find the characters ââ¬Å"fââ¬Â, ââ¬Å"lââ¬Â, ââ¬Å"eââ¬Â, but only when they come at the end of a word. ââ¬Â  tells the regex engine to match any word boundary (whether its at the beginning or the end) and B tells it to match any position that isnt a word boundary. This again can vary considerably from tool to tool. Some tools dont support word boundaries at all, and others support them using a slightly different syntax.The tools that do support word boundaries generally consider words to be bounded by spaces or punctuation, and consider numerals to be legitimate parts of words, but there are some variations on these rules that can effect the accuracy of your matches. The man page or other documentation should resolve the ma   tter. Escape Characters By now, youre  believably wondering how you go about searching for one of the special characters (asterisks, periods, slashes, and so on). The answer lies in the use of the  miss characterââ¬for most tools, the backslash (ââ¬Å"ââ¬Â).To reverse the meaning of a special character (in other words, to  embrace it as a normal character instead of as a metacharacter), we  only when put a backslash before that character. So, we know that a regex like ââ¬Å". *ââ¬Â finds any character any number of times. But  conceive of were searching for ellipses of various lengths and we just want to find periods any number of times. Because the period is normally a special character, wed need to escape it with a backslash: $ grep ââ¬Å". *ââ¬Â Important. Files ;ellipses. files Unfortunately, this  domiciliate to the legendary ugliness of regular expressions more than any other element of the syntax.Add a few escape characters, and a simple sed routine designed to    replace a couple of URLs quickly degenerates into confusion: sed ââ¬Ës/http://etext. lib. virginia. edu//http://www. etext. virginia. edu/g To make matters worse, the list of what needs to be escaped differs from tool to tool. Some tools, for example, consider the ââ¬Å"+ââ¬Â quantifier to have its normal meaning (as a  unexceptional plus sign) until it is escaped. If youre having trouble with a regex (a sed routine that wont  dissect or a grep pattern that wont match even though youre certain the pattern exists), try  play around with the escapes.Or better yet, read the man page. Alternation Alternation refers to the use of the ââ¬Å"|ââ¬Â symbol to indicate logical OR. In a previous example, we used ââ¬Å"blur[f]+leââ¬Â to catch those instances of ââ¬Å"blurfleââ¬Â that were misspelled with two ââ¬Å"fsââ¬Â. Using alternation, we could have written: $ egrep ââ¬Å"blurfle|blurffleââ¬Â Important. files ;blurfles This means simply ââ¬Å"Find either blurfle    OR blurffle. ââ¬Â The power of this becomes more evident when we use parentheses to limit the  mountain range of the  secondary matches.Consider the following regex, which accounts for both the American and British spellings of the word ââ¬Å"grayââ¬Â: $ egrep ââ¬Å"gr(a|e)yââ¬Â Important. files ;hazy. shades Or perhaps a mail-filtering program that uses the following regex to single out past correspondence between you and the boss: /(^To:|^From:) (Seaman|Ramsay)/ This says, ââ¬Å"Find a ââ¬ËTo: or a ââ¬ËFrom: line followed by a space and then either the word ââ¬ËSeaman or the word ââ¬ËRamsay This can make your regexs extremely flexible, but be careful! Parentheses are also meta characters which figure prominently in the use of . . . Back referencesPerhaps the most powerful element of the regular expression syntax, back references allows you to load the results of a matched pattern into a  modify and then reuse it later in the expression. In a previous examp   le, we used two separate regular expressions to put something before and after a filename in a list of files. I mentioned at that point that it wasnt entirely necessary that we use two lines. This is because back references allow us to get it down to one line. Heres how: s/(blurfle[0-9]+)/fraggelate 1 >>fraggled_files/ The key elements in this example are the parentheses and the ââ¬Å"1ââ¬Â.Earlier we  observe that parentheses can be used to limit the scope of a match. They can also be used to save a particular pattern into a temporary fender. In this example, everything in the ââ¬Å"searchââ¬Â one-half of the sed routine (the ââ¬Å"blurfleââ¬Â part) is saved into a buffer. In the ââ¬Å"replaceââ¬Â half we recall the contents of that buffer back into the string by referring to its buffer number. In this case, buffer ââ¬Å"1ââ¬Â. So, this sed routine will do just what the earlier one did: find all the instances of blurfle followed by a number between zero an   d nine and replace it with ââ¬Å"fragellate blurfle[some number] ;;fraggled filesââ¬Â.Backreferences allow for something that very few  indifferent search engines can manage; namely, strings of  info that change slightly from instance to instance.  rascal  total schemes provide a perfect example of this. Suppose we had a document that numbered each page with the notation . The number and the chapter name change from page to page, but the rest of the string stays the same. We can easily write a regular expression that matches on this string, but what if we wanted to match on it and then replace everything but the number and the chapter name? //Page 1, Chapter 2/ Buffer number one (ââ¬Å"1ââ¬Â) holds the first matched sequence, ([0-9]+); buffer number two (ââ¬Å"2ââ¬Â) holds the second, ([A-Za-z]+). Tools vary in the number of backreference they can hold. The more common tools (like sed and grep) hold nine, but Python can hold up to ninety-nine. Perl is limited only by the    amount of physical memory (which, for all practical purposes, means you can have as  numerous as you want). Perl also lets you assign the buffer number to an ordinary scalar variable ($1, $2, etc. ) so you can use it later on in the code block. a.OBJECT ORIENTED PROGRAMMING AND JAVA Object-oriented Programming was developed because of limitations found in earlier approaches of programming. To appreciate what OOP does, we need to understand what these limitations are and how they arose from traditional programming. PROCEDURAL LANGUAGES Pascal, C, Basic, FORTRAN, and  uniform languages are procedural languages. That is, each statement in the language tells the computer to do something: Get some input, add these numbers, divide by 6, display the output. A program in a procedural language is a list of instructions.For very small programs no other organizing principle (often called a paradigm) is needed. The programmer creates the list of instructions, and the computer carries them out.    Division into Functions When programs become larger, a single list of instructions becomes unwieldy. Few programmers can comprehend a program of more than a few hundred statements unless it is broken down into smaller units. For this  condition the  contribution was adopted as a way to make programs more comprehensible to their human creators. (The term functions is used in C++ and C.In other languages the same concept may be referred to as a subroutine, a subprogram, or a procedure. ) A program is divided into functions, and ( imaginationlly, at least) each function has a understandably defined purpose and a clearly defined interface to the other functions in the program. The  paper of breaking a program into functions can be further extended by grouping a number of functions together into a larger entity called a module, but the principle is similar: grouping a number of components that carry out specific tasks.Dividing a program into functions and modules is one of the cornersto   nes of  structured programming, the somewhat  loosely defined discipline that has influenced programming organization for more than a decade. Problems with Structured Programming As programs  turn ever larger and more complex, even the structured programming approach begins to show signs of strain. You may have heard about, or been involved in, horror stories of program development. The project is too complex, the schedule slips, more programmers are added, complexity increases, costs skyrocket, the schedule slips further, and disaster ensues.Analyzing the reasons for these  chastenings reveals that there are weaknesses in the procedural paradigm itself. No matter how well the structured programming approach is implemented, large programs become excessively complex. What are the reasons for this failure of procedural languages? One of the most crucial is the  subroutine played by selective information. Data Under setd In a procedural language, the emphasis is on doing thingsââ¬rea   d the keyboard,  change the vector, check for errors, and so on. The subdivision of a program into functions continues this emphasis. Functions do things just as single program statements do.What they do may be more complex or abstract, but the emphasis is still on the action. What happens to the data in this paradigm? Data is, after all, the reason for a programs existence. The important part of an  enumeration program isnt a function that displays the data, or a function that checks for correct input; its the  livestock data itself. Yet data is given second-class status in the organization of procedural languages. For example, in an inventory program, the data that makes up the inventory is probably read from a disk file into memory, where it is treated as a global variable.By global we mean that the variables that  form the data are declared outside of any function, so they are  rileible to all functions. These functions  do various operations on the data. They read it,  dissect    it, update it, rearrange it, display it, write it back to the disk, and so on. We should note that most languages, such as Pascal and C, also support  topical anaesthetic variables, which are hidden within a single function. But local variables are not useful for important data that  essential be  plan of attacked by many different functions. Now suppose a new programmer is hired to write a function to analyze this nventory data in a certain way. Unfamiliar with the subtleties of the program, the programmer creates a function that  by chance corrupts the. This is easy to do, because every function has complete  devil to the data. Its like leaving your personal papers in the lobby of your apartment building: Anyone can change or destroy them. In the same way, global data can be corrupted by functions that have no business changing it. another(prenominal) problem is that, since many functions access the same data, the way the data is stored becomes critical.The arrangement of the data    cant be changed without modifying all the functions that access it. If you add new data items, for example, youll need to modify all the functions that access the data so that they can also access these new items. It will be hard to find all such functions, and even harder to modify all of them correctly. Its similar to what happens when your local supermarket moves the bread from aisle 4 to aisle 12. Everyone who patronizes the supermarket must figure out where the bread has gone, and adjust their shop habits accordingly.What is needed is a way to restrict access to the data, to hide it from all but a few critical functions. This will protect the data, simplify maintenance, and offer other benefits as well. Relationship to the Real  creation Procedural programs are often difficult to design. The problem is that their chief componentsââ¬functions and data structuresââ¬dont model the real world very well. For example, suppose you are writing a program to create the elements of a    graphics user interface: menus, windows, and so on. Quick now, what functions will you need? What data structures?The answers are not obvious, to say the least. It would be better if windows and menus corresponded more closely to actual program elements. New Data Types There are other problems with traditional languages. One is the difficulty of creating new data types. Computer languages typically have several intact data types: integers, floating-point numbers, characters, and so on. What if you want to invent your own data type? Perhaps you want to work with complex numbers, or two dimensional coordinates, or datesââ¬quantities the built-in data types donââ¬â¢t handle easily.Being able to create your own types is called extensibility; you can extend the capabilities of the language. Traditional languages are not usually extensible. Without  stirred convolutions, you canââ¬â¢t bundle together both X and Y coordinates into a single variable called Point, and then add and s   ubtract  surveys of this type. The result is that traditional programs are more complex to write and maintain. The object oriented approach The fundamental idea behind object-oriented languages is to combine into a single unit both data and the functions that operate on that data.Such a unit is called an object. An objectââ¬â¢s functions, called member methods in Java, typically provide the only way to access its data. If you want to read the item and return the value to you, you call a member function in the object. It will read the item and return the value to you. You canââ¬â¢t access the data directly. The data is hidden, so it is safe from accidental modification. Data and its functions are said to be encapsulated into a single entity. Data encapsulation and data hiding are key  basis in the description of object oriented languages.If you want to modify the data in an object, you know exactly what functions interact with it: the member functions in the object. No other fu   nctions can access the data. This simplifies writing, debugging, and maintaining the program. A Java program typically consists of a number of objects, which communicate with each other by calling one anotherââ¬â¢s members functions. We should mention that what are called member functions in C++ are called methods in Java. Also, data items are referred to as instance variables. Calling an objectââ¬â¢s member function is referred to as sending a message to the object.\r\n'  
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment