Articles from December, 2006

IPV4 Inspector API

I recently had to write a component for an application which allows users to inspect an IP address in detail as well as validate the address against various different criteria. I couldn’t find an API which provides this type of functionality in any of the Adobe classes so I wrote my own. I figured someone else may need to do something similar at some point so I am publishing the API under the MIT License.

The IPV4 API allows detailed inspection of an IP version 4 address (IPv4). It provides a robust API which is not available from Adobe at the moment. Usage is simple and straight forward and contains methods which perform the following:

  • Determine if the address specified is a valid IP address
  • Determine the network class of the specified IP Address
  • Determine the network octet of the specified IP Address
  • Determine the host octet of the specified IP Address
  • Determine if the IP Address is valid for Network assignment
  • Determine if the IP Address is within the Class range specified
  • Determine if the IP Address is a loopback address.

Below is a simple usage example which performs various operations on a specific IP Address:

The IPV4 inspector API can be used for inspecting and validating an IP Address. I plan on adding an update which contains methods for dealing with masks and prefix notation as well.

You can view the ASDoc as well as download the source swc

AS3 Iterator Factory API for Flex 2

I have been posting updates of my utils package lately but haven’t had the time to walk through how to use the API’s in detail other than the provided ASDoc.

One of the really useful API’s in the utils package is the Iterator implementation. The Iterator API provides a standard implementation of the Iterator pattern and is useful for traversing an object, array or collection of objects. The Iterator API provides an Array Iterator, ArrayCollection Iterator and an Object Iterator. You can use them individually as needed but one of the coolest features is the Iterator Factory. The Iterator Factory handles iterator instantiation and allows a single iterator instance, typed as an IIterator interface, to use any of the iterators, via the Iterator Factory.

You can click here to view an example of how to use the Iterator Factory.

AS3 Utility classes available for Flex 2

I have compiled some common AS3 utility APIs for public use as specified under the MIT license.

The utilities APIs are comprised of the following:

DeepCopy:
Creates a Deep Copy of an object reference to a new memory address and returns the cloned object

HashMap:
Creates a HashMap of object key / values as well as provides a standard API for working with a HashMap

ICollectionViewSortHelper:
Provides an API for collection alpha / numerical, ascending / descending sorting

Introspection:
Provides a robust API which performs detailed object introspection on a specified type

IteratorFactory:
Factory Pattern implementation which provides an API for Iterator instantiation

ObjectIterator:
Iterator implementation which provides methods for iterating over an object

ArrayCollectionIterator:
Iterator implementation which provides methods for iterating over a Collection

ArrayIterator:
Iterator implementation which provides methods for iterating over an array

StringUtil:
All static class which extends mx.utils.StringUtil to add additional methods for working with Strings

AVM2MemoryUtil:
All static class which returns the current memory allocated to a Flash Player instance in bytes, kilobytes or megabytes

I will continue to add to the utils package and make the updates regularly available. You can download the swc as well as view the ASDoc

AS3 HashMap for Flex 2

The inclusion of the Dictionary class in ActionScript 3 creates numerous possibilities when sub classing. The Dictionary class allows for creating key / value mappings or tables which are more commonly known as Hashes or Hash Maps. The only problem is that the Dictionary class does not provide an API for working with the map. The Dictionary class is a good starting point in which sub classes can create managed key / value hash maps and provide methods for retrieving values and keys as well as removing values, determining how many key / values exist and so on.

I am working on a project in which the data set is comprised of sentences tokenized into their individual parts of speech; noun, verb, preposition etc. Part of the requirement is that a lookup can be made on any individual part of speech to retrieve further information such as tense, plurality and so on. At first I simply used a Dictionary for the mappings but ended up adding all kinds of logic outside of the map whenever I needed to check for a key or add a value and so on. So I decided to write a simple HashMap class for AS3 which is similar to the HashMap available in java.util.HashMap.

Below is an example of how to use the HashMap class:

You can view the source for the HashMap class as well as the IMap interface which defines the methods necessary for working with the HashMap.