Example usage for java.lang System identityHashCode

List of usage examples for java.lang System identityHashCode

Introduction

In this page you can find the example usage for java.lang System identityHashCode.

Prototype

@HotSpotIntrinsicCandidate
public static native int identityHashCode(Object x);

Source Link

Document

Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode().

Usage

From source file:org.apache.solr.core.CoreContainer.java

@Override
protected void finalize() throws Throwable {
    try {// w ww. j a va2s . co  m
        if (!isShutDown) {
            log.error(
                    "CoreContainer was not shutdown prior to finalize(), indicates a bug -- POSSIBLE RESOURCE LEAK!!!  instance="
                            + System.identityHashCode(this));
            shutdown();
        }
    } finally {
        super.finalize();
    }
}

From source file:org.apache.kylin.dict.DictionaryManager.java

DictionaryInfo load(String resourcePath, boolean loadDictObj) throws IOException {
    ResourceStore store = MetadataManager.getInstance(config).getStore();

    logger.info("DictionaryManager(" + System.identityHashCode(this) + ") loading DictionaryInfo(loadDictObj:"
            + loadDictObj + ") at " + resourcePath);
    DictionaryInfo info = store.getResource(resourcePath, DictionaryInfo.class,
            loadDictObj ? DictionaryInfoSerializer.FULL_SERIALIZER : DictionaryInfoSerializer.INFO_SERIALIZER);
    return info;//from  w w w  . ja  va 2s  . c om
}

From source file:org.jabsorb.ng.JSONRPCBridge.java

/**
 * Adds a reference to the map of known references
 * /*from  w w  w.j  a  v  a  2  s . c  om*/
 * @param o
 *            The object to be added
 */
public void addReference(final Object o) {

    synchronized (referenceMap) {
        referenceMap.put(new Integer(System.identityHashCode(o)), o);
    }
}

From source file:org.pentaho.reporting.engine.classic.core.layout.process.alignment.AbstractAlignmentProcessor.java

protected void computeInlineBlock(final RenderBox box, final long position, final long itemElementWidth) {
    final StaticBoxLayoutProperties blp = box.getStaticBoxLayoutProperties();
    box.setCachedX(position + blp.getMarginLeft());
    final long width = itemElementWidth - blp.getMarginLeft() - blp.getMarginRight();
    if (width == 0) {
        // ModelPrinter.printParents(box);

        throw new IllegalStateException("A box without any width? "
                + Integer.toHexString(System.identityHashCode(box)) + ' ' + box.getClass());
    }/*  www . j  a v  a 2s  . co m*/
    box.setCachedWidth(width);

    final BoxDefinition bdef = box.getBoxDefinition();
    final long leftInsets = bdef.getPaddingLeft() + blp.getBorderLeft();
    final long rightInsets = bdef.getPaddingRight() + blp.getBorderRight();
    box.setContentAreaX1(box.getCachedX() + leftInsets);
    box.setContentAreaX2(box.getCachedX() + box.getCachedWidth() - rightInsets);

    // final InfiniteMinorAxisLayoutStep layoutStep = new InfiniteMinorAxisLayoutStep(metaData);
    // layoutStep.continueComputation(getPageGrid(), box);
}

From source file:org.jbpm.taskmgmt.exe.TaskInstance.java

public String toString() {
    return "TaskInstance"
            + (name != null ? "[" + name + "]" : Integer.toHexString(System.identityHashCode(this)));
}

From source file:IdentityMap.java

/**
 * {@inheritDoc}// w w w.  j  av  a  2 s . co  m
 * @see java.util.Collection#contains(java.lang.Object)
 */
public boolean contains(final Object key) {
    int hash = System.identityHashCode(key);
    int index = hash % _capacity;
    if (index < 0) {
        index = -index;
    }

    Entry entry = _buckets[index];
    while (entry != null) {
        if (entry.getKey() == key) {
            return true;
        }
        entry = entry.getNext();
    }
    return false;
}

From source file:IdentityHashMap.java

/**
 * Returns a collection view of the mappings contained in this map.  Each
 * element in the returned collection is a <tt>Map.Entry</tt>.  The
 * collection is backed by the map, so changes to the map are reflected in
 * the collection, and vice-versa.  The collection supports element
 * removal, which removes the corresponding mapping from the map, via the
 * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
 * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations.
 * It does not support the <tt>add</tt> or <tt>addAll</tt> operations.
 *
 * @return a collection view of the mappings contained in this map.
 * @see Map.Entry//from  ww  w.  j  a v  a 2s  . c  om
 */
