clone

Proper Implementation of clone() For Domain Classes to duplicate a Grails domain instance

天涯浪子 提交于 2019-11-29 02:25:47
I have several domain classes for which the user interface includes a "duplicate" command. As part of the implementation of those commands, I have implemented clone() methods in the corresponding domain classes. I have been trying to correct my bad habit of improperly implementing clone() (in general) based on use of " new " rather than "super.clone()," so as soon as I thought about doing the same for my Grails domain classes, I wondered how using super.clone() to obtain a clone might interact with GORM / Hibernate persistence. In particular, I was wondering about the proper way to handle the

Discard a local branch in Mercurial before it is pushed

扶醉桌前 提交于 2019-11-29 01:13:52
Many times it happens that I have few commits on my local Hg repository which I don't want to push and sometimes I want to remove the local branch altogether. But I cannot rollback more than one commit which leaves me no choice than creating a new clone and download the whole repository again. This feels stupid, since if I could just delete my local branch which has not affected the remote repository in anyway, then I wouldn't have to create and setup a new clone. So, is it how it is in Mercurial or is there some way to discard a local branch? Thanks! If you enable the mq extension (bundled

C# Reflection Indexed Properties

一笑奈何 提交于 2019-11-29 01:09:58
I am writing a Clone method using reflection. How do I detect that a property is an indexed property using reflection? For example: public string[] Items { get; set; } My method so far: public static T Clone<T>(T from, List<string> propertiesToIgnore) where T : new() { T to = new T(); Type myType = from.GetType(); PropertyInfo[] myProperties = myType.GetProperties(); for (int i = 0; i < myProperties.Length; i++) { if (myProperties[i].CanWrite && !propertiesToIgnore.Contains(myProperties[i].Name)) { myProperties[i].SetValue(to,myProperties[i].GetValue(from,null),null); } } return to; } FlySwat

How to clone object in Kotlin?

守給你的承諾、 提交于 2019-11-29 01:08:35
The question is that simple. Kotlin documentation describes cloning only in accessing Java and in enum class . In latter case clone is just throwing an exception. So, how would I / should I clone arbitrary Kotlin object? Should I just use clone() as in Java? For a data class , you can use the compiler-generated copy() method . Note that it will perform a shallow copy. To create a copy of a collection, use the toList() or toSet() methods, depending on the collection type you need. These methods always create a new copy of a collection; they also perform a shallow copy. For other classes, there

Gitolite: adding user not working, and DENIED by fallthru when cloning as root?

[亡魂溺海] 提交于 2019-11-29 00:28:27
I've managed to init an empty git repo on my NAS, and I attempted to add a new user by generating a new public key "foo.pub" and copying + pasting it into keydir/ and committing that and pushing it onto the NAS. First, the files: Here is my ~/.ssh/config file: Host root HostName iptonas User root Port 123 Host foo HostName iptonas User foo Port 123 identityfile ~/.ssh/foo Grabbed a copy of gitolite-admin from NAS: git clone ssh://root/gitolite-admin I get: Cloning into 'gitolite-admin'... remote: Counting objects: 12, done. remote: Compressing objects: 100% (9/9), done. remote: Total 12 (delta

Hudson git clone error

夙愿已清 提交于 2019-11-28 23:39:26
I have created free-style software project in Hudson. I want to clone a public Git repository: git://github.com/bret/watir.git Build fails with error message: Started by user anonymous Checkout:workspace / C:\Documents and Settings\Administrator\.hudson\jobs\watir\workspace - hudson.remoting.LocalChannel@1a1f370 Last Build : #4 Checkout:workspace / C:\Documents and Settings\Administrator\.hudson\jobs\watir\workspace - hudson.remoting.LocalChannel@1a1f370 Cloning the remote Git repository Cloning repository origin $ git clone -o origin git://github.com/bret/watir.git "C:\Documents and Settings

jQuery UI: Drag and clone from original div, but keep clones

依然范特西╮ 提交于 2019-11-28 22:55:28
I have a div, which has jQuery UI Draggable applied. What I want to do, is click and drag that, and create a clone that is kept in the dom and not removed when dropped. Think of a deck of cards, my box element is the deck, and I want to pull cards/divs off that deck and have them laying around my page, but they would be clones of the original div. I just want to make sure that you cannot create another clone of one of the cloned divs. I have used the following, which didn't work like I wanted: $(".box").draggable({ axis: 'y', containment: 'html', start: function(event, ui) { $(this).clone()

Why clone() is the best way for copying arrays?

喜夏-厌秋 提交于 2019-11-28 22:43:03
It's a shame for me, but I did not know that: You should use clone to copy arrays, because that's generally the fastest way to do it. as Josh Bloch states in this blog: http://www.artima.com/intv/bloch13.html I always used System.arraycopy(...) . Both approaches are native, so probably without going deeper into the sources of libraries I can not figure out, why it is so. My question is simple: why is it the fastest way? What is the difference with System.arraycopy ? The difference is explained here , but it does not answer the question why Josh Bloch considers clone() as the fastest way. I

How to mmap the stack for the clone() system call on linux?

北慕城南 提交于 2019-11-28 21:39:35
The clone() system call on Linux takes a parameter pointing to the stack for the new created thread to use. The obvious way to do this is to simply malloc some space and pass that, but then you have to be sure you've malloc'd as much stack space as that thread will ever use (hard to predict). I remembered that when using pthreads I didn't have to do this, so I was curious what it did instead. I came across this site which explains, "The best solution, used by the Linux pthreads implementation, is to use mmap to allocate memory, with flags specifying a region of memory which is allocated as it

deep copying a graph structure

心不动则不痛 提交于 2019-11-28 20:53:52
I have a graph class with Node's, where each Node can connect to others: public class Node { List<Node> connections; } I would like to make a deep copy of the entire graph. As a first attempt, I tried making a copy constructor like: public Node(Node other) { connections = new ArrayList<Node>(); for (Node n : other.connections) { connections.add(new Node(n)); } } So deep copying a graph would just be: public Graph deepCopy () { Graph g = new Graph(); g.nodes = new ArrayList<Node>(); for (Node n : nodes) { g.nodes.add(new Node(n)); } } But that doesn't work as that destroys the connection