List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:eu.cloudwave.wp5.feedbackhandler.controller.PlotController.java
@RequestMapping(Urls.PLOTS_PROCEDURE) @ResponseStatus(HttpStatus.OK)/* w w w . j a va2 s .c o m*/ public ModelAndView procedure( @RequestHeader(value = Headers.ACCESS_TOKEN, required = false) final String accessToken, @RequestHeader(value = Headers.APPLICATION_ID, required = false) final String applicationId, @RequestParam(Params.CLASS_NAME) final String className, @RequestParam(Params.PROCEDURE_NAME) final String procedureName, @RequestParam(Params.ARGUMENTS) final String arguments) { final DbApplication application = handleUnauthorized(applicationId, accessToken); final String[] procedureArguments = Iterables.toArray(Splitters.onComma(arguments), String.class); final List<? extends ProcedureExecutionMetric> metrics = metricRepository.find(application, className, procedureName, procedureArguments); final Procedure procedure = metrics.size() > 0 ? metrics.get(0).getProcedure() : new ProcedureImpl(className, procedureName, null, Lists.newArrayList(procedureArguments), Lists.newArrayList()); final ModelAndView model = new ModelAndView(PROCEDURE_PLOT); final String[] formattedData = formatData(metrics); model.addObject(Attributes.PROCEDURE, procedure); model.addObject(Attributes.DATA_EXECUTION_TIME, formattedData[0]); model.addObject(Attributes.DATA_CPU_USAGE, formattedData[1]); return model; }
From source file:org.icgc.dcc.submission.validation.cascading.StructuralCheckFunction.java
@SuppressWarnings("unchecked") public StructuralCheckFunction(Iterable<String> fieldNames) { super(1);// ww w . ja va 2 s. c o m dictionaryFields = new Fields(Iterables.toArray(fieldNames, String.class)); headerSize = dictionaryFields.size(); fieldDeclaration = dictionaryFields.append(ValidationFields.STATE_FIELD); }
From source file:org.vclipse.vcml.ui.outline.TypeFilterAction.java
@Override public void run() { List<ViewerFilter> filters = Lists.newArrayList(treeViewer.getFilters()); if (filters.contains(filter) && stateEnabled) { filters.remove(filter);/*from www . j ava2 s . c o m*/ setImageDescriptor(disabled); stateEnabled = false; } else { filters.add(this.filter); setImageDescriptor(enabled); stateEnabled = true; } treeViewer.setFilters(Iterables.toArray(filters, ViewerFilter.class)); }
From source file:com.comphenix.protocol.events.PacketAdapter.java
/** * Initialize a packet listener with the given parameters. * @param plugin - the plugin.// www . j a v a2 s. c o m * @param types - the packet types. */ public PacketAdapter(Plugin plugin, Iterable<? extends PacketType> types) { this(params(plugin, Iterables.toArray(types, PacketType.class))); }
From source file:monasca.api.app.validation.Validation.java
/** * @throws WebApplicationException if the {@code value} is null or empty. *//*from w ww.j a v a2s .c om*/ public static Map<String, String> parseAndValidateDimensions(String dimensionsStr) { Validation.validateNotNullOrEmpty(dimensionsStr, "dimensions"); Map<String, String> dimensions = new HashMap<String, String>(); for (String dimensionStr : COMMA_SPLITTER.split(dimensionsStr)) { String[] dimensionArr = Iterables.toArray(COLON_SPLITTER.split(dimensionStr), String.class); if (dimensionArr.length == 1) { DimensionValidation.validateName(dimensionArr[0]); dimensions.put(dimensionArr[0], ""); } else if (dimensionArr.length > 1) { DimensionValidation.validateName(dimensionArr[0]); if (dimensionArr[1].contains("|")) { List<String> dimensionValueArr = VERTICAL_BAR_SPLITTER.splitToList(dimensionArr[1]); for (String dimensionValue : dimensionValueArr) { DimensionValidation.validateValue(dimensionValue, dimensionArr[0]); } } else { DimensionValidation.validateValue(dimensionArr[1], dimensionArr[0]); } dimensions.put(dimensionArr[0], dimensionArr[1]); } } //DimensionValidation.validate(dimensions); return dimensions; }
From source file:org.schedoscope.export.ftp.FtpExportCSVMapper.java
@Override protected void map(WritableComparable<?> key, HCatRecord value, Context context) throws IOException, InterruptedException { List<TextPairWritable> items = new ArrayList<TextPairWritable>(); for (String f : inputSchema.getFieldNames()) { String fieldValue = ""; Object obj = value.get(f, inputSchema); if (obj != null) { if (inputSchema.get(f).isComplex()) { fieldValue = serializer.getFieldAsJson(value, f); } else { fieldValue = obj.toString(); fieldValue = HCatUtils.getHashValueIfInList(f, fieldValue, anonFields, salt); }//w ww . j av a 2 s . c om } TextPairWritable item = new TextPairWritable(f, fieldValue); items.add(item); } TextPairArrayWritable record = new TextPairArrayWritable(Iterables.toArray(items, TextPairWritable.class)); LongWritable localKey = new LongWritable(context.getCounter(TaskCounter.MAP_INPUT_RECORDS).getValue()); context.write(localKey, record); }
From source file:name.marcelomorales.siqisiqi.pdfbox.CoordinatesGenerator.java
public void generarPdf(OutputStream os, String template, Map<String, Object> m, String path, String coordenates, float fontSize, float ancho) throws IOException { long t = System.currentTimeMillis(); PDDocument doc = null;/*from ww w . j a v a 2s. c o m*/ try { doc = PDDocument.load(new File(path)); List pages = doc.getDocumentCatalog().getAllPages(); PDPage sourcePage = (PDPage) pages.get(0); boolean append = sourcePage.getContents() != null; PDPageContentStream contentStream = new PDPageContentStream(doc, sourcePage, append, true); StringReader fileReader = null; try { fileReader = new StringReader(template); List<String> list = CharStreams.readLines(fileReader); boolean textHasBegun = false; float currentOffset = 0f; for (String line : list) { if (line == null) { continue; } if (line.startsWith("#")) { continue; } final Iterable<String> str = Splitter.on(',').omitEmptyStrings().trimResults().split(line); final String[] split = Iterables.toArray(str, String.class); if (split == null || split.length < 4) { continue; } if (Character.isDigit(split[0].charAt(0))) { if (textHasBegun) { contentStream.endText(); } contentStream.beginText(); textHasBegun = true; contentStream.moveTextPositionByAmount(parseFloat(split[0]), parseFloat(split[1])); } else { contentStream.moveTextPositionByAmount(currentOffset, 0); } if (!textHasBegun) { LOGGER.warn("Hay un posible mal uso de un .ree", new Throwable()); contentStream.beginText(); textHasBegun = true; } PDType1Font font; if ("b".equals(split[2])) { font = HELVETICA_BOLD; } else { font = HELVETICA; } contentStream.setFont(font, fontSize); Object text = null; if (split[3].startsWith("\"")) { // TODO: text = substring(split[3], 1, -1); } else { // TODO: text = new PropertyModel(m, split[3]).getObject(); } if (text == null) { LOGGER.warn("Propiedad {} no se encuentra", split[3]); //contentStream.drawString("ERROR: propiedad no encontrada"); contentStream.drawString(" "); } else { String string = text.toString(); currentOffset = font.getStringWidth(string) * ancho; contentStream.drawString(string); } } if (textHasBegun) { contentStream.endText(); } } finally { Closeables.closeQuietly(fileReader); } contentStream.close(); try { doc.save(os); } catch (COSVisitorException e) { throw new IOException("Ha ocurrido un error al escribir en el Os", e); } } finally { if (doc != null) { doc.close(); } LOGGER.info("Me ha tomado {} milisegundos hacer el pdf", System.currentTimeMillis() - t); } }
From source file:org.eclipse.viatra.query.tooling.ui.queryresult.BackendSelectionControl.java
@Override protected Control createControl(Composite parent) { final ComboViewer viewer = new ComboViewer(parent, SWT.BORDER | SWT.READ_ONLY); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { @Override/*from ww w . j a va 2s . c o m*/ public String getText(Object element) { if (element instanceof IQueryBackendFactory) { return QueryBackendRegistry.getInstance().getQueryBackendName((IQueryBackendFactory) element); } return super.getText(element); } }); viewer.setInput(Iterables.toArray(getRegisteredQueryBackendImplementations(), IQueryBackendFactory.class)); IQueryBackendFactory queryBackendFactory = getHints().getQueryBackendFactory(); viewer.setSelection(queryBackendFactory != null ? new StructuredSelection(queryBackendFactory) : new StructuredSelection()); viewer.addSelectionChangedListener(event -> { final ISelection select = event.getSelection(); if (select instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) select; Object o = selection.getFirstElement(); if (o instanceof IQueryBackendFactory) { applyBackendSelection((IQueryBackendFactory) o); } } }); viewer.getControl().setToolTipText("Select query backend engine to be used on subsequent loads."); return viewer.getControl(); }
From source file:sample.WelcomeController.java
@Route(method = HttpMethod.GET, uri = "/orientdb/{name}") public Result test3(@NotNull @PathParameter("name") String name) { if (name.equalsIgnoreCase("*")) return ok(Iterables.toArray(userCrud.findAll(), User.class)).json(); else/*from www . jav a 2 s. co m*/ return ok(userCrud.query( new OSQLSynchQuery<User>("select from User where m_adr contains ( adr2 ='" + name + "')"))) .json(); }
From source file:org.gradle.model.internal.method.WeaklyTypeReferencingMethod.java
public Type[] getGenericParameterTypes() { return Iterables.toArray(Iterables.transform(paramTypes, new Function<ModelType<?>, Type>() { public Type apply(ModelType<?> modelType) { return modelType.getType(); }//from w w w.j a v a 2s . c o m }), Type.class); }