public Set entrySet() {
    if (entrySet == null) {
        entrySet = new AbstractSet() {
            public Iterator iterator() {
                return getHashIterator(ENTRIES);
            }

            public boolean contains(Object o) {
                if (!(o instanceof Map.Entry))
                    return false;
                Map.Entry entry = (Map.Entry) o;
                Object key = entry.getKey();
                Entry tab[] = table;
                // int hash = (key==null ? 0 : key.hashCode());
                int hash = (key == null ? 0 : System.identityHashCode(key));
                int index = (hash & 0x7FFFFFFF) % tab.length;

                for (Entry e = tab[index]; e != null; e = e.next)
                    if (e.hash == hash && e.equals(entry))
                        return true;
                return false;
            }

            public boolean remove(Object o) {
                if (!(o instanceof Map.Entry))
                    return false;
                Map.Entry entry = (Map.Entry) o;
                Object key = entry.getKey();
                Entry tab[] = table;
                // int hash = (key==null ? 0 : key.hashCode());
                int hash = (key == null ? 0 : System.identityHashCode(key));
                int index = (hash & 0x7FFFFFFF) % tab.length;

                for (Entry e = tab[index], prev = null; e != null; prev = e, e = e.next) {
                    if (e.hash == hash && e.equals(entry)) {
                        modCount++;
                        if (prev != null)
                            prev.next = e.next;
                        else
                            tab[index] = e.next;

                        count--;
                        e.value = null;
                        return true;
                    }
                }
                return false;
            }

            public int size() {
                return count;
            }

            public void clear() {
                IdentityHashMap.this.clear();
            }
        };
    }

    return entrySet;
}

From source file:edu.oregonstate.eecs.mcplan.domains.blackjack.AbstractionDiscovery.java

private static <X extends FactoredRepresentation<BlackjackState>, R extends Representer<BlackjackState, X>> void runExperiment(
        final BlackjackParameters params, final int Niterations, final int Ntrain_games,
        final int Ntrain_episodes, final int Ntest_games, final int Ntest_episodes, final File root)
        throws Exception {
    final BlackjackAggregator repr = new BlackjackAggregator();
    final BlackjackMdp mdp = new BlackjackMdp(params);
    System.out.println("Solving MDP");
    final Pair<String[][], String[][]> soln = mdp.solve();
    final String[][] hard_actions = soln.first;
    final String[][] soft_actions = soln.second;

    System.out.println("****************************************");
    System.out.println("game = " + params.max_score + " x (" + Ntrain_games + "(" + Ntrain_episodes + ")"
            + " / " + Ntest_games + "(" + Ntest_episodes + ")) " + ": " + repr);
    final Csv.Writer data_out = new Csv.Writer(new PrintStream(new File(root, "data.csv")));
    data_out.cell("abstraction").cell("game").cell("iteration").cell("Ntrain_games").cell("Ntrain_episodes")
            .cell("Ntest_games").cell("Ntest_episodes").cell("mean").cell("var").cell("conf").newline();

    final ActionGenerator<BlackjackState, JointAction<BlackjackAction>> action_gen = new BlackjackJointActionGenerator(
            1);/*  w  ww .  j  a v a 2s . co m*/
    final Policy<BlackjackState, JointAction<BlackjackAction>> rollout_policy = new RandomPolicy<BlackjackState, JointAction<BlackjackAction>>(
            0 /*Player*/, rng.nextInt(), action_gen.create());

    final double c = 1.0;
    final int rollout_width = 1;
    final int rollout_depth = 1;
    // Optimistic default value
    final double[] default_value = new double[] { 1.0 };
    Representer<BlackjackState, ClusterAbstraction<BlackjackState>> Crepr = new TrivialClusterRepresenter(
            params, mdp.S());

    // NOTE: In the Blackjack domain, we can easily enumerate all
    // legal states, so I'm punting the issue of how to collect them
    // properly during search. In reality, there's a question of
    // whether we should be weighting them, e.g. by their reachability.
    final ArrayList<RealVector> Phi = enumerateStates(params);

    RealMatrix A0 = MatrixUtils.createRealIdentityMatrix(Phi.get(0).getDimension());

    for (int iter = 0; iter < Niterations; ++iter) {
        System.out.println("Iteration " + iter);
        //         final UnlabeledStateAccumulator<ClusterAbstraction<BlackjackState>> train_visitor
        //            = new UnlabeledStateAccumulator<ClusterAbstraction<BlackjackState>>( Crepr.create() );
        final MctsVisitor<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction> train_visitor = new DefaultMctsVisitor<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction>();
        final BackupRule<ClusterAbstraction<BlackjackState>, BlackjackAction> train_backup = BackupRule
                .<ClusterAbstraction<BlackjackState>, BlackjackAction>MaxQ();

        // Gather training examples
        System.out.println("Gathering training examples...");
        final SolvedStateAccumulator<HandValueAbstraction> acc = new SolvedStateAccumulator<HandValueAbstraction>(
                repr);
        for (int i = 0; i < Ntrain_games; ++i) {
            if (i % 100000 == 0) {
                System.out.println("Episode " + i);
            }

            final Deck deck = new InfiniteDeck();
            final BlackjackSimulator sim = new BlackjackSimulator(deck, 1, params);

            final GameTreeFactory<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction> factory = new UctSearch.Factory<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction>(
                    sim, Crepr.create(), action_gen.create(), c, Ntrain_episodes, rng, rollout_policy,
                    rollout_width, rollout_depth, train_backup, default_value);

            final SearchPolicy<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction> search_policy = new SearchPolicy<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction>(
                    factory, train_visitor, null) {
                @Override
                protected JointAction<BlackjackAction> selectAction(
                        final GameTree<ClusterAbstraction<BlackjackState>, BlackjackAction> tree) {
                    return BackupRules.MaxAction(tree.root()).a();
                }

                @Override
                public int hashCode() {
                    return System.identityHashCode(this);
                }

                @Override
                public boolean equals(final Object that) {
                    return this == that;
                }
            };

            final Episode<BlackjackState, BlackjackAction> episode = new Episode<BlackjackState, BlackjackAction>(
                    sim, search_policy);
            episode.addListener(acc);
            episode.run();
        }

        // Train classifier
        System.out.println("Training classifier...");
        final String algorithm = "kmeans"; //"rf";
        final boolean with_metric_learning = true;
        if ("kmeans".equals(algorithm)) {
            // final ArrayList<RealVector> Phi = train_visitor.Phi_;
            final MetricConstrainedKMeans kmeans = makeClustering(rng, A0, acc.Phi_, acc.actions_, Phi,
                    with_metric_learning);
            final VoronoiClassifier classifier = new VoronoiClassifier(kmeans.mu()) {
                @Override
                protected double distance(final RealVector x1, final RealVector x2) {
                    return kmeans.distance(x1, x2);
                }
            };
            // Update reference matrix. This has the effect of keeping some of
            // the information from previous training episodes.
            A0 = kmeans.metric.copy();
            writeClustering(kmeans, root, iter, params, hard_actions, soft_actions);
            Crepr = new ClusterRepresenter(classifier, repr.create());
        } else if ("rf".equals(algorithm)) {
            final Instances train = makeTrainingSet(acc, HandValueAbstraction.makeAttributes(params), iter);
            writeDataset(root, train);
            final Classifier classifier = makeClassifier(train);
            SerializationHelper.write(new File(root, "rf" + iter + ".model").getAbsolutePath(), classifier);
            Crepr = new PairwiseSimilarityRepresenter<BlackjackState, HandValueAbstraction>(repr.create(),
                    new Instances(train), classifier);
        }

        // Test
        System.out.println("Testing...");
        final MctsVisitor<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction> test_visitor = new DefaultMctsVisitor<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction>();
        final BackupRule<ClusterAbstraction<BlackjackState>, BlackjackAction> test_backup = BackupRule
                .<ClusterAbstraction<BlackjackState>, BlackjackAction>MaxQ();
        final MeanVarianceAccumulator ret = new MeanVarianceAccumulator();
        for (int i = 0; i < Ntest_games; ++i) {
            if (i % 10000 == 0) {
                System.out.println("Episode " + i);
            }

            final Deck deck = new InfiniteDeck();
            final BlackjackSimulator sim = new BlackjackSimulator(deck, 1, params);

            final GameTreeFactory<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction> factory = new UctSearch.Factory<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction>(
                    sim, Crepr.create(), action_gen.create(), c, Ntest_episodes, rng, rollout_policy,
                    rollout_width, rollout_depth, test_backup, default_value);

            final SearchPolicy<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction> search_policy = new SearchPolicy<BlackjackState, ClusterAbstraction<BlackjackState>, BlackjackAction>(
                    factory, test_visitor, null) {
                @Override
                protected JointAction<BlackjackAction> selectAction(
                        final GameTree<ClusterAbstraction<BlackjackState>, BlackjackAction> tree) {
                    return BackupRules.MaxAction(tree.root()).a();
                }

                @Override
                public int hashCode() {
                    return System.identityHashCode(this);
                }

                @Override
                public boolean equals(final Object that) {
                    return this == that;
                }
            };

            final Episode<BlackjackState, BlackjackAction> episode = new Episode<BlackjackState, BlackjackAction>(
                    sim, search_policy);
            episode.run();
            //         System.out.println( sim.state().token().toString() );
            //         System.out.println( "Reward: " + sim.reward()[0] );
            ret.add(sim.reward()[0]);
        }
        System.out.println("****************************************");
        System.out.println("Average return: " + ret.mean());
        System.out.println("Return variance: " + ret.variance());
        final double conf = 0.975 * ret.variance() / Math.sqrt(Ntest_games);
        System.out.println("Confidence: " + conf);
        System.out.println();
        //         data_out.println( "abstraction,game,iterations,Ntrain_games,Ntrain_episodes,Ntest_games,Ntest_episodes,mean,var,conf" );
        data_out.cell(repr).cell(params.max_score).cell(iter).cell(Ntrain_games).cell(Ntrain_episodes)
                .cell(Ntest_games).cell(Ntest_episodes).cell(ret.mean()).cell(ret.variance()).cell(conf)
                .newline();
    }
}

