pattern

Regex Pattern for findin http in PHP

Hello everyone, how can i extract the http from this text? "Text: Here's 2 free bonuses. http://blablabla.blabla/blabla " But the url can also be another one. Finaly After i have the array, wich contains usualy just one url, how can i add it to the above text exactly at the same position? but with html tag <a> the results should l...

who should instantiate and assign runtime strategy implementations?

When implementing the strategy pattern, how do you determine which class is responsible for: Selecting the specific concrete strategy implementation to pass to the Context class (assuming that the selection is based on some complex business logic and not a static flag) Instantiating the aforementioned concrete implementation and actual...

Pattern to define key/value properties by using a single String

Hi, As you know, a single String can define many key/value properties. For instance, a query String can be defined as someKey=someValue&anotherKey=anotherValue Now i need to define a pattern in which a single String can define many key/value properties to be stored in a class attribute. But each value can be a String, an Array, A ref...

Java Scanner question

How do you set the delimiter for a scanner to either ; or new line? I tried: Scanner.useDelimiter(Pattern.compile("(\n)|;")); But it doesn't work. ...

strategy implementation question

I have a MessageProcessor class which processes xml messages of different types. A switch statement (C#) based on the message type calls the appropriate method to parse the xml and extract the data required for the type of message. I would rather have a number of parser classes, one of which will be injected into the MessageProcessor w...

Code infrastructure for accessing different properties of multiple elements (vector graphics editor)

Hi everybody, I am currently working on a small vector graphics editor (sort of) and facing a code design question, wondering how it would be solved in an elegant and straightforward manner. If anyone has a good idea how to solve this, or knows a good link or a piece of open source code dealing with a similar setup, I would be really ...

Difference between Template Method (separation) and Strategy pattern?

Hi all. My teacher is a really good one and I tend to understand his points, but this one just goes over my head. He explains Template Method in two variants; - Unification: the standard variant, that is composed of an abstract class with some abstract methods defining the variant parts of the otherwise fixed algorithm. - Separation: his...

RegEx number [-99.99..-0.01]+[0.01..99.99]

I want to validate a number. This number must be from -99.99 to +99.99 but except 0 (zero). I came up with this RegEx expression [-+]?((\d{1,2}\.?\d{0,1}[1-9])|(\d{0,1}[1-9])) but it does not handle number of this type: x0 xy.00 Any idea? Edit: I am trying to do a restriction for xsd file. ...

Constant Parameter Design

I am working with a Class that contains constants or parameter values that all classes can reference for example; public class Parameters { public static final String JUMP_TO_VALUE = "Parameters.JUMP_TO_VALUE"; public static final String EXCEPTION_ID = "Parameters.EXCEPTION_ID"; } Some of the foundation classes in my applicati...

What are the advantage of assinging object fields to local variables?

I'm trying to develop some asynchronous methods for a personal project of mine, and I'm looking into the framework for reference. I've downloaded the .NET source code to take a look at the bits and bolts more closely (with developer comments, something that Reflector doesn't give us :-P ) Anyway, in a lot of .NET classes I've came acro...

regex to get weight

I have html that has the weight of a item. <div><b>Item Weight (0.51 lbs in Warehouse 3)</b></div> I need a regex to get the weight and unit of measure. So in the above html, I need: 0.51 and lbs I am using java, I have a helper method, just need to get the regex down now! String regexPattern = ""; String result = ""; Patte...

Combination of values and appropriate Design Pattern

Greetings, I would like to ask what kind of design pattern will be the best in the scenario described below: I have a two combobox: option1 option21 option2 option22 option3 option23 option4 option24 there should be a specific combinations of those two comboboxes - only specific values should be displayed in...

jQuery plugin design pattern (common practice?) for dealing with private functions

Hey all, I've been developing jQuery plugins for quite some time now, and I like to think I know how to design one well by now. One issue keeps nagging me though, and that is how to deal with private functions in a powerful yet elegant manner. My plugins generally look something like this: (function($) { $.fn.myplugin = function(.....

please help me understand the pattern match in haskell. i'm a little confused.

if i have somthing like that: func (x1:x2:x3:xs) = xs then x1,x2,x3 must exist, yes? they can't be [], but must(again, MUST) be with a value, yes? also, the xs can be [] or [a] or [a,a,a] (etc'), yes? (in [a] i mean that it's a list with one number, and [a,a,a] is list of three numbers). also i have function that define isPrefixOf: m...

BeginTran(), Commit() and Rollback() in Repository Pattern

While creating a repository by using NHibetnate(or, whatever), should I keep explicit BeginTransaction(), Commit(), Rollback() like the following? public class NHibernateRepository<T> : IRepository<T> { private NHibernate.ISession _session; public NHibernateRepository() { _session = NHibernateSessionManager.Instance...

Domain Driven Design: How to access child of aggregate root

If I have an Order class an as aggregate root and 1000 line items. How do I load just one of the 1000 line items? As far as I understand, a line item can only be accessed through the Order class and has a "local" identity. Would I still create a repository method at the OrderRepository like "GetLineItemById"? Edit to comment the answer...

Best Design Pattern for HttpRequestDispatcher?

Hello, What's the best design pattern to use for an HTTP Request Dispatcher that has to do a "GET" or a "POST", return an output stream, parse the output stream, and then display the parsed results on an interface? Currently, I have an HttpRequestDispatcher.java in which a UI Class is defined in its constructor, and in the threaded run...

How to work with several objects in OpenGL-ES

I am trying to learn how to add several objects and working with those in my 3D-world. I am developing for iPhone. Regarding my question below I couldn't find good information about it while Googling. I have a function that creates all vertices-arrays with data in order to create a sphere. No problem adding it as the only object. The p...

Combined Data from 2 Domain Models

Hello everyone, im trying to implement the Data Gateway / Domain Pattern. I understand the basics and its a fantastic pattern to separate domain logic from the persistent data layer. Now i have following requirement: Lets say i have 2 domain-models: User(s) and Company(ies). When i wanna retrieve a user list with all users, i would do ...

Handling recurrent events

I am building a site that acts as some kind of calendar. I am struggling over finding a way to handle reccurent events, i.e. events that are noted as 'daily,' 'weekly', 'monthly', 'quarterly' and so on... I've tried different approaches, but all end up being way to slow, or unmanageable. I'd like some hints about how I could handle that...