Java Code Examples for java.util.LinkedHashSet#toArray()

The following examples show how to use java.util.LinkedHashSet#toArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkedHashSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_toArray() {
    LinkedHashSet<Integer> lhs = new LinkedHashSet<Integer>();
    lhs.add(new Integer(1));
    lhs.add(new Integer(6));
    lhs.add(new Integer(7));
    lhs.add(new Integer(8));
    lhs.add(new Integer(9));
    lhs.add(new Integer(10));
    lhs.add(new Integer(11));
    lhs.add(new Integer(12));
    lhs.add(new Integer(13));

    Object[] o = lhs.toArray();
    for (int i = 0; i < o.length; i++) {
        assertTrue(lhs.contains(o[i]));
    }
    assertEquals(lhs.size(), o.length);
}
 
Example 2
Source File: CheckEncodingPropertiesFile.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add a new charset name mapping
 * @param javaName the (supposedly) java name of the charset.
 * @param xmlNames a list of corresponding XML names for that charset.
 */
void addMapping(String javaName, Collection<String> xmlNames) {
    final LinkedHashSet<String> aliasNames = new LinkedHashSet<>();
    aliasNames.add(javaName);
    aliasNames.addAll(xmlNames);
    final String[] aliases = aliasNames.toArray(new String[aliasNames.size()]);
    final String cs = findCharsetNameFor(aliases);
    if (cs != null) {
        registerCharsetNameFor(cs, aliases);
        if (xmlNames.size() > 0) {
            String preferred = xmlNames.iterator().next();
            String cachedPreferred = preferredMime.get(cs.toUpperCase());
            if (cachedPreferred != null && !cachedPreferred.equals(preferred)) {
                throw new ConflictingPreferredMimeNameError(cs, cachedPreferred, preferred);
            }
            preferredMime.put(cs.toUpperCase(), preferred);
        }
    } else {
        registerUnresolvedNamesFor(aliases, aliasNames);
    }
}
 
Example 3
Source File: AbstractElementRenderer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Element[] getElementsAt( final double x, final double y ) {
  if ( logicalPageDrawable == null ) {
    return new Element[ 0 ];
  }

  final RenderNode[] nodes = logicalPageDrawable.getNodesAt( x, y, null, null );
  if ( nodes.length == 0 ) {
    return new Element[ 0 ];
  }

  final LinkedHashSet<Element> elements = new LinkedHashSet<Element>( nodes.length );
  for ( int i = 0; i < nodes.length; i++ ) {
    final RenderNode node = nodes[ i ];
    final Element reportElement = elementsById.get( node.getInstanceId() );
    if ( reportElement != null ) {
      elements.add( reportElement );
    }
  }
  return elements.toArray( new Element[ elements.size() ] );
}
 
Example 4
Source File: StubUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static String[][] suggestArgumentNamesWithProposals(IJavaProject project, String[] paramNames) {
	String[][] newNames= new String[paramNames.length][];
	ArrayList<String> takenNames= new ArrayList<String>();

	// Ensure that the code generation preferences are respected
	for (int i= 0; i < paramNames.length; i++) {
		String curr= paramNames[i];
		String baseName= NamingConventions.getBaseName(NamingConventions.VK_PARAMETER, curr, project);

		String[] proposedNames= getVariableNameSuggestions(NamingConventions.VK_PARAMETER, project, curr, 0, takenNames, true);
		if (!curr.equals(baseName)) {
			// make the existing name to favorite
			LinkedHashSet<String> updatedNames= new LinkedHashSet<String>();
			updatedNames.add(curr);
			for (int k= 0; k < proposedNames.length; k++) {
				updatedNames.add(proposedNames[k]);
			}
			proposedNames= updatedNames.toArray(new String[updatedNames.size()]);
		}
		newNames[i]= proposedNames;
		takenNames.add(proposedNames[0]);
	}
	return newNames;
}
 
Example 5
Source File: CheckEncodingPropertiesFile.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add a new charset name mapping
 * @param javaName the (supposedly) java name of the charset.
 * @param xmlNames a list of corresponding XML names for that charset.
 */