From source file:er.extensions.components.javascript.ERXJSPopUpRelationPicker.java

public String objectArrayCreationString() {
    // here's an example of the string this method should return:
    //var parentschildren = new Array(new Entity("dogs","1",new Array(new Entity("poodle","4",null,false),new Entity("puli","5",null,true),new Entity("greyhound","5",null,false)),false), new Entity("fish","2",new Array(new Entity("trout","6",null,true),new Entity("mackerel","7",null,false),new Entity("bass","8",null,false)),true), new Entity("birds","3",new Array(new Entity("robin","9",null,false),new Entity("hummingbird","10",null,false),new Entity("crow","11",null,true)),false));

    StringBuilder returnString = new StringBuilder(1000);
    returnString.append("var ");
    returnString.append(objectsArrayName);
    returnString.append(" = [");

    int iCount = parentEntitiesList().count();
    for (int i = 0; i < iCount; i++) {
        Object aParent = parentEntitiesList().objectAtIndex(i);
        returnString.append("\n\tnew Entity(");
        returnString.append(" \""
                + NSKeyValueCodingAdditions.Utility.valueForKeyPath(aParent, parentDisplayValueName()) + "\",");
        returnString.append(" \"" + idForParent(aParent) + "\",");
        returnString.append(" \"" + System.identityHashCode(aParent) + "\",");

        // now do all the possible children of the parent. Each child should look like 'new Entity("poodle","4",null,false)'
        returnString.append(" [");
        NSArray childrenOfAParent = sortedChildren(aParent);

        int jCount = childrenOfAParent.count();
        Object defaultChild = defaultChildKey() != null
                ? NSKeyValueCodingAdditions.Utility.valueForKeyPath(aParent, defaultChildKey())
                : null;/*from  w w w.  j a  v a 2 s.c o  m*/
        int defaultChildIndex = -1;

        for (int j = 0; j < jCount; j++) {
            Object aChild = childrenOfAParent.objectAtIndex(j);
            returnString.append("\n\t\t new Entity(");
            returnString.append(
                    " \"" + NSKeyValueCodingAdditions.Utility.valueForKeyPath(aChild, childDisplayValueName())
                            + "\","); // visible text of pop-up
            returnString.append(" \"" + idForChild(aParent, aChild) + "\","); // value text of pop-up
            returnString.append(" \"" + System.identityHashCode(aChild) + "\",");
            returnString.append(" null,");
            if (isSelectedChild(aChild)) {
                returnString.append(" true");
            } else {
                returnString.append(" false");
            }
            returnString.append(", null");
            returnString.append(')');
            if (j != jCount - 1) {
                // append a comma and a space
                returnString.append(", ");
            }
            if (aChild == defaultChild)
                defaultChildIndex = j;
        }
        returnString.append("],");
        if (isSelectedParent(aParent)) { // in the single case, the parent will be updated when we call parent changed
            returnString.append(" true");
        } else {
            returnString.append(" false");
        }
        returnString.append(", ");
        returnString.append(defaultChild != null ? "\"" + defaultChildIndex + "\"" : "-1");
        returnString.append(')');

        if (i != iCount - 1) {
            // append a comma and a space
            returnString.append(", ");
        }
    }
    returnString.append("];");
    return returnString.toString();
}

From source file:org.apache.hadoop.net.unix.DomainSocketWatcher.java

public String toString() {
    return "DomainSocketWatcher(" + System.identityHashCode(this) + ")";
}