RouteCompilerImpl implements RouteCompiler { public CompiledRoute compile(Route route) { CompiledRoute compiledRoute = new CompiledRoute(); compiledRoute.weight = route.weight; List<String> variables = detectVariables(route); compiledRoute.setVariables(variables); compiledRoute.setAnchor(route.getAnchor()); compiledRoute.setType(Route.TYPE_DIRECTLY); compiledRoute.setActivityClass(route.getActivityClass().getName()); if (variables == null || variables.size() < 1) { String constantUrl = route.getPath(); if (route.getAnchor() != null) { constantUrl += "#" + route.getAnchor(); } compiledRoute.setConstantUrl(constantUrl); } else { String regexString = compileRegex(route, variables); compiledRoute.setRegex(Pattern.compile(regexString)); } if (route.getProxyDestIdentify() != null) { compiledRoute.setType(Route.TYPE_PROXY); } if (route.getMiddlewares() != null && route.getMiddlewares().size() > 0) { ArrayList<String> fragmentClassNames = new ArrayList<>(); for (Class clazz : route.getMiddlewares()) { fragmentClassNames.add(clazz.getName()); } compiledRoute.setMiddlewares(fragmentClassNames); compiledRoute.setType(Route.TYPE_PROXY); } return compiledRoute; }  CompiledRoute compile(Route route); static List<String> detectVariables(Route route); static String compileRegex(Route route, List<String> variables); static String quote(String str);  }
@Test public void testParcel() { Parcel parcel = Parcel.obtain(); CompiledRoute compiledRoute = new CompiledRoute(); compiledRoute.setVariables(Arrays.asList("vendor", "repository")) .setRegex(Pattern.compile("hello")) .setConstantUrl("constantUrl") .setType(Route.TYPE_DIRECTLY) .setActivityClass(Activity.class.getName()) .setProxyDestIdentify("ha") .setMiddlewares(Arrays.asList("a", "b")) .setAnchor("comments") .setSchemes(Arrays.asList("vendor", "repository")); compiledRoute.writeToParcel(parcel, 0); parcel.setDataPosition(0); CompiledRoute compiledRouteFromParcel = new CompiledRoute(parcel); assertTrue("-> test parcelable", compiledRoute.equals(compiledRouteFromParcel)); assertEquals("b", compiledRoute.getNextMiddleware("a")); assertNull(compiledRoute.getNextMiddleware("b")); assertNull(compiledRoute.getNextMiddleware("c")); }