如果您正在构建一些线性链(java的StringBuilder)或创建具有许多属性的对象(PizzaBuilder),那么构建器模式似乎很好.
是否可以扩展以构建一个树而不指定可能混淆的节点位置?
a
/ | \
c d e
/ \
f g
TreeBuilder tb.addNode(levelNumber, parentNumber, nodeName) // I think this is terrible
tb.addNode(2, 3, g) //terrible
Run Code Online (Sandbox Code Playgroud)
或者这种模式不是一个好主意?
谢谢
更新 - 请参阅底部的编辑
IDRefs/keyrefs似乎可以在JAXB注释中使用,但ref最终是元素文本.
我希望ref成为元素的属性.
例如,给定此对象模型:
@XmlType
public class Employee {
@XmlID
@XmlAttribute
String name;
@XmlAttribute
int years;
@XmlAttribute
String foo;
}
@XmlType
public class Office {
@XmlAttribute
String name;
@XmlElementWrapper
@XmlElement(name = "employee")
List<Employee> employees;
}
@XmlRootElement
public class Company {
@XmlElementWrapper
@XmlElement(name = "office")
List<Office> offices;
@XmlElementWrapper
@XmlElement(name = "employee")
List<Employee> employees;
}
Run Code Online (Sandbox Code Playgroud)
我希望外化的xml格式最终看起来像这样:
<company>
<offices>
<office name="nyc">
<employees>
<!--*** id ref to employee name ***-->
<employee ref="alice"/>
<employee ref="bob"/>
</employees>
</office>
<office name="sf">
<employees>
<employee ref="connie"/>
<employee …Run Code Online (Sandbox Code Playgroud) 我很难理解为什么会发生以下错误.如果#1没问题,为什么#2不行呢?
public interface IFoobar<DATA extends IFoobar> {
void bigFun();
}
class FoobarImpl<DATA extends IFoobar> implements IFoobar<DATA> {
public void bigFun() {
DATA d = null;
IFoobar<DATA> node = d; //#1 ok
d = node; //#2 error
}
}
Run Code Online (Sandbox Code Playgroud) 我的理解是计算百分位数,需要对数据进行排序.这可能是因为大量数据分布在多个服务器上而不会移动它们吗?
根据maven程序集插件文档,允许相对目录,但"......"似乎根本不起作用.
由于我无法进入(并且我无法更改)的原因,我想在程序集中包含maven项目目录之外的一些文件.
/-
---maven-project/
---some-crap/
Run Code Online (Sandbox Code Playgroud)
我尝试了各种各样的事情:
<fileSets>
<fileSet>
<directory>${project.basedir}/../some-crap</directory>
<outputDirectory>crapdir</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileset>
Run Code Online (Sandbox Code Playgroud)
要么
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>crapdir</outputDirectory>
<includes>
<include>../some-crap/**/*</include>
</includes>
</fileSet>
</fileset>
Run Code Online (Sandbox Code Playgroud)
要么
<fileSets>
<fileSet>
<directory>../some-crap</directory>
<outputDirectory>crapdir</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileset>
Run Code Online (Sandbox Code Playgroud)
我的maven版本是3.0.4(最新)
除了在蚂蚁中写东西以获取这些东西或在组装之前将其复制到我的目标目录之外,我能做些什么吗?
我真的认为程序集插件将".."视为目录名而不是"上升一级".
谢谢.
我有一个shared_ptr,它将被多个线程访问。我使用shared_ptr 的std :: atomic 函数来使该线程安全。std :: atomic_is_lock_free()检查std :: atomic是否真正使用CPU原子操作而不是锁。
此功能的注释如下:
除std :: atomic_flag以外的所有原子类型都可以使用互斥锁或其他锁定操作来实现,而不是使用无锁原子CPU指令来实现。原子类型有时也可以是无锁的,例如,如果在给定的体系结构上,只有对齐的内存访问自然是原子的,则相同类型的未对齐对象必须使用锁。如果类型有时是无锁的,则必须使用函数(1)或其成员函数等效项来确定特定实例是否无锁。
在MacOS Mavericks(带有c ++ 11 std)和Linux CentOS 5.6(带有boost)上运行这段代码都返回false。我认为x86_64具有相当强大的原子操作。
#include <iostream>
#include <unordered_map>
#include <atomic>
#include <memory>
typedef std::unordered_map<std::string, std::string> StringMap;
int main()
{
std::shared_ptr<StringMap> pMap;
std::atomic_store(&pMap, std::make_shared<StringMap>());
std::cout << "unordered_map ptr is lock free:" << std::boolalpha << std::atomic_is_lock_free(&pMap) << "\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的问题:就这些指针操作是无锁的而言,我是否很幸运,还是有其他选择?
编辑 这返回true:
std::atomic<StringMap*> apMap;
std::cout << "atomic ptr is lock free:" << std::boolalpha << apMap.is_lock_free() << "\n";
Run Code Online (Sandbox Code Playgroud) 我正在使用boost :: interprocess :: vector在进程之间共享一些字符串,我想确保不会溢出它所在的共享内存段.
如何找到向量在内存中占用的空间,以及特殊的段分配字符串将占用多少内存?
typedef boost::interprocess::managed_shared_memory::segment_manager SegmentManager;
typedef boost::interprocess::allocator<char, SegmentManager> CharAllocator;
typedef boost::interprocess::basic_string<char, std::char_traits<char>, CharAllocator> ShmString;
typedef boost::interprocess::allocator<ShmString, SegmentManager> StringAllocator;
typedef boost::interprocess::vector<ShmString, StringAllocator> ShmStringVector;
const size_t SEGMENT_SIZE = ...;
addToSharedVector(std::string localString){
using namespace boost::interprocess;
managed_shared_memory segment(open_only, kSharedMemorySegmentName);
ShmStringVector *shmvector = segment.find<ShmStringVector>(kSharedMemoryVectorName).first;
size_t currentVectorSizeInShm = ?????(shmvector); <-------- HALP!
size_t sizeOfNewStringInSharedMemory = ?????(localString); <--------
//shared mutex not shown for clarity
if (currentVectorSizeInShm + sizeOfNewStringInSharedMemory < SEGMENT_SIZE) {
CharAllocator charAllocator(segment.get_segment_manager());
ShmString shmString(charAllocator);
shmFunctionName = localString.c_str();
shmvector->push_back(shmString);
}
}
Run Code Online (Sandbox Code Playgroud) 我在我的Windows 7框中安装了虚拟框4.3.28,试图打开导入的VM并得到以下错误.
我已经看到大约两年前的一些帖子说这是一些Windows安全修复的问题,但我没有安装该修复程序,我已经安装了所谓的治疗方法,但无济于事.
KB3004394不在我的系统上
那些没有帮助我的旧修补程序(我没有在我的计算机上看到违规的KB文件)
https://www.virtualbox.org/ticket/13677
错误我看到:
1618.161c: supR3HardenedScreenImage/LdrLoadDll: cache hit (Unknown Status -22900 (0xffffa68c)) on \Device\HarddiskVolume1\Windows\System32\crypt32.dll
1618.161c: Error (rc=0):
1618.161c: supR3HardenedScreenImage/LdrLoadDll: cached rc=Unknown Status -22900 (0xffffa68c) fImage=1 fProtect=0x0 fAccess=0x0 cHits=8 \Device\HarddiskVolume1\Windows\System32\crypt32.dll
1618.161c: Error (rc=0):
1618.161c: supR3HardenedMonitor_LdrLoadDll: rejecting 'C:\windows\system32\crypt32.dll' (C:\windows\system32\crypt32.dll): rcNt=0xc0000190
1618.161c: supR3HardenedMonitor_LdrLoadDll: returns rcNt=0xc0000190 'C:\windows\system32\crypt32.dll'
1618.161c: Fatal error:
1618.161c: Error loading 'crypt32.dll': 1790 [C:\windows\system32\crypt32.dll]
Run Code Online (Sandbox Code Playgroud) 我有一个函数传递给and_then它返回编译器未知的类型。当与其他选项方法链接时,需要类型注释。
fn main() {
let w = Some("hi".to_string());
let x: Option<&String> = w.as_ref();
//fails:
let y: Option<String> =
x.and_then::<String, FnOnce(Option<&String>) -> Option<String>>(|_inner: &String| None);
//ok:
let y: Option<String> = x.and_then(|_inner: &String| None);
}
Run Code Online (Sandbox Code Playgroud)
添加强制注释会导致此编译器错误:
fn main() {
let w = Some("hi".to_string());
let x: Option<&String> = w.as_ref();
//fails:
let y: Option<String> =
x.and_then::<String, FnOnce(Option<&String>) -> Option<String>>(|_inner: &String| None);
//ok:
let y: Option<String> = x.and_then(|_inner: &String| None);
}
Run Code Online (Sandbox Code Playgroud)
我认为它是在抱怨这种FnOnce特性,但我不明白这与x.
我想了解这里出了什么问题。
最终,目标是and_then在链式语句中实现这一点,这就是需要注释的原因。
let y …Run Code Online (Sandbox Code Playgroud) 似乎在 2021 年 11 月版本的 Intellij 中,编辑器已开始在项目结构视图中显示方法。如果您的光标位于编辑器中的某个方法上,项目结构将打开并跳转到该方法。
我想禁用它并返回到不显示方法的旧式项目结构。
java ×6
c++ ×2
atomic ×1
boost ×1
c++11 ×1
concurrency ×1
generics ×1
jaxb ×1
mapreduce ×1
maven ×1
maven-3 ×1
percentile ×1
rust ×1
shared-ptr ×1
statistics ×1
tree ×1
virtualbox ×1
windows ×1