List of usage examples for com.google.common.collect ImmutableList of
public static <E> ImmutableList<E> of(E e1, E e2)
From source file:com.spotify.folsom.KetamaRunner.java
public static void main(final String[] args) throws Throwable { ImmutableList<HostAndPort> addresses = ImmutableList.of(HostAndPort.fromParts("127.0.0.1", 11211), HostAndPort.fromParts("127.0.0.1", 11213)); final BinaryMemcacheClient<String> client = new MemcacheClientBuilder<>(StringTranscoder.UTF8_INSTANCE) .withAddresses(addresses).connectBinary(); for (int i = 0; i < 10; i++) { final String key = "key" + i; final String value = "value" + i; checkKeyOkOrNotFound(client.delete(key)); client.set(key, value, 1000);// w ww . j a v a 2 s . co m System.out.println(client.get(key).get()); } client.shutdown(); }
From source file:ch.ledcom.log4jtools.GraphLoggers.java
/** * @param args//w w w. j a v a 2s . com * @throws IOException */ public static void main(final String[] args) throws IOException { List<String> categories = ImmutableList.of("com", "org"); File logFile = new File("/home/glederre/logs/problems.xml"); LoggerSetExtractor loggerSetProcessor = new LoggerSetExtractor(); GraphingProcessor graphingProcessor = new GraphingProcessor(categories, "/home/glederre/logs/rrd/test"); List<LogProcessor> processors = new ArrayList<LogProcessor>(); processors.add(loggerSetProcessor); processors.add(graphingProcessor); LogFileXMLReader reader = new LogFileXMLReader(processors); reader.process(new BufferedReader(new FileReader(logFile)), "hqhcecom", "prod"); graphingProcessor.close(); Set<String> loggers = loggerSetProcessor.getLoggers(); for (String logger : loggers) { System.out.println(logger); } RrdGraphDef gDef = new RrdGraphDef(); gDef.setWidth(500); gDef.setHeight(300); gDef.setFilename("/home/glederre/logs/test.png"); gDef.setStartTime(graphingProcessor.getFirstSample().getTime()); gDef.setEndTime(graphingProcessor.getLastSample().getTime()); gDef.setTitle("My Title"); gDef.setVerticalLabel("occ"); for (String category : categories) { gDef.datasource("occ", "/home/glederre/logs/rrd/test", category, AVERAGE); } gDef.hrule(2568, Color.GREEN, "hrule"); gDef.setImageFormat("png"); RrdGraph graph = new RrdGraph(gDef); }
From source file:org.glowroot.agent.ui.sandbox.UiSandboxMain.java
public static void main(String[] args) throws Exception { Container container;/*w w w .j av a 2 s . c o m*/ File testDir = new File("target"); File configFile = new File(testDir, "config.json"); if (!configFile.exists()) { Files.write("{\"transactions\":{\"profilingIntervalMillis\":100}," + "\"ui\":{\"defaultTransactionType\":\"Sandbox\"}}", configFile, UTF_8); } if (useJavaagent && useGlowrootCentral) { container = new JavaagentContainer(testDir, false, ImmutableList.of("-Dglowroot.agent.id=UI Sandbox", "-Dglowroot.collector.address=localhost:8181")); } else if (useJavaagent) { container = new JavaagentContainer(testDir, true, ImmutableList.<String>of()); } else if (useGlowrootCentral) { container = new LocalContainer(testDir, false, ImmutableMap.of("glowroot.agent.id", "UI Sandbox", "glowroot.collector.address", "localhost:8181")); } else { container = new LocalContainer(testDir, true, ImmutableMap.<String, String>of()); } container.executeNoExpectedTrace(GenerateTraces.class); }
From source file:org.garethaye.minimax.tic_tac_toe.TicTacToeClient.java
public static void main(String[] args) throws TException { BasicConfigurator.configure();/*from w ww.j av a 2s . co m*/ TTransport transport = new TFramedTransport(new TSocket("localhost", 4200)); Minimax.Client client = new Minimax.Client(new TBinaryProtocol(transport)); transport.open(); System.out.println(System.currentTimeMillis()); Move move = client.getMove("localhost", 4201, new GameState(GameState._Fields.TIC_TAC_TOE_GAME_STATE, new TicTacToeGameState(getBoard())), ImmutableList.of(1, 2), 1); System.out.println(System.currentTimeMillis()); LOGGER.info(move.toString()); transport.close(); }
From source file:net.corda.vega.SwapExampleX.java
public static void main(String[] args) { CurveGroupDefinition curveGroupDefinition = loadCurveGroup(); MarketData marketData = loadMarketData(); List<SwapTrade> trades = ImmutableList.of(createVanillaFixedVsLibor3mSwap(), createVanillaFixedVsLibor6mSwap()); CurveCalibrator calibrator = CurveCalibrator.of(1e-9, 1e-9, 100, CalibrationMeasures.PAR_SPREAD); ImmutableRatesProvider ratesProvider = calibrator.calibrate(curveGroupDefinition, marketData, ReferenceData.standard());//from w ww .ja va 2 s . co m MarketDataFxRateProvider fxRateProvider = MarketDataFxRateProvider.of(marketData); ImmutableRatesProvider combinedRatesProvider = ImmutableRatesProvider.combined(fxRateProvider, ratesProvider); List<ResolvedSwapTrade> resolvedTrades = trades.stream() .map(trade -> trade.resolve(ReferenceData.standard())).collect(toList()); DiscountingSwapProductPricer pricer = DiscountingSwapProductPricer.DEFAULT; CurrencyParameterSensitivities totalSensitivities = CurrencyParameterSensitivities.empty(); MultiCurrencyAmount totalCurrencyExposure = MultiCurrencyAmount.empty(); for (ResolvedSwapTrade resolvedTrade : resolvedTrades) { ResolvedSwap swap = resolvedTrade.getProduct(); PointSensitivities pointSensitivities = pricer.presentValueSensitivity(swap, combinedRatesProvider) .build(); CurrencyParameterSensitivities sensitivities = combinedRatesProvider .parameterSensitivity(pointSensitivities); MultiCurrencyAmount currencyExposure = pricer.currencyExposure(swap, combinedRatesProvider); totalSensitivities = totalSensitivities.combinedWith(sensitivities); totalCurrencyExposure = totalCurrencyExposure.plus(currencyExposure); } //PortfolioNormalizer normalizer = new PortfolioNormalizer(Currency.EUR, combinedRatesProvider); //RwamBimmNotProductClassesCalculator calculatorTotal = new RwamBimmNotProductClassesCalculator( // fxRateProvider, // Currency.EUR, // IsdaConfiguration.INSTANCE); // //Triple<Double, Double, Double> margin = BimmAnalysisUtils.computeMargin( // combinedRatesProvider, // normalizer, // calculatorTotal, // totalSensitivities, // totalCurrencyExposure); // //System.out.println(margin); }
From source file:com.metamx.tranquility.example.JavaExample.java
public static void main(String[] args) { final String indexService = "druid/overlord"; // Your overlord's druid.service final String discoveryPath = "/druid/discovery"; // Your overlord's druid.discovery.curator.path final String dataSource = "foo"; final List<String> dimensions = ImmutableList.of("bar", "qux"); final List<AggregatorFactory> aggregators = ImmutableList.of(new CountAggregatorFactory("cnt"), new LongSumAggregatorFactory("baz", "baz")); // Tranquility needs to be able to extract timestamps from your object type (in this case, Map<String, Object>). final Timestamper<Map<String, Object>> timestamper = new Timestamper<Map<String, Object>>() { @Override//w w w. jav a 2s .com public DateTime timestamp(Map<String, Object> theMap) { return new DateTime(theMap.get("timestamp")); } }; // Tranquility uses ZooKeeper (through Curator) for coordination. final CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("zk.example.com:2181") .retryPolicy(new ExponentialBackoffRetry(1000, 20, 30000)).build(); curator.start(); // The JSON serialization of your object must have a timestamp field in a format that Druid understands. By default, // Druid expects the field to be called "timestamp" and to be an ISO8601 timestamp. final TimestampSpec timestampSpec = new TimestampSpec("timestamp", "auto", null); // Tranquility needs to be able to serialize your object type to JSON for transmission to Druid. By default this is // done with Jackson. If you want to provide an alternate serializer, you can provide your own via ```.objectWriter(...)```. // In this case, we won't provide one, so we're just using Jackson. final Tranquilizer<Map<String, Object>> druidService = DruidBeams.builder(timestamper).curator(curator) .discoveryPath(discoveryPath).location(DruidLocation.create(indexService, dataSource)) .timestampSpec(timestampSpec) .rollup(DruidRollup.create(DruidDimensions.specific(dimensions), aggregators, QueryGranularity.MINUTE)) .tuning(ClusteredBeamTuning.builder().segmentGranularity(Granularity.HOUR) .windowPeriod(new Period("PT10M")).partitions(1).replicants(1).build()) .buildTranquilizer(); druidService.start(); try { // Build a sample event to send; make sure we use a current date Map<String, Object> obj = ImmutableMap.<String, Object>of("timestamp", new DateTime().toString(), "bar", "barVal", "baz", 3); // Send event to Druid: final Future<BoxedUnit> future = druidService.send(obj); // Wait for confirmation: Await.result(future); } catch (Exception e) { log.warn(e, "Failed to send message"); } finally { // Close objects: druidService.stop(); curator.close(); } }
From source file:com.google.devtools.build.xcode.xcodegen.XcodeGen.java
public static void main(String[] args) throws IOException, OptionsParsingException { OptionsParser parser = OptionsParser.newOptionsParser(XcodeGenOptions.class); parser.parse(args);//from ww w . jav a 2 s .co m XcodeGenOptions options = parser.getOptions(XcodeGenOptions.class); if (options.control == null) { throw new IllegalArgumentException( "--control must be specified\n" + Options.getUsage(XcodeGenOptions.class)); } FileSystem fileSystem = FileSystems.getDefault(); Control controlPb; try (InputStream in = Files.newInputStream(fileSystem.getPath(options.control))) { controlPb = Control.parseFrom(in); } Path pbxprojPath = fileSystem.getPath(controlPb.getPbxproj()); Iterator<String> srcList = allSourceFilePaths(controlPb).iterator(); Path workspaceRoot; // TODO(bazel-team): Remove this if-else clause once Bazel passes in the workspace root. if (controlPb.hasWorkspaceRoot()) { workspaceRoot = fileSystem.getPath(controlPb.getWorkspaceRoot()); } else if (!srcList.hasNext()) { workspaceRoot = XcodeprojGeneration.relativeWorkspaceRoot(pbxprojPath); } else { // Get the absolute path to the workspace root. // TODO(bazel-team): Remove this hack, possibly by converting Xcodegen to be run with // "bazel run" and using RUNFILES to get the workspace root. For now, this is needed to work // around Xcode's handling of symlinks not playing nicely with how Bazel stores output // artifacts in /private/var/tmp. This means a relative path from .xcodeproj in bazel-out to // the workspace root in .xcodeproj will not work properly at certain times during // Xcode/xcodebuild execution. Walking up the path of a known source file prevents having // to reason about a file that might only be accessible through a symlink, like a tools jar. Path relSourceFilePath = fileSystem.getPath(srcList.next()); Path absSourceFilePath = relSourceFilePath.toAbsolutePath(); workspaceRoot = absSourceFilePath; for (int i = 0; i < relSourceFilePath.getNameCount(); i++) { workspaceRoot = workspaceRoot.getParent(); } } try (OutputStream out = Files.newOutputStream(pbxprojPath)) { // This workspace root here is relative to the PWD, so that the .xccurrentversion // files can actually be read. The other workspaceRoot is relative to the .xcodeproj // root or is absolute. Path relativeWorkspaceRoot = fileSystem.getPath("."); PBXProject project = XcodeprojGeneration.xcodeproj(workspaceRoot, controlPb, ImmutableList .of(new CurrentVersionSetter(relativeWorkspaceRoot), new PbxReferencesGrouper(fileSystem))); XcodeprojGeneration.write(out, project); } }
From source file:examples.Library.java
public static String SayHello() { return Joiner.on(" ").join(ImmutableList.of("Hello", "World")); }
From source file:org.sonar.plugins.ndepend.NdependProvider.java
public static List extensions() { return ImmutableList.of(NdependRulesDefinition.class, NdependSensor.class); }
From source file:com.google.devtools.build.lib.packages.util.BazelMockAndroidSupport.java
public static void setupNdk(MockToolsConfig config) throws IOException { new Crosstool(config, "android/crosstool") .setCrosstoolFile(/*version=*/ "mock_version", ResourceFileLoader.loadResource(BazelMockAndroidSupport.class, "MOCK_ANDROID_CROSSTOOL")) .setSupportedArchs(ImmutableList.of("x86", "armeabi-v7a")).setSupportsHeaderParsing(false).write(); }