Java Code Examples for java.util.LinkedHashMap

The following are top voted examples for showing how to use java.util.LinkedHashMap. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: classpath   File: XMLParser.java View source code 7 votes vote down vote up
public String getPrefix(String namespaceURI)
{
  if (XMLConstants.XML_NS_URI.equals(namespaceURI))
    return XMLConstants.XML_NS_PREFIX;
  if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI))
    return XMLConstants.XMLNS_ATTRIBUTE;
  for (Iterator i = namespaces.iterator(); i.hasNext(); )
    {
      LinkedHashMap ctx = (LinkedHashMap) i.next();
      if (ctx.containsValue(namespaceURI))
        {
          for (Iterator j = ctx.entrySet().iterator(); j.hasNext(); )
            {
              Map.Entry entry = (Map.Entry) i.next();
              String uri = (String) entry.getValue();
              if (uri.equals(namespaceURI))
                return (String) entry.getKey();
            }
        }
    }
  return null;
}
 
Example 2
Project: jboss-dmr   File: ObjectModelValue.java View source code 6 votes vote down vote up
ObjectModelValue(final DataInput in) throws IOException {
    super(ModelType.OBJECT);
    final int count = in.readInt();
    final LinkedHashMap<String, ModelNode> map = new LinkedHashMap<String, ModelNode>();
    for (int i = 0; i < count; i++) {
        final String key = in.readUTF();
        final ModelNode value = new ModelNode();
        value.readExternal(in);
        map.put(key, value);
    }
    this.map = map;
}
 
Example 3
Project: foe   File: ZipArchiveEntry.java View source code 6 votes vote down vote up
/**
 * Adds an extra field - replacing an already present extra field
 * of the same type.
 *
 * <p>The new extra field will be the first one.</p>
 * @param ze an extra field
 */
public void addAsFirstExtraField(ZipExtraField ze) {
    if (ze instanceof UnparseableExtraFieldData) {
        unparseableExtra = (UnparseableExtraFieldData) ze;
    } else {
        LinkedHashMap copy = extraFields;
        extraFields = new LinkedHashMap();
        extraFields.put(ze.getHeaderId(), ze);
        if (copy != null) {
            copy.remove(ze.getHeaderId());
            extraFields.putAll(copy);
        }
    }
    setExtra();
}
 
Example 4
Project: bixie   File: AbstractTransitionRelation.java View source code 6 votes vote down vote up
protected ProverExpr indentifierExpression2proverExpression(
		CfgIdentifierExpression exp,
		LinkedHashMap<CfgVariable, ProverExpr> boundVariables) {
	// First check if we are talking about a bound variable
	if (boundVariables.containsKey(exp.getVariable())) {
		return boundVariables.get(exp.getVariable());
	}

	return createProverVar(exp.getVariable(), exp.getCurrentIncarnation());
}
 
Example 5
Project: UFMGame   File: Save.java View source code 6 votes vote down vote up
/**
 * Creates new Game object where team is the human and a username of the
 * person who is playing the game
 * 
 * @param team
 *            is the team you play with
 * @param username
 *            is the name the user inserts
 * @return a game object with the user and pc teams
 */
public static Game newGame(Team team, String username) {
	Human human = new Human(team, username, 50000);
	LinkedHashMap<String, Team> teams = loadTeam();
	ArrayList<User> users = new ArrayList<User>();
	users.add(human);
	teams.remove(team.getid());
	int i = 1;
	for (String key : teams.keySet()) {
		users.add(new PC(teams.get(key), "pc" + i, 50000));
		i = i + 1;
	}
	Game game = new Game(users);
	return game;
}
 
Example 6
Project: rayo-server   File: CassandraDatastore.java View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List<Application> getApplications() {

	try {
		log.debug("Finding all applications");
		
		List<Application> applications = new ArrayList<Application>();
		Selector selector = Pelops.createSelector(schemaName);
		LinkedHashMap<Bytes, List<Column>> rows = selector.getColumnsFromRows(
				"applications", 
				Selector.newKeyRange("", "", 10000), // 10000 applications limite, 
				false, ConsistencyLevel.ONE);
				
		for(Map.Entry<Bytes, List<Column>> row: rows.entrySet()) {
			if (row.getValue().size() > 0) {
				Application application = new Application(row.getKey().toUTF8());
				populateApplicationData(application, row.getValue());
				applications.add(application);
			}
		}

		return applications;
	} catch (PelopsException pe) {
		log.error(pe.getMessage(),pe);
		return Collections.EMPTY_LIST;
	}
}
 