void addMapping(String javaName, Collection<String> xmlNames) {
    final LinkedHashSet<String> aliasNames = new LinkedHashSet<>();
    aliasNames.add(javaName);
    aliasNames.addAll(xmlNames);
    final String[] aliases = aliasNames.toArray(new String[aliasNames.size()]);
    final String cs = findCharsetNameFor(aliases);
    if (cs != null) {
        registerCharsetNameFor(cs, aliases);
        if (xmlNames.size() > 0) {
            String preferred = xmlNames.iterator().next();
            String cachedPreferred = preferredMime.get(cs.toUpperCase());
            if (cachedPreferred != null && !cachedPreferred.equals(preferred)) {
                throw new ConflictingPreferredMimeNameError(cs, cachedPreferred, preferred);
            }
            preferredMime.put(cs.toUpperCase(), preferred);
        }
    } else {
        registerUnresolvedNamesFor(aliases, aliasNames);
    }
}
 
Example 6
Source File: AbstractScriptableDataFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public final String[] getReferencedFields( final String query, final DataRow parameter ) {
  try {
    final String[] additionalFields = scriptingSupport.computeAdditionalQueryFields( query, parameter );
    if ( additionalFields == null ) {
      return null;
    }

    final String realQuery = scriptingSupport.computeQuery( query, parameter );
    if ( realQuery == null ) {
      throw new ReportDataFactoryException( "Query '" + query + "' is not recognized." ); //$NON-NLS-1$ //$NON-NLS-2$
    }

    String[] referencedFieldsInternal = getReferencedFieldsInternal( realQuery, parameter );
    if ( referencedFieldsInternal == null ) {
      return null;
    }

    final LinkedHashSet<String> fields = new LinkedHashSet<String>();
    fields.addAll( Arrays.asList( referencedFieldsInternal ) );
    fields.addAll( Arrays.asList( additionalFields ) );
    return fields.toArray( new String[fields.size()] );
  } catch ( final ReportDataFactoryException rx ) {
    logger.debug( "Failed to compute referenced fields", rx ); // NON-NLS
    return null;
  }
}
 
Example 7
Source File: CheckEncodingPropertiesFile.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add a new charset name mapping
 * @param javaName the (supposedly) java name of the charset.
 * @param xmlNames a list of corresponding XML names for that charset.
 */
void addMapping(String javaName, Collection<String> xmlNames) {
    final LinkedHashSet<String> aliasNames = new LinkedHashSet<>();
    aliasNames.add(javaName);
    aliasNames.addAll(xmlNames);
    final String[] aliases = aliasNames.toArray(new String[aliasNames.size()]);
    final String cs = findCharsetNameFor(aliases);
    if (cs != null) {
        registerCharsetNameFor(cs, aliases);
        if (xmlNames.size() > 0) {
            String preferred = xmlNames.iterator().next();
            String cachedPreferred = preferredMime.get(cs.toUpperCase());
            if (cachedPreferred != null && !cachedPreferred.equals(preferred)) {
                throw new ConflictingPreferredMimeNameError(cs, cachedPreferred, preferred);
            }
            preferredMime.put(cs.toUpperCase(), preferred);
        }
    } else {
        registerUnresolvedNamesFor(aliases, aliasNames);
    }
}
 
