Search Results

Search found 7651 results on 307 pages for 'pattern matching'.

Page 7/307 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • java filenames filter pattern

    - by Sergey
    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!

    Read the article

  • Java - is this an idiom or pattern, behavior classes with no state

    - by Berlin Brown
    I am trying to incorporate more functional programming idioms into my java development. One pattern that I like the most and avoids side effects is building classes that have behavior but they don't necessarily have any state. The behavior is locked into the methods but they only act on the parameters passed in. The code below is code I am trying to avoid: public class BadObject { private Map<String, String> data = new HashMap<String, String>(); public BadObject() { data.put("data", "data"); } /** * Act on the data class. But this is bad because we can't * rely on the integrity of the object's state. */ public void execute() { data.get("data").toString(); } } The code below is nothing special but I am acting on the parameters and state is contained within that class. We still may run into issues with this class but that is an issue with the method and the state of the data, we can address issues in the routine as opposed to not trusting the entire object. Is this some form of idiom? Is this similar to any pattern that you use? public class SemiStatefulOOP { /** * Private class implies that I can access the members of the <code>Data</code> class * within the <code>SemiStatefulOOP</code> class and I can also access * the getData method from some other class. * * @see Test1 * */ class Data { protected int counter = 0; public int getData() { return counter; } public String toString() { return Integer.toString(counter); } } /** * Act on the data class. */ public void execute(final Data data) { data.counter++; } /** * Act on the data class. */ public void updateStateWithCallToService(final Data data) { data.counter++; } /** * Similar to CLOS (Common Lisp Object System) make instance. */ public Data makeInstance() { return new Data(); } } // End of Class // Issues with the code above: I wanted to declare the Data class private, but then I can't really reference it outside of the class: I can't override the SemiStateful class and access the private members. Usage: final SemiStatefulOOP someObject = new SemiStatefulOOP(); final SemiStatefulOOP.Data data = someObject.makeInstance(); someObject.execute(data); someObject.updateStateWithCallToService(data);

    Read the article

  • Is scala's cake pattern possible with parametrized components?

    - by Nicolas
    Parametrized components work well with the cake pattern as long as you are only interested in a unique component for each typed component's, example: trait AComponent[T] { val a:A[T] class A[T](implicit mf:Manifest[T]) { println(mf) } } class App extends AComponent[Int] { val a = new A[Int]() } new App Now my application requires me to inject an A[Int] and an A[String], obviously scala's type system doesn't allow me to extends AComponent twice. What is the common practice in this situation ?

    Read the article

  • Command Design Pattern

    - by pchajer
    After reading command design pattern, I have a couple of question - Why we are creating concrete command and receiver object on client. Can't this initialization on invoker class? I think client should create invoker and pass it's request to invoker. Invoker should take care of all the stuff. By doing this, We have less dependency on client. The design of class diagram is totally different from actual design.

    Read the article

  • Are Promises/A a good event design pattern to implement even in synchronous languages like PHP?

    - by Xeoncross
    I have always kept an eye out for event systems when writing code in scripting languages. Web applications have a history of allowing the user to add plugins and modules whenever needed. In most PHP systems you have a global/singleton event object which all interested parties tie into and wait to be alerted to changes. Event::on('event_name', $callback); Recently more patterns like the observer have been used for things like jQuery. $(el).on('event', callback); Even PHP now has built in classes for it. class Blog extends SplSubject { public function save() { $this->notify(); } } Anyway, the Promises/A proposal has caught my eye. It is designed for asynchronous systems, but I'm wondering if it is also a good design to implement now that even synchronous languages like PHP are changing. Combining Dependency Injection with Promises/A seems it might be the best combination for handling events currently.

    Read the article

  • MVC repository pattern design decision

    - by bradjive
    I have an asp .net MVC application and recently started implementing the repository pattern with a service validation layer, much like this. I've been creating one repository/service for each model that I create. Is this overkill? Instead, should I create one repository/service for each logical business area that provides CRUD for many different models? To me, it seems like I'm either cluttering the project tree with many files or cluttering a class with many methods. 6 one way half dozen the other. Can you think of any good arguments either way?

    Read the article

  • Using a Generic Repository pattern with fluent nHibernate

    - by alex
    I'm currently developing a medium sized application, which will access 2 or more SQL databases, on different sites etc... I am considering using something similar to this: http://mikehadlow.blogspot.com/2008/03/using-irepository-pattern-with-linq-to.html However, I want to use fluent nHibernate, in place of Linq-to-SQL (and of course nHibernate.Linq) Is this viable? How would I go about configuring this? Where would my mapping definitions go etc...? This application will eventually have many facets - from a WebUI, WCF Library and Windows applications / services. Also, for example on a "product" table, would I create a "ProductManager" class, that has methods like: GetProduct, GetAllProducts etc... Any pointers are greatly received.

    Read the article

  • Parametrized Strategy Pattern

    - by ott
    I have several Java classes which implement the strategy pattern. Each class has variable number parameters of different types: interface Strategy { public data execute(data); } class StrategyA implements Strategy { public data execute(data); } class StrategyB implements Strategy { public StrategyB(int paramA, int paramB); public data execute(data); } class StrategyB implements Strategy { public StrategyB(int paramA, String paramB, double paramC); public data execute(data); } Now I want that the user can enter the parameters in some kind of UI. The UI should be chosen at runtime, i.e. the strategies should be independent of it. The parameter dialog should not be monolithic and there should be the possibility to make it behave and look different for each strategy and UI (e.g. console or Swing). How would you solve this problem?

    Read the article

  • myth about factory pattern

    - by leiz
    This has bothered me for awhile, and I have no clues if this is a myth. It seems that a factory pattern can ease the pain of adding a dependency for a class. For example, in a book, it has something like this Suppose that you have a class named Order. Initially it did not depend on anything. Therefore you didn't bother using a factory to create Order objects and you just used plain new to instantiate the objects. However, you now have a requirement that Order has to be created in association with a Customer. There are million places you need to change to add this extra parameter. If only you had de?ned a factory for the Order class, you would have met the new requirement without the same pain. How is this not same pain as adding an extra parameter to the constructor? I mean you would still need to provide an extra argument for the factory and that is also used by million places, right?

    Read the article

  • C# ProgressBar design pattern

    - by MadSeb
    Hi, I'm working on a database upgrader application. The upgrader updates the schema of a database ( adds new columns, renames columns , adds new tables, new views to an existing database by executing SQL statements ). When a user wants to upgrade from version 1.0 to 2.0 , "Upgrader" objects are taken from an object factory and the "Execute" method of each "Upgrader" is called. The GUI of the application has a progress bar and each time an upgrader object performs a SQL statement the progress bar gets incremented. while (!version.Equal(CurrentVersion)) { IUpgrader myUpgrader = UpgraderFactory.GetUpgrader(version); myUpgrader.Execute(UpgradedFile,progressbar); version.Increment(); } My question is very simple : how should the upgrader object communicate with the progressbar. In the code above, the upgrader object is given direct access to the progressbar but I'm wondering if some better way of doing this or better design pattern exists. Regards, Seb

    Read the article

  • makefile pattern rules: single wildcard, multiple instances in prerequisite

    - by johndashen
    Hi all, hopefully this is a basic question about make pattern rules: I want to use a wildcard more than once in a prerequisite for a rule, i.e. in my Makefile I have data/%P1.m: $(PROJHOME)/data/%/ISCAN/%P1.RAW @echo " Writing temporary matlab file for $*" # do something data/%P2.m: $(PROJHOME)/data/%/ISCAN/AGP2.RAW @echo " Writing temporary matlab file for $*" # do something In this example, I try to invoke make when the wildcard % is AG. Both files $(PROJHOME)/data/AG/ISCAN/AGP1.RAW and $(PROJHOME)/data/AG/ISCAN/AGP2.RAW exist. I attempt the following make commands and get this output: [jshen@iLab10 gender-diffs]$ make data/AGP1.m make: *** No rule to make target `data/AGP1.m'. Stop. [jshen@iLab10 gender-diffs]$ make data/AGP2.m Writing temporary matlab file for AG, part 2... [jshen@iLab10 gender-diffs]$ ls data/AG/ISCAN/AG* data/AG/ISCAN/AGP1.RAW data/AG/ISCAN/AGP2.RAW How can I implement multiple instances of the same wildcard in the first make rule?

    Read the article

  • augment the factory pattern in java

    - by TP
    I am trying to use a factory pattern to create a QuestionTypeFactory where the instantiated classes will be like MultipleChoice, TrueFalseQuestion etc. The factory code looks something like this class QuestionFactory { public enum QuestionType { TrueFalse, MultipleChoice, Essay } public static Question createQuestion(QuestionType quesType) { switch (quesType) { case TrueFalse: return new TrueFalseQuestion(); case MultipleChoice: return new MultipleChoiceQuestion(); case Essay: return new EssayQuestion(); } throw new IllegalArgumentException("Not recognized."); } } This works ok for now. If I want to add another question type I will need to modify the factory class and I do not want to do that. How can I set it up so that each question class registers itself with the Factory so that when I add a new question type, I do not have to change the code for the factory? I am a bit new to java and am not sure how to do this.

    Read the article

  • State pattern: Why doesn't the context class implement or inherit the State abstract interface/class

    - by Ricket
    I'm reading about the State pattern. I have only just begun, so of course I begin by reading the entire Wikipedia article on it. I noticed that both of the examples in the article have some base abstract class or Java interface for a generic State's methods/functions. Then there are some states which inherit from the base and implement those methods/functions in different ways. Then there's a Context class which has a private member of type State and which, at any time, can be equal to an instance of one of the implementations. That context class also implements the same methods, and passes them onto the current state instance, and then has an additional method to change the state (or depending on design I understand the change of state could be a reaction to one of the implemented methods). Why doesn't this context class specifically "extend" or "implement" the generic State base class/interface?

    Read the article

  • C++ visitor pattern handling templated string types?

    - by Steve the Plant
    I'm trying to use the visitor pattern to serialize the contents of objects. However one snag I'm hitting is when I'm visiting strings. My strings are of a templated type, similar to STL's basic_string. So something like: basic_string<char_type, memory_allocator, other_possible_stuff> \\ many variations possible! Since I can have very many different templated string types, I can't go and add them to my visitor interface. It would be ridiculous. But I can't add templates to my VisitString method because C++ prevents using templates parameters in virtual methods. So what are my options to work around this?

    Read the article

  • XSD string pattern independent of leading/trailing space

    - by AndiDog
    I have a XSD simple type that should match UUIDs: <simpleType name="UuidT"> <restriction base="string"> <pattern value="[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}" /> </restriction> </simpleType> It correctly matches the following content: <!-- valid --> <Uuid>12345678-1234-5678-9012-123456789012</Uuid> But it doesn't match content that contains excess whitespace: <!-- not valid --> <Uuid> 2de25a81-b117-4b2a-b910-50f0878884f7 </Uuid> Sure, I could add \s* to both sides of the regex, but isn't there a simpler solution in XSD?

    Read the article

  • LLBLGen and the repository pattern

    - by user137348
    I was wondering if building a repository on the top LLBLGen (adapter) is a good idea. I don't want to overengineer and reinvent the wheel again. The DataAccessAdapter class could be some kind of a generic repository.It has all the CRUD methods you need. But on the other side for a larger project it could be good to have a layer between your ORM and service layer. I'd like to hear your opinions, if your using the repository pattern with LLBLGen,if yes why if no why not. If you have some implementation, post it please.

    Read the article

  • what is the pattern for modifying a collection in C#

    - by macias
    What is the pattern (best practice) for such problem -- modifying elements (values) in collection? Conditions: size of the collection is not changed (no element is deleted or added) modification is in-place In C++ it was easy and nice, I just iterated trough a collection and changed the elements. But in C# iterating (using enumerator) is read-only operation (speaking in terms of C++, only const_iterator is available). So, how to do this in C#? Example: having sequence of "1,2,3,4" modification is changing it to "1, 2, 8, 9" but not "1, 2, 3" or "1, 2, 3, 4, 5".

    Read the article

  • Graphic editor opensource project example on c++ underlying composite pattern

    - by G-71
    Can you tell me when I can see a some opensource project (only project on C++ language), which is simple graphic editor, ?ontaining following primitive (for example): an ellipse, a rectangle, a line. And desirable, that to be able to group this primitive in one primitive (for example, Word Grouping - Group). Composite pattern use is desirable in this project. I want to see how to organize classes, but more serious for me is to see how organize grouping operation. I searched for it on codeproject.com codeproject.com, codeplex.com, but not found this. I have already some source http://pastebin.com/xe4JF5PW But in my opinion, this code is dirty and ugly. Therefore, I want to see some opensource project for example. Thanks!

    Read the article

  • Entity framework using Data Repository pattern

    - by JamesStuddart
    Hi all, I have been implementing a new project which I have decided to use the repository pattern and Entity Framework. I have sucessfuly implemented basic CRUD methods and I have no moved onto my DeepLoads. From all the examples and documentation I can find to do this I need to call something like this: public Foo DeepLoadFoo() { return (from foobah in Context.Items.Include("bah").Include("foo").Include("foofoo") select foo).Single(); } This doesnt work for me, maybe I am trying to be too lazy but what I would like to achieve would be something along the lines of this: public Foo DeepLoadFoo(Foo entity, Type[] childTypes) { return (from foobah in Context.Items.Include(childTypes).Single(); } Is anything like this possible, or am I stuck with include.include.include.include? Thanks

    Read the article

  • Composite pattern in C++ problem

    - by annouk
    Hello! I have to work with an application in C++ similar to a phone book: the class Agenda with an STL list of Contacts.Regarding the contacts hierarchy,there is a base-class named Contact(an abstract one),and the derived classes Friend and Acquaintance(the types of contact). These classes have,for instance, a virtual method called getName,which returns the name of the contact. Now I must implement the Composite pattern by adding another type of contact,Company(being derived from Contact),which also contains a collection of Contacts(an STL list as well),that can be either of the "leaf" type(Friends or Acquaintances),or they can be Companies as well. Therefore,Company is the Compound type. The question is: how and where can I implement an STL find_if to search the contact with a given name(via getName function or suggest me smth else) both among the "leaf"-type Contact and inside the Company collection? In other words,how do I traverse the tree in order to find possible matches there too,using an uniform function definition? I hope I was pretty clear...

    Read the article

  • Exception handling pattern

    - by treefrog
    It is a common pattern I see where the error codes associated with an exception are stored as Static final ints. when the exception is created to be thrown, it is constructed with one of these codes along with an error message. This results in the method that is going to catch it having to look at the code and then decide on a course of action. The alternative seems to be- declare a class for EVERY exception error case Is there a middle ground ? what is the recommended method ?

    Read the article

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

    - by user358795
    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="(?:Yes|No)(.*)End"; p=Pattern.compile(pattern); m=p.matcher(TEST_STRING); boolean f=m.find(); int count=m.groupCount(); int start=m.start(1); int end=m.end(1); System.out.println("Pattern=" + pattern + "\t Found=" + f + " Group count=" + count + " Start of group 1=" + start + " End of group 1=" + end ); } { Pattern p; Matcher m; String pattern="(?:Yes)|(?:No)(.*)End"; p=Pattern.compile(pattern); m=p.matcher(TEST_STRING); boolean f=m.find(); int count=m.groupCount(); int start=m.start(1); int end=m.end(1); System.out.println("Pattern=" + pattern + "\t Found=" + f + " Group count=" + count + " Start of group 1=" + start + " End of group 1=" + end ); } } Which gives the following output: Pattern=(?:Yes|No)(.*)End Found=true Group count=1 Start of group 1=9 End of group 1=21 Pattern=(?:Yes)|(?:No)(.*)End Found=true Group count=1 Start of group 1=-1 End of group 1=-1

    Read the article

  • MVC pattern and (Game) State pattern

    - by topright
    Game States separate I/O processing, game logic and rendering into different classes: while (game_loop) { game->state->io_events(this); game->state->logic(this); game->state->rendering(); } You can easily change a game state in this approach. MVC separation works in more complex way: while (game_loop) { game->cotroller->io_events(this); game->model->logic(this); game->view->rendering(); } So changing Game States becomes error prone task (switch 3 classes, not 1). What are practical ways of combining these 2 concepts?

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >