List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:com.inmobi.grill.cli.commands.GrillDimensionCommands.java
@CliCommand(value = "dim drop storage", help = "drop storage to dimension table") public String dropStorageFromDim( @CliOption(key = { "", "table" }, mandatory = true, help = "<table> <storage-spec>") String tablepair) { Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(tablepair); String[] pair = Iterables.toArray(parts, String.class); if (pair.length != 2) { return "Syntax error, please try in following " + "format. create fact <fact spec path> <storage spec path>"; }/*from w w w .j a v a2s .co m*/ File f = new File(pair[0]); if (!f.exists()) { return "Fact spec path" + f.getAbsolutePath() + " does not exist. Please check the path"; } f = new File(pair[1]); if (!f.exists()) { return "Storage spech path " + f.getAbsolutePath() + " does not exist. Please check the path"; } APIResult result = client.dropStorageFromDim(pair[0], pair[1]); if (result.getStatus() == APIResult.Status.SUCCEEDED) { return "Dim table storage removal successful"; } else { return "Dim table storage removal failed"; } }
From source file:org.cloudsmith.geppetto.pp.dsl.ui.editor.findrefs.ReferenceSearchResultContentProvider.java
public Object[] getElements(Object inputElement) { if (rootNodes == null || rootNodes.isEmpty()) { return new Object[0]; }/*from w ww . j a v a 2s . c om*/ return Iterables.toArray(rootNodes, ReferenceSearchViewTreeNode.class); }
From source file:org.apache.hadoop.mapred.FileInputFormat.java
/** List input directories. * Subclasses may override to, e.g., select only files matching a regular * expression. /*from w w w. java2 s .c om*/ * * @param job the job to list input paths for * @return array of FileStatus objects * @throws IOException if zero items. */ protected FileStatus[] listStatus(JobConf job) throws IOException { Path[] dirs = getInputPaths(job); if (dirs.length == 0) { throw new IOException("No input paths specified in job"); } // get tokens for all the required FileSystems.. TokenCache.obtainTokensForNamenodes(job.getCredentials(), dirs, job); // Whether we need to recursive look into the directory structure boolean recursive = job.getBoolean(INPUT_DIR_RECURSIVE, false); // creates a MultiPathFilter with the hiddenFileFilter and the // user provided one (if any). List<PathFilter> filters = new ArrayList<PathFilter>(); filters.add(hiddenFileFilter); PathFilter jobFilter = getInputPathFilter(job); if (jobFilter != null) { filters.add(jobFilter); } PathFilter inputFilter = new MultiPathFilter(filters); FileStatus[] result; int numThreads = job.getInt(org.apache.hadoop.mapreduce.lib.input.FileInputFormat.LIST_STATUS_NUM_THREADS, org.apache.hadoop.mapreduce.lib.input.FileInputFormat.DEFAULT_LIST_STATUS_NUM_THREADS); StopWatch sw = new StopWatch().start(); if (numThreads == 1) { List<FileStatus> locatedFiles = singleThreadedListStatus(job, dirs, inputFilter, recursive); result = locatedFiles.toArray(new FileStatus[locatedFiles.size()]); } else { Iterable<FileStatus> locatedFiles = null; try { LocatedFileStatusFetcher locatedFileStatusFetcher = new LocatedFileStatusFetcher(job, dirs, recursive, inputFilter, false); locatedFiles = locatedFileStatusFetcher.getFileStatuses(); } catch (InterruptedException e) { throw new IOException("Interrupted while getting file statuses"); } result = Iterables.toArray(locatedFiles, FileStatus.class); } sw.stop(); if (LOG.isDebugEnabled()) { LOG.debug("Time taken to get FileStatuses: " + sw.now(TimeUnit.MILLISECONDS)); } LOG.info("Total input files to process : " + result.length); return result; }
From source file:org.opentestsystem.shared.web.AbstractRestController.java
/** * Catch validation exception and return customized error message *///from ww w . j a v a 2 s . co m @ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(value = HttpStatus.BAD_REQUEST) @ResponseBody public ResponseError handleInvalidFormatException(final HttpMessageNotReadableException except) throws LocalizedException { ResponseError err = null; if (except.getCause() instanceof InvalidFormatException) { final InvalidFormatException invalidFormatEx = (InvalidFormatException) except.getCause(); final String[] fieldNames = Iterables .toArray(Iterables.transform(invalidFormatEx.getPath(), FIELD_NAME_SELECTOR), String.class); final String path = StringUtils.join(fieldNames, "."); String msgArg = getLocalizedMessage(path, null); if (path.equals(msgArg)) { LOGGER.warn("unable to find " + path); msgArg = camelToPretty(fieldNames[fieldNames.length - 1]); } err = new ResponseError(getLocalizedMessage(INVALID_FORMAT_MESSAGE, new String[] { msgArg, invalidFormatEx.getValue().toString() })); } else { err = new ResponseError(getLocalizedMessage(BIND_EXCEPTION_MESSAGE, null)); } return err; }
From source file:com.android.build.gradle.internal.dsl.BuildType.java
/** * Sets the ProGuard configuration files. * * <p>There are 2 default rules files * <ul>//from w ww . ja v a 2 s . co m * <li>proguard-android.txt * <li>proguard-android-optimize.txt * </ul> * <p>They are located in the SDK. Using <code>getDefaultProguardFile(String filename)</code> will return the * full path to the files. They are identical except for enabling optimizations. */ @NonNull public BuildType setProguardFiles(@NonNull Iterable<?> proguardFileIterable) { getProguardFiles().clear(); proguardFiles(Iterables.toArray(proguardFileIterable, Object.class)); return this; }
From source file:org.blip.workflowengine.transferobject.ModifiablePropertyNode.java
@Override public PropertyNode add(final String key, final PropertyNode value, final Collection<Attribute> attributes) { return internalAdd(true, key, value, Iterables.toArray(attributes, Attribute.class)); }
From source file:org.apache.lens.cli.commands.LensFactCommands.java
/** * Gets the all partitions of fact./*from w w w . j a v a 2 s . co m*/ * * @param specPair the spec pair * @return the all partitions of fact */ @CliCommand(value = "fact list partitions", help = "get all partitions associated with fact") public String getAllPartitionsOfFact(@CliOption(key = { "", "table" }, mandatory = true, help = "<table-name> <storageName> [optional <partition query filter> to get]") String specPair) { Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(specPair); String[] pair = Iterables.toArray(parts, String.class); if (pair.length == 2) { try { return formatJson( mapper.writer(pp).writeValueAsString(getClient().getAllPartitionsOfFact(pair[0], pair[1]))); } catch (IOException e) { throw new IllegalArgumentException(e); } } if (pair.length == 3) { try { return formatJson(mapper.writer(pp) .writeValueAsString(getClient().getAllPartitionsOfFact(pair[0], pair[1], pair[2]))); } catch (IOException e) { throw new IllegalArgumentException(e); } } return "Syntax error, please try in following " + "format. fact list partitions <table> <storage> [partition values]"; }
From source file:edu.mayo.cts2.framework.plugin.service.bioportal.transform.EntityDescriptionTransform.java
/** * Transform entity synonyms.//from ww w . j a va 2 s. co m * * @param codeSystemName the code system name * @param codeSystemVersionName the code system version name * @param node the node * @return the designation[] */ private Designation[] transformEntitySynonyms(String codeSystemName, String codeSystemVersionName, Node node) { List<Designation> returnList = new ArrayList<Designation>(); Node synonyms = TransformUtils.getNamedChild(node, "synonyms"); if (synonyms != null) { for (Node synonym : TransformUtils.getNodeList(synonyms, "string")) { Designation designation = new Designation(); designation.setValue(ModelUtils.toTsAnyType(TransformUtils.getNodeText(synonym))); designation.setDesignationRole(DesignationRole.ALTERNATIVE); //designation.setAssertedInCodeSystemVersion( // this.buildCodeSystemVersionReference(codeSystemName, codeSystemVersionName)); returnList.add(designation); } } return Iterables.toArray(returnList, Designation.class); }
From source file:io.crate.execution.engine.pipeline.ProjectionToProjectorVisitor.java
@Override public Projector visitGroupProjection(GroupProjection projection, Context context) { InputFactory.Context<CollectExpression<Row, ?>> ctx = inputFactory.ctxForAggregations(); ctx.add(projection.keys());/* w ww. j av a 2 s. c o m*/ ctx.add(projection.values()); List<Input<?>> keyInputs = ctx.topLevelInputs(); return new GroupingProjector(Symbols.typeView(projection.keys()), keyInputs, Iterables.toArray(ctx.expressions(), CollectExpression.class), projection.mode(), ctx.aggregations().toArray(new AggregationContext[0]), context.ramAccountingContext, indexVersionCreated, bigArrays); }
From source file:org.apache.isis.viewer.restfulobjects.applib.util.Parser.java
public static Parser<String[]> forArrayOfStrings() { return new Parser<String[]>() { @Override/*from w w w . ja v a2 s . c o m*/ public String[] valueOf(final List<String> strings) { if (strings == null) { return new String[] {}; } if (strings.size() == 1) { // special case processing to handle comma-separated values return valueOf(strings.get(0)); } return strings.toArray(new String[] {}); } @Override public String[] valueOf(final String[] strings) { if (strings == null) { return new String[] {}; } if (strings.length == 1) { // special case processing to handle comma-separated values return valueOf(strings[0]); } return strings; } @Override public String[] valueOf(final String str) { if (str == null) { return new String[] {}; } final Iterable<String> split = Splitter.on(",").split(str); return Iterables.toArray(split, String.class); } @Override public String asString(final String[] strings) { return Joiner.on(",").join(strings); } }; }