Example 8
Source File: ResourcesLoader.java    From buck with Apache License 2.0 5 votes vote down vote up
@TargetApi(LOLLIPOP)
public static void updateLoadedApkResDirs(Context context) throws Exception {
  List<String> exoResourcePaths = getExoPaths(context);
  if (exoResourcePaths.isEmpty()) {
    return;
  }
  // Split resource loading doesn't interact correctly with WebView's asset loading, so we add
  // the webview assets directly (in the same way that the webview asset-loading does it).
  // If split resource loading didn't replace the base source dir (and just added split resource
  // dirs), I think it would interact fine with webview assets. I'm not sure if this would work
  // on Android <5.0, and it would require using different package id or type ids in the split
  // resources.
  List<String> webviewAssets = getWebViewAssets(context);
  getAssetManager(context).addAssetPaths(webviewAssets, true);
  ApplicationInfo applicationInfo = context.getApplicationInfo();
  LinkedHashSet<String> sharedLibraryFiles = new LinkedHashSet<>();
  if (applicationInfo.sharedLibraryFiles != null) {
    sharedLibraryFiles.addAll(Arrays.asList(applicationInfo.sharedLibraryFiles));
  }
  sharedLibraryFiles.addAll(webviewAssets);
  applicationInfo.sharedLibraryFiles =
      sharedLibraryFiles.toArray(new String[sharedLibraryFiles.size()]);

  String resDir = exoResourcePaths.get(0);
  String[] splitResDirs = new String[exoResourcePaths.size() - 1];
  for (int i = 1; i < exoResourcePaths.size(); i++) {
    splitResDirs[i - 1] = exoResourcePaths.get(i);
  }
  ActivityThreadInternal activityThread = ActivityThreadInternal.currentActivityThread();
  for (LoadedApkInternal loadedApk : activityThread.getLoadedApks()) {
    if (loadedApk.getApplication() == context) {
      loadedApk.setResDir(resDir);
      loadedApk.setSplitResDirs(splitResDirs);
    }
  }
}
 
Example 9
Source File: CrosstabProcessorFunction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String[] computeRows( final CrosstabGroup crosstabGroup ) {
  final LinkedHashSet<String> list = new LinkedHashSet<String>();
  list.addAll( crosstabGroup.getPaddingFields() );
  collectRelationalFields( crosstabGroup.getParentSection(), list );
  collectCrosstabFields( crosstabGroup, list );
  return list.toArray( new String[list.size()] );
}
 
Example 10
Source File: AbstractKettleTransformationProducer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String[] getReferencedFields() throws ParseException {
  final LinkedHashSet<String> retval = new LinkedHashSet<>();
  HashSet<String> args = new HashSet<>();
  for ( final FormulaArgument argument : arguments ) {
    args.addAll( Arrays.asList( argument.getReferencedFields() ) );
  }
  for ( final FormulaParameter formulaParameter : parameter ) {
    args.addAll( Arrays.asList( formulaParameter.getReferencedFields() ) );
  }
  retval.addAll( args );
  retval.add( DataFactory.QUERY_LIMIT );
  return retval.toArray( new String[ retval.size() ] );
}
 
Example 11
Source File: BulkOperationCleanupAction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an action to cleanup "affected cache regions" based on the
 * affected entity persisters.  The affected regions are defined as the
 * region (if any) of the entity persisters themselves, plus the
 * collection regions for any collection in which those entity
 * persisters participate as elements/keys/etc.
 *
 * @param session The session to which this request is tied.
 * @param affectedQueryables The affected entity persisters.
 */
public BulkOperationCleanupAction(SharedSessionContractImplementor session, Queryable... affectedQueryables) {
	final SessionFactoryImplementor factory = session.getFactory();
	final LinkedHashSet<String> spacesList = new LinkedHashSet<>();
	for ( Queryable persister : affectedQueryables ) {
		spacesList.addAll( Arrays.asList( (String[]) persister.getQuerySpaces() ) );

		if ( persister.canWriteToCache() ) {
			final EntityDataAccess entityDataAccess = persister.getCacheAccessStrategy();
			if ( entityDataAccess != null ) {
				entityCleanups.add( new EntityCleanup( entityDataAccess, session ) );
			}
		}

		if ( persister.hasNaturalIdentifier() && persister.hasNaturalIdCache() ) {
			naturalIdCleanups.add(
					new NaturalIdCleanup( persister.getNaturalIdCacheAccessStrategy(), session )
			);
		}

		final Set<String> roles = factory.getMetamodel().getCollectionRolesByEntityParticipant( persister.getEntityName() );
		if ( roles != null ) {
			for ( String role : roles ) {
				final CollectionPersister collectionPersister = factory.getMetamodel().collectionPersister( role );
				if ( collectionPersister.hasCache() ) {
					collectionCleanups.add(
							new CollectionCleanup(
									collectionPersister.getCacheAccessStrategy(),
									session
							)
					);
				}
			}
		}
	}

	this.affectedTableSpaces = spacesList.toArray( new String[ spacesList.size() ] );
}
 