Example 7
Project: bixie   File: GreedyCfgChecker.java View source code 6 votes vote down vote up
/**
 * Tries to cover elements in blocks by covering all blocks in the effectual
 * set of the CFG using Princess' cfg-theory. The map ineffFlags contains
 * one helper variable for each block in the effectual set.
 * 
 * @param blocks
 *            Map from SMT variables to BasicBlocks.
 * @param tr
 *            Transition relation of the analyzed procedure.
 * @param ineffFlags
 *            Map from SMT variables in blocks to helper variables for
 *            Princess.
 * @return The set of blocks that could be covered.
 */
protected Set<BasicBlock> coverBlocks(Map<ProverExpr, BasicBlock> blocks,
		TransitionRelation tr,
		LinkedHashMap<ProverExpr, ProverExpr> ineffFlags) {

	Set<BasicBlock> coveredBlocks = new HashSet<BasicBlock>();

	int threshold = ineffFlags.size();
	// hint for the greedy cover algorithm about
	// how many blocks could be covered in one query.
	if (threshold > 1)
		threshold = threshold / 2;

	while (threshold >= 1 && !ineffFlags.isEmpty()) {
		prover.push();

		coveredBlocks.addAll(coverBlocksWithThreshold(blocks, tr,
				ineffFlags, threshold));

		prover.pop();

		if (threshold == 1 || ineffFlags.isEmpty())
			break;

		do {
			threshold = (int) Math.ceil((double) threshold / 2.0);
		} while (threshold > ineffFlags.size());

	}

	return coveredBlocks;
}
 
Example 8
Project: eclipse-integration-commons   File: LiveProcessTracker.java View source code 6 votes vote down vote up
@Override
public synchronized Collection<Item> getLaunches() {
	LinkedHashMap<String, Item> launches = new LinkedHashMap<String, LaunchList.Item>();
	for (IProcess p : processes) {
		ILaunch l = p.getLaunch();
		if (l!=null) {
			ILaunchConfiguration c = l.getLaunchConfiguration();
			if (c!=null) {
				launches.put(c.getName(), new Item(c, l.getLaunchMode()));
			}
		}
	}
	return launches.values();
}
 
Example 9
Project: Desktop   File: FormulaCache.java View source code 6 votes vote down vote up
public void markAsDirtyIfFormulaNode(NodeModel node) {
		final LinkedHashMap<String, Object> entry = cache.get(node.getID());
		if (entry != null) {
//			System.out.println("clearing cache for " + node);
			entry.clear();
		}
	}
 
Example 10
Project: google-web-toolkit-svnmirror   File: LinkedHashMap_CustomFieldSerializer.java View source code 6 votes vote down vote up
/**
 * Infers the value of the private accessOrder field of instance by examining
 * its behavior on a set of test inputs, without using reflection. Note that
 * this implementation clones the instance, which could be slow.
 * 
 * @param instance the instance to check
 * @return the value of instance.accessOrder
 */
@SuppressWarnings("unchecked")
public static boolean getAccessOrderNoReflection(LinkedHashMap instance) {
  /*
   * Clone the instance so our modifications won't affect the original. In
   * particular, if the original overrides removeEldestEntry, adding elements
   * to the map could cause existing elements to be removed.
   */
  instance = (LinkedHashMap) instance.clone();
  instance.clear();

  /*
   * We insert key1, then key2, after which we access key1. We then iterate
   * over the key set and observe the order in which keys are returned. The
   * iterator will return keys in the order of least recent insertion or
   * access, depending on the value of the accessOrder field within the
   * LinkedHashMap instance. If the iterator is ordered by least recent
   * insertion (accessOrder = false), we will encounter key1 first since key2
   * has been inserted more recently. If it is ordered by least recent access
   * (accessOrder = true), we will encounter key2 first, since key1 has been
   * accessed more recently.
   */
  instance.put(KEY1, KEY1); // INSERT key1
  instance.put(KEY2, KEY2); // INSERT key2
  instance.get(KEY1); // ACCESS key1
  return instance.keySet().iterator().next() == KEY2;
}
 
Example 11
Project: TweetLanes   File: LazyImageLoader.java View source code 6 votes vote down vote up
public MemoryCache(int max_capacity) {
    mMaxCapacity = max_capacity;
    mSoftCache = new ConcurrentHashMap<URL, SoftReference<ExpiringBitmap>>();
    mHardCache = new LinkedHashMap<URL, ExpiringBitmap>(mMaxCapacity / 3,
            0.75f, true) {

        private static final long serialVersionUID = 1347795807259717646L;

        @Override
        protected boolean removeEldestEntry(
                LinkedHashMap.Entry<URL, ExpiringBitmap> eldest) {
            // Moves the last used item in the hard cache to the soft
            // cache.
            if (size() > mMaxCapacity) {
                mSoftCache.put(eldest.getKey(),
                        new SoftReference<ExpiringBitmap>(eldest.getValue()));
                return true;
            } else
                return false;
        }
    };
}