Graph-based Pattern-oriented, Context-sensitive Code Completion

Anh Tuan Nguyen, Tung Thanh Nguyen, Hoan Anh Nguyen, Ahmed Tamrawi, Hung Viet Nguyen, Jafar Al-Kofahi,
Tien N. Nguyen

Video Demo Downloads


Empirical Evaluation

Usefulness in Code Completion - Tasks

 

Task

Description

1

Listing and sorting files in a directory

2

Comparing two directories

3

Looking up IP information from a text-based DNS database

4

Listing the pages linking to a target page

5

Writing to an INI configuration file

6

Validating an XML string

 

Task 1. Listing and sorting files in a directory.

Given a directory, list all the files in that directory and its sub-directories decreasingly by file size.

Please consider the following when implementing this task:

  1. Your function should be called "ListDirFilesDec" with a single parameter "strPath" as string containing the directory path; your function should return the results in a list of type string.
  2. Your function should be recursive to process all directories similarly.
  3. You need to use "java.io" and "java.util" packages.

 

Task 2. Comparing two directories.

Given two directories, compare their file contents by name only and return three separate lists as follows:

- First list should contain files in the first directory but NOT in the second one.
- Second list should contain files in the second directory but NOT in the first one.
- Third list should contain files that exist in both directories.

Please consider the following when implementing this task:

  1. Your method should be called "DirCompare" with the following parameters:
    1. strDir1Path as a string containing the first directory path,
    2. strDir2Path as a string containing the second directory path,
    3. setOnlyInDir1 as a set or list containing the file names that exists in the first directory and not the second one,
    4. setOnlyInDir2 as a set or list containing the file names that exists in the second directory and not the first one,
    5. setInBoth as a set or list containing the files names that exists in both directories.
  2. Your method should use set/list operations to find the results.
  3. You need to use "java.io" and "java.util" packages.

 

Task 3. Looking up IP information from a text-based DNS database.

Given a simple text based DNS database containing some host's information (domain name and IP address), the database contains each host info in a separate line, formatted as follows: first the IP address, then a tab white space, and finally the host name. An example is shown below:

127.0.0.1 localhost
192.168.0.1 dnsserver
207.46.197.32 microsoft.com
129.42.38.1 ibm.com

With such database you need to retrieve the IP address for a given host, if the host does not exist in the database, then the function should return the smallest available IP address, i.e. the smallest 32 bit unsigned integer that does not exist in the database. (Note that, an IP address is conveniently written as a sequence of 4 numbers, e.g. 207.46.197.32, but it should be converted to a 32 bit unsigned integer for the comparison).

Please consider the following when implementing this task:

  1. Your function should be called IPLookup, that takes one parameter "strHostname" as string containing the name of the host to lookup, and it should return a string containing the IP address properly formatted.
  2. You should load the database first into a dictionary like data structure, then check if whether the passed hostname exists in the data or not and if not return the minimal IP address available.
  3. You need to use "java.io" and "java.util" packages.

 

Task 4. Listing the pages linking to a target page.

Given a simplified text-based web-cache that holds link information for websites, where each website is considered as a file containing linked websites (URL links), each in a separate line. The cache itself is considered as a list containing paths to such files. An example of a website file/cache is shown below:

For a website "www.MyWebsite.com" there will be a file with similar name with the following as its contents:

windows.com
msn.com
bing.com
google.com

Given such cache, implement a function that for given a URL/Website will retrieve all the other websites linking to/referencing it.

Please consider the following when implementing this task:

  1. Your function should be called "BackLink" and should have the following parameters:
    1. aryWebCache as a string array that will contain paths to websites files, structured similarly to what is described above,
    2. strTargetURL as a string that will contain the URL to check for,
    3. The return value need to be an list of type string containing the websites names referring to strTargetURL.
  2. For each given website in the aryWebCache load its data then check whether strTargetURL is one of the linked URLs or not, and if it was then add the website name to the results.
  3. You need to use "java.io" and "java.util" packages.

 

Task 5. Writing to an INI configuration file.

Given an INI file structured as follows:

[Category1]
name1 = value1
name2 = value2
...

[Category2]
name3 = value3

Categories, names, and values could be considered as strings. A category name will be within square brackets [ ], and within a category, each name is unique, but two categories might share a name, assigned to two different values. Each name and value pair is only separated by an equal sign "=" and no white spaces.

Given such a file, write a function that will modify a value for a given entry/name, with a specified category.

Please consider the following when implementing this task:

  1. Your function should be called "ModifyINI" that would take the following parameters:
    1. strINIFile as a string containing the absolute path for the INI file,
    2. strCategory as a string containing the category name,
    3. strName as a string containing the entry name,
    4. strValue as a string containing the new value,
    5. Your function should return a Boolean value: true if it was successful and false if there was an error or the request was invalid.
  2. First you need to load the file and correctly separate each category entries from each other. You can use three dimensional mapping, where the first dimension is the categories, the second is the entities/names and the last is the values.
  3. Then for the given parameters check if the category exists in the specified file, if it didn't then the request is invalid and the file should not be updated (return false).
  4. Otherwise check if the name does exist, and if it was then update its value and update the file, on the other hand, if the name did not exist, then create a new entry in that category with the name and value pair in it.
  5. When adding a new pair, it must be added at the end of the category.
  6. You need to use "java.io" and "java.util" packages.

 

Task 6. Validating an XML string.


Given an XML-like formatted string, where the tags are considered to have no attributes, and each open tag has a corresponding close tag. Also, Tag names are not pre-defined and can be anything, but the open and closing tags will have the same name (e.g. if the open tag was <Tag> then the closing tag must be matching it with a backslash preceding the tag name </Tag>). Also, the string might/might not have white spaces between the tags, and the tags could be separated into separate lines or just following each other, an example:

<Root>

<Parent1>

<Child1>
...
</Child1>

<Child2>...</Child2>

<Child3>
...
</Child3>

</Parent1>

<...

</Root>

Given such a string, write a function to validate its structure, your function should check whether every open tag has a corresponding close tag or not, and vice versa.

  1. Please consider the following when implementing this task:
    Your function should be called "Validate" that takes the following parameters:
    a. strValue as a string containing the XML-like formatted string to be validated,
    b. Your function should return an integer value, -1 if strValue is valid and does not have any problems. Otherwise it should return the index of the first invalid tag.
  2. You need to process the string and identify all tag pairs.
  3. You can use stacks for validation.
  4. You need to use "java.io" and "java.util" packages.