Example 12
Source File: JRPropertiesMap.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the names of the properties.
 *  
 * @return the names of the properties
 */
public String[] getPropertyNames()
{
	String[] names;
	if (hasOwnProperties())
	{
		if (base == null)
		{
			names = propertiesList.toArray(new String[propertiesList.size()]);
		}
		else
		{
			LinkedHashSet<String> namesSet = new LinkedHashSet<String>();
			collectPropertyNames(namesSet);
			names = namesSet.toArray(new String[namesSet.size()]);
		}
	}
	else if (base != null)
	{
		names = base.getPropertyNames();
	}
	else
	{
		names = new String[0];
	}
	return names;
}
 
Example 13
Source File: StandardClassMetadata.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String[] getMemberClassNames() {
	LinkedHashSet<String> memberClassNames = new LinkedHashSet<String>();
	for (Class<?> nestedClass : this.introspectedClass.getDeclaredClasses()) {
		memberClassNames.add(nestedClass.getName());
	}
	return memberClassNames.toArray(new String[memberClassNames.size()]);
}
 
Example 14
Source File: SolrStoreMapping.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
     * @param nodes
     *            the nodes to set
     */
//    public void setNodes(String[] nodes)
//    {
//        LinkedHashSet<String> unique = new LinkedHashSet<String>();
//        for(String node : nodes)
//        {
//            for(String split : node.split(","))
//            {
//                unique.add(split.trim());
//            }
//        }
//        
//        this.nodes = unique.toArray(new String[0]);
//    }
    
    public void setNodeString(String nodes)
    {
        LinkedHashSet<String> unique = new LinkedHashSet<String>();

        for(String split : nodes.split(","))
        {
            unique.add(split.trim());
        }


        this.nodes = unique.toArray(new String[0]);
    }
 
Example 15
Source File: ReportAuthenticationStore.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String[] getDefinedOptions( final String url ) {
  final AuthenticationData data = localStorage.get( url );
  if ( data == null ) {
    return backend.getDefinedOptions( url );
  }
  final LinkedHashSet<String> keys = new LinkedHashSet<String>();
  keys.addAll( Arrays.asList( backend.getDefinedOptions( url ) ) );
  keys.addAll( Arrays.asList( data.getDefinedOptions() ) );
  return keys.toArray( new String[ keys.size() ] );
}
 
Example 16
Source File: Attributes.java    From requery with Apache License 2.0 5 votes vote down vote up
static <E> Attribute<E, ?>[] toArray(Collection<Attribute<E, ?>> attributes,
                                     Predicate<Attribute<E, ?>> filter) {
    LinkedHashSet<Attribute> filtered = new LinkedHashSet<>();
    for (Attribute<E, ?> attribute : attributes) {
        if (filter == null || filter.test(attribute)) {
            filtered.add(attribute);
        }
    }
    Attribute<E, ?>[] array = new Attribute[filtered.size()];
    return filtered.toArray(array);
}
 
Example 17
Source File: DefaultVideoDecoderFactory.java    From webrtc_android with MIT License 5 votes vote down vote up
@Override
public VideoCodecInfo[] getSupportedCodecs() {
  LinkedHashSet<VideoCodecInfo> supportedCodecInfos = new LinkedHashSet<VideoCodecInfo>();

  supportedCodecInfos.addAll(Arrays.asList(softwareVideoDecoderFactory.getSupportedCodecs()));
  supportedCodecInfos.addAll(Arrays.asList(hardwareVideoDecoderFactory.getSupportedCodecs()));
  if (platformSoftwareVideoDecoderFactory != null) {
    supportedCodecInfos.addAll(
        Arrays.asList(platformSoftwareVideoDecoderFactory.getSupportedCodecs()));
  }

  return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
}
 
