Skip to content

Commit

Permalink
Groomed code. Mostly formatting stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
gazbert committed Feb 27, 2016
1 parent 2bfa529 commit b33e10d
Show file tree
Hide file tree
Showing 151 changed files with 4,857 additions and 4,696 deletions.
Original file line number Diff line number Diff line change
@@ -1,60 +1,61 @@
package com.gazbert.patterns.behavioural.chainofresponsibility;

/*The MIT License (MIT)
Copyright (c) 2014 Gazbert
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Gareth Jon Lynch
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
package com.gazbert.patterns.behavioural.chainofresponsibility;

/**
*
* Provides the default functionality and 2 operations for subclasses to provide implementations for:
* Provides the default functionality and 2 operations for subclasses to provide implementations for:
* <br>
* (1) deciding if they want to review the document.
* <br>
* (2) method to call to review the document.
* <p>
* Consumers of the pattern call the reviewDocument() method.
*
* @author gazbert
*
* @author gazbert
*/
public abstract class AbstractDocumentReviewHandler implements DocumentReviewHandler {

/** Here for our test assertions to track who's reviewed the document */
/**
* Here for our test assertions to track who's reviewed the document
*/
private static String handledBy = "";

/**
* Holds reference to the next Handler/Receiver.
*/
private DocumentReviewHandler nextHandler;
private DocumentReviewHandler nextHandler;

/**
* Consumers of the pattern call this method to do stuff.
* <p>
* This is the business method.
* <p>
* In this case, JIRA/Bugzilla would call this with the document to review...
*
* @param document
*
* @param document the doc to review
*/
public static void reviewDocumentRequest(final String document)
{
public static void reviewDocumentRequest(String document) {
// Create the handlers/receivers
final DocumentReviewHandler supportReviewHandler = new SupportReviewHandler();
final DocumentReviewHandler salesReviewHandler = new SalesReviewHandler();
Expand All @@ -64,16 +65,16 @@ public static void reviewDocumentRequest(final String document)
// Chain em together - totally random order of chaining here ;-)
supportReviewHandler.setNextHandler(salesReviewHandler);
salesReviewHandler.setNextHandler(engineeringReviewHandler);
engineeringReviewHandler.setNextHandler(testingReviewHandler);
engineeringReviewHandler.setNextHandler(testingReviewHandler);
testingReviewHandler.setNextHandler(null); // see NullObjectPattern for better way of 'ending' stuff

// New review request comes in and gets routed to support team first...
supportReviewHandler.processHandler(document);
}

@Override
public void setNextHandler(final DocumentReviewHandler handler) {
this.nextHandler = handler;
public void setNextHandler(DocumentReviewHandler handler) {
this.nextHandler = handler;
}


Expand All @@ -87,51 +88,47 @@ public void processHandler(String document) {
boolean wordFound = false;

// check for matching words for this Handler
for (String word : getSelectionCriteria())
{
if (document.indexOf(word) >= 0)
{
for (String word : getSelectionCriteria()) {
if (document.contains(word)) {
wordFound = true;
break;
}
}
}

// Do the handling if we need to...
if (wordFound)
{
if (wordFound) {
handledBy = reviewDocument(document);
}
else
{
} else {
// Check if next Receiver 'wants it'... ;-o
if (null != nextHandler)
{
if (null != nextHandler) {
nextHandler.processHandler(document);
}
}
}

/**
* Only here for unit test code to assert stuff with sake of this demo.
* @return
*
* @return handledBy
*/
public static String getHandledBy()
{
return handledBy;
public static String getHandledBy() {
return handledBy;
}

///////////////////// Subclass contract for the concrete Handlers ////////////////////////

/**
* This is where we ask each Handler for its document review selection criteria.
* @return
*
* @return selection criteria
*/
protected abstract String[] getSelectionCriteria();

/**
* This is where we send the document to interested Handlers.
* @param document
*
* @param document the doc
* @return department that reviewed the document
*/
*/
protected abstract String reviewDocument(String document);
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package com.gazbert.patterns.behavioural.chainofresponsibility;

/*The MIT License (MIT)
Copyright (c) 2014 Gazbert
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Gareth Jon Lynch
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
package com.gazbert.patterns.behavioural.chainofresponsibility;

/**
* Provides operations that each concrete Handler impl must provide.
Expand All @@ -32,13 +34,13 @@ public interface DocumentReviewHandler {
/**
* Sets the next handler. The abstract impl usually calls this instead of each concrete impl.
*
* @param handler
* @param handler the doc review handler.
*/
void setNextHandler(DocumentReviewHandler handler);

/**
* Each handler provides its own impl to do something with the message.
* @param document
* @param document the doc.
*/
void processHandler(String document);
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package com.gazbert.patterns.behavioural.chainofresponsibility;

/*The MIT License (MIT)
Copyright (c) 2014 Gazbert
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Gareth Jon Lynch
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
package com.gazbert.patterns.behavioural.chainofresponsibility;

/**
* Handler for Engineering team.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Gareth Jon Lynch
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.gazbert.patterns.behavioural.chainofresponsibility;

/*The MIT License (MIT)
Copyright (c) 2014 Gazbert
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/

/**
* Handler for Sales team.
*
Expand Down
Loading

0 comments on commit b33e10d

Please sign in to comment.