pattern

Java Matcher groups: Understanding The difference between "(?:X|Y)" and "(?:X)|(?:Y)"

Can anyone explain: Why the two patterns used below give different results? (answered below) Why the 2nd example gives a group count of 1 but says the start and end of group 1 is -1? public void testGroups() throws Exception { String TEST_STRING = "After Yes is group 1 End"; { Pattern p; Matcher m; String pattern="(?:Y...

Software Architecture: Unit of Work design pattern discussion

Hey everybody. According Martin Fowler's Unit of Work description: "Maintains a list of objects that are affected by a business transaction and coordinates the writing out of changes and resolution of concurrency problems." Avoiding very small calls to the database, which ends up being very slow I'm wondering. If ...

Java Split not working as expected

I am trying to use a simple split to break up the following string: 00-00000 My expression is: ^([0-9][0-9])(-)([0-9])([0-9])([0-9])([0-9])([0-9]) And my usage is: String s = "00-00000"; String pattern = "^([0-9][0-9])(-)([0-9])([0-9])([0-9])([0-9])([0-9])"; String[] parts = s.split(pattern); If I play around with the Pattern and ...

automatic formatting in web page content

i have content stored as raw text in a database that i show in a HTML table on a web site. In the content people refer to numbers and i want to have those numbers automatically become links For example, in a field i might have This description is for driving a car. The manual refers to ABC:25920 and is very durable. In this case ab...

PHP database class pattern questions/suggestions

I am developing my own class model for my database and I would like to know what you guys think of it. For each table in my database I have 2 classes. The first one, is a fetching class (I don't know how to call it..), this class has some static methods interacting with the database (fetchAll, fetchById etc..). The second class is the m...

Transition methods in state design pattern

Hi, I have a state machine with many states A--B--C--D--E. I have many transitions from C for example to A if some condition is verified. For every state I have a class extending abstract class Stateand I have a manager that delegates every transition method to state method. The question is "could states call directly manager transitio...

Double hashing passwords - client & server

Hey, first, let me say, I'm not asking about things like md5(md5(..., there are already topics about it. My question is this: We allow our clients to store their passwords locally. Naturally, we don't want them stored in plan text, so we hmac them locally, before storing and/or sending. Now, this is fine, but if this is all we did, the...

Visual artifacts on UIView rotation with tiled background image.

I have an iPad app with a standard UIViewController/UIView setup - all rotations are allowed. The UIView draws some tiled image as background (the tile is 256*256 pixels): - (void)drawRect:(CGRect)rect { [[UIImage imageNamed: @"Background.png"] drawAsPatternInRect: rect]; } When I turn my iPad I can see that during the rotation th...

ocaml pattern match question

I'm trying to write a simple recursive function that look over list and return a pair of integer. This is easy to write in c/c++/java but i'm new to ocaml so somehow hard to find out the solution due to type conflict it should goes like .. let rec test p l = ... ;; val separate : (’a -> bool) -> ’a list -> int * int = <fun> test (fun ...

Patterns/Best Pratices Parameters WebService

Camarades, I am developing a WebService, and wish to make it accessible to everyone, in all languages in a simple and practical way. For one of the access, I need to send two pieces of information, a token and an XML. In this case, was in doubt, I use parameters: String - String or String - XmlDocument? Well, in other words, my questi...

java filenames filter pattern

Hello, I need to implement File[] files = getFiles( String folderName, String ptrn ); Where ptrn is a command prompt style pattern like "*2010*.txt" I'm familar with FilenameFilter class, but can't implement public boolean accept(File dir, String filename) because String.matches() doesn't accept such patterns. Thanks! ...

JS Proxy Pattern problem

Hi, I use this code to override the window.alert function. The function replaces breaks by \r\n. It works fine in Firefox, but ofcourse not in IE. Im getting the error: Property or method not supported. (function() { var proxied = window.alert; window.alert = function(txt) { txt = txt.replace(/<br>/g, "\r\n"); return proxie...

Repository pattern design considerations

Hi all, I am currently in the process of designing/implementing a repository pattern in a .NET application. After many days of research I feel I am getting close but there really is so many ideas and opinions out there I was hoping to get some peoples thoughts on any design considerations they may have had if you've implemented one your...

How to use case insensitive pattern matching with PostgreSQL and Umlauts?

I'm trying to get PostgreSQL 8.4.3 to do case insensitive pattern matching with its ~* operator when the strings contain non-ASCII characters like German umlauts. The database, terminal, and everything else is configured to use UTF-8. Here's the problem in a nutshell: SELECT 'Ö' ~* 'ö'; -- false There are other variants which do...

Decision making design pattern help

Hey, I have a situation where (pseudo-code): Action a; Object o; if(objectIsPartOfGroup(o, "Group1")) a = treatCaseGroup1(); if(a != indecisive) return a; if(objectIsPartOfGroup(o, "Group2")) a = treatCaseGroup2(); if(a != indecisive) return a; if(objectIsPartOfGroup(o, "Group3")) a = treatCaseGroup3(); if(a != indecisive) ...

UAC and elevation prompt pattern

I've read several questions regarding UAC and privilege elevation but I've not found a satisfactory/comprehensive answer. I have this scenario: on Windows 6 or above, when the user opens a configuration window I have to show the shield (BCM_SETSHIELD) on the OK button only if privilege elevation will be required to complete the task. --...

How to apply Composite-Iterator

I'm trying to figure out how can i merge iterator and composite objects. what can be the best implementation for a struct below. class Composite<Item> : Item { } class Iterator<Item> { } class Iterable<Item> { } ...

A good way to have all my messages in Java

Hello, i'm looking for a small framework to have all my messages stored in a common way. I'll give an example for better understanding. In a part of my code, in a particular JFrame i've an alert something like this: JOptionPane.showMessageDialog(null, "Error, you must provide an integer value", "ERROR", JOptionPane.ERROR_MESSAGE); S...

what design pattern to use for multiple throttled api requests?

I'm writing a web site that uses multiple web services with throttle restrictions. I.e. Amazon is 1 request per second, another is 5000/day another is x/minute. When a user does something, I need to trigger one or more requests to the above services and return the results (to the browser) when available. The solution need to be flexibl...

Alternatives for the singleton pattern?

Hi there, I have been a web developer for some time now using ASP.NET and C#, I want to try and increase my skills by using best practices. I have a website. I want to load the settings once off, and just reference it where ever I need it. So I did some research and 50% of the developers seem to be using the singleton pattern to do t...