Example 18
Source File: AbstractMDXDataFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public String[] getReferencedFields( final String queryName,
                                     final DataRow parameter ) throws ReportDataFactoryException {
  final boolean isNewConnection = connection == null;
  try {
    if ( connection == null ) {
      connection =
        connectionProvider.createConnection( computeJdbcUser( parameter ), computeJdbcPassword( parameter ) );
      connection.setLocale( getLocale() );

      final String role = computeRole( parameter );
      if ( role != null ) {
        connection.setRoleName( role );
      }
    }

    final MDXCompiler compiler = new MDXCompiler( parameter, getLocale() );
    final String value = computedQuery( queryName, parameter );
    final String translatedQuery = compiler.translateAndLookup( value, parameter );
    final LinkedHashSet<String> params = new LinkedHashSet<String>();
    params.addAll( compiler.getParameter() );
    if ( getRoleField() != null ) {
      params.add( getRoleField() );
    }
    if ( getJdbcPasswordField() != null ) {
      params.add( getJdbcPasswordField() );
    }
    if ( getJdbcUserField() != null ) {
      params.add( getJdbcUserField() );
    }
    final PreparedOlapStatement statement = connection.prepareOlapStatement( translatedQuery );

    final OlapParameterMetaData data = statement.getParameterMetaData();
    final int count = data.getParameterCount();
    for ( int i = 0; i < count; i++ ) {
      final String parameterName = data.getParameterName( i + 1 );
      params.add( parameterName );
    }
    params.add( DataFactory.QUERY_LIMIT );
    return params.toArray( new String[ params.size() ] );
  } catch ( final Throwable e ) {
    throw new ReportDataFactoryException( "Failed to obtain a connection", e );
  } finally {
    if ( isNewConnection ) {
      close();
    }
  }
}
 
Example 19
Source File: CompositeFont.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public CompositeFont( FontMappingManager manager,
		CompositeFontConfig config, String[] sequence )
{
	FontMappingManager parentManager = manager.getParent( );
	if ( parentManager != null )
	{
		this.parent = parentManager.getCompositeFont( config.fontName );
	}
	this.config = config;
	this.specialCharacters = config.getSpecialCharacters( );
	// create the fonts follows the sequence
	LinkedHashSet fonts = new LinkedHashSet( );
	if ( sequence != null )
	{
		for ( int i = 0; i < sequence.length; i++ )
		{
			Collection catalogFonts = config.getFontByCatalog( sequence[i] );
			if ( catalogFonts != null )
			{
				fonts.addAll( catalogFonts );
			}
		}
	}
	fonts.addAll( config.getAllFonts( ) );
	usedFonts = (String[]) fonts.toArray( new String[]{} );

	fullIndexed = true;
	fontsIndex = new CharSegment[usedFonts.length][];
	for ( int i = 0; i < usedFonts.length; i++ )
	{
		fontsIndex[i] = config.getCharSegment( usedFonts[i] );
		if ( fontsIndex[i] == null )
		{
			fullIndexed = false;
		}
	}
	if ( fullIndexed )
	{
		fullIndex = CharSegment.merge( fontsIndex );
	}
	else
	{
		baseFonts = new BaseFont[usedFonts.length];
		for ( int i = 0; i < baseFonts.length; i++ )
		{
			baseFonts[i] = manager.createFont( usedFonts[i], Font.NORMAL );
		}
	}
}
 
Example 20
Source File: ProfileHandler.java    From spacewalk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Get custom options for a kickstart profile.
 * @param loggedInUser The current user
 * @param ksLabel the kickstart label
 * @return a list of hashes holding this info.
 * @throws FaultException A FaultException is thrown if
 *         the profile associated with ksLabel cannot be found
 *
 * @xmlrpc.doc Get custom options for a kickstart profile.
 * @xmlrpc.param #session_key()
 * @xmlrpc.param #param("string","ksLabel")
 *
 * @xmlrpc.returntype
 * #array()
 * $KickstartCommandSerializer
 * #array_end()
 */
public Object[] getCustomOptions(User loggedInUser, String ksLabel)
throws FaultException {
    KickstartData ksdata = KickstartFactory.lookupKickstartDataByLabelAndOrgId(
            ksLabel, loggedInUser.getOrg().getId());
    if (ksdata == null) {
        throw new FaultException(-3, "kickstartProfileNotFound",
        "No Kickstart Profile found with label: " + ksLabel);
    }
    LinkedHashSet options = ksdata.getCustomOptions();
    return options.toArray();
}