This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main where | |
| import Control.Monad | |
| import Data.List | |
| type Line = [Int] | |
| data Wire = Wire { start :: Int | |
| , end :: Int } deriving Show |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| countCrossings :: TestCase -> Int | |
| countCrossings = length . guardedPairs crosses | |
| -- This is the "pairs" function from the first meeting, with the addition of a | |
| -- predicate function to filter out unwanted pairs | |
| guardedPairs :: (a -> a -> Bool) -> [a] -> [(a,a)] | |
| guardedPairs p xs = [(x,y) | (x:ys) <- tails xs, y <- ys, p x y] | |
| crosses :: Wire -> Wire -> Bool | |
| crosses (Wire s1 e1) (Wire s2 e2) = if s1 < s2 then e1 > e2 else e1 < e2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Find the longest shared prefix of two lists | |
| -- e.g. findPrefix [1,2,3,4] [1,2,3,5] returns [1,2,3] | |
| findPrefix :: (Eq a) => [a] -> [a] -> [a] | |
| findPrefix xs = map fst . takeWhile (uncurry (==)) . zip xs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.example.api; | |
| public interface Greeting { | |
| String sayHello(String name); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.example.impl; | |
| import org.example.api.Greeting; | |
| import aQute.bnd.annotation.component.Component; | |
| @Component | |
| public class BasicGreeting implements Greeting { | |
| public String sayHello(String name) { | |
| return "Hello " + name; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.example.impl; | |
| import junit.framework.TestCase; | |
| public class BasicGreetingTest extends TestCase { | |
| public void testHello() { | |
| assertEquals("Hello Fred", new BasicGreeting().sayHello("Fred")); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.example.gui; | |
| import java.awt.Container; | |
| import java.awt.Dimension; | |
| import java.awt.event.*; | |
| import javax.swing.*; | |
| import org.example.api.Greeting; | |
| import aQute.bnd.annotation.component.*; | |
| @Component |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Reference(type = '?') | |
| public void setLog(LogService log) { | |
| // ... | |
| } | |
| public void unsetLog(LogService log) { | |
| // ... | |
| } | |
| @Reference(type = '*') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| osgi> 2011-10-18 11:28:36 | |
| Full thread dump Java HotSpot(TM) Client VM (14.3-b01 mixed mode): | |
| "[ThreadPool Manager] - Idle Thread" daemon prio=6 tid=0x35668c00 nid=0x1688 in Object.wait() [0x3715f000] | |
| java.lang.Thread.State: WAITING (on object monitor) | |
| at java.lang.Object.wait(Native Method) | |
| - waiting on <0x07220be8> (a org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor) | |
| at java.lang.Object.wait(Object.java:485) | |
| at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:106) | |
| - locked <0x07220be8> (a org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ExampleBundleTest extends TestCase { | |
| private final BundleContext context = FrameworkUtil.getBundle(ExampleBundleTest.class).getBundleContext(); | |
| public void testServiceAvailable() { | |
| // Tests that a specific service exists and can be invoked successfully. | |
| // The service reference is released automatically. | |
| try (ServiceConsumer<MyService> svc = new ServiceConsumer<>(MyService.class, context)) { | |
| assertEquals("Hello Neil", svc.get().sayHello("Neil")); | |
| } |
OlderNewer