code
stringlengths
73
34.1k
label
stringclasses
1 value
public static DateLabel forDateTime(String id, Date date) { return DateLabel.forDatePattern(id, new Model<Date>(date), DATE_TIME_PATTERN); }
java
protected Entry get( DirectoryEntry parent, String name ) { parent.getClass(); Entry[] entries = listEntries( parent ); if ( entries != null ) { for ( int i = 0; i < entries.length; i++ ) { if ( name.equals( entries[i].getName() ) ) ...
java
private File toFile( Entry entry ) { Stack<String> stack = new Stack<String>(); Entry entryRoot = entry.getFileSystem().getRoot(); while ( entry != null && !entryRoot.equals( entry ) ) { String name = entry.getName(); if ( "..".equals( name ) ) { ...
java
public static void validateSchema(Bean bean) { validateId(bean); validatePropertyNames(bean); validateReferences(bean); validateProperties(bean); validatePropertyList(bean); validatePropertyReferences(bean); validatePropertyRefList(bean); validatePropertyR...
java
public final void initializeReferences(Collection<Bean> beans) { Map<BeanId, Bean> indexed = BeanUtils.uniqueIndex(beans); for (Bean bean : beans) { for (String name : bean.getReferenceNames()) { List<BeanId> ids = bean.getReference(name); if (ids == null...
java
public static Schema create(SchemaId id, final String classType, final String name, final String description) { return new Schema(id, classType, name, description); }
java
public Class<?> getClassType() { try { return Class.forName(getType(), true, ClassLoaderHolder.getClassLoader()); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } }
java
public void add(AbstractSchemaProperty property) { Class type = property.getClass(); properties.put(type, property); if (SchemaProperty.class.isAssignableFrom(type)) { propertyNames.add(property.getName()); } else if (SchemaPropertyList.class.isAssignableFrom(type)) { ...
java
public <T extends AbstractSchemaProperty> Set<T> getIndexed() { HashSet<AbstractSchemaProperty> indexed = new HashSet<>(); for (AbstractSchemaProperty prop : properties.values()) { if (prop.isIndexed()) indexed.add(prop); } return (Set<T>) indexed; }
java
@SuppressWarnings({ "unchecked", "rawtypes" }) public <T extends AbstractSchemaProperty> Set<T> get(final Class<T> clazz) { return (Set<T>) properties.get(clazz); }
java
public <T extends AbstractSchemaProperty> T get(final Class<T> clazz, final String name) { Set<T> propertyCollection = get(clazz); for (T property : propertyCollection) { if (property.getName().equals(name)) { return property; } } return null; ...
java
public void setVelocityPropertiesMap(Map<String, Object> velocityPropertiesMap) { if (velocityPropertiesMap != null) { this.velocityProperties.putAll(velocityPropertiesMap); } }
java
public VelocityEngine createVelocityEngine() throws IOException, VelocityException { VelocityEngine velocityEngine = newVelocityEngine(); Map<String, Object> props = new HashMap<String, Object>(); // Load config file if set. if (this.configLocation != null) { if (logger.isInfoEnabled()) { logger.info("L...
java
private synchronized void set( Artifact artifact, Content content ) { Map<String, Map<String, Map<Artifact, Content>>> artifactMap = contents.get( artifact.getGroupId() ); if ( artifactMap == null ) { artifactMap = new HashMap<String, Map<String, Map<Artifact, Content>>>(); ...
java
public static BeanId create(final String instanceId, final String schemaName) { if (instanceId == null || "".equals(instanceId)) { throw CFG107_MISSING_ID(); } return new BeanId(instanceId, schemaName); }
java
public static boolean isPredecessor(KeyValue kv) { if (Bytes.equals(kv.getFamily(), PRED_COLUMN_FAMILY)) { return true; } return false; }
java
public static HOTPProvider instantiateProvider(boolean allowTestProvider) { HOTPProvider resultProvider = null; ServiceLoader<HOTPProvider> loader = ServiceLoader.load(HOTPProvider.class); Iterator<HOTPProvider> iterator = loader.iterator(); if (iterator.hasNext()) { while (i...
java
public static Lookup get() { if (LOOKUP != null) { return LOOKUP; } synchronized (Lookup.class) { // allow for override of the Lookup.class String overrideClassName = System.getProperty(Lookup.class.getName()); ClassLoader l = Thread.currentThread(...
java
private static String formatName( String name ) { if ( name.length() < NAME_COL_WIDTH ) { return name; } return name.substring( 0, NAME_COL_WIDTH - 1 ) + ">"; }
java
private void instrument(CtClass proxy, final SchemaPropertyRef ref) throws Exception { final Schema schema = schemas.get(ref.getSchemaName()); checkNotNull(schema, "Schema not found for SchemaPropertyRef ["+ref+"]"); final String fieldName = ref.getFieldName(); // for help on javassist s...
java
public static byte[] remove(byte[] arr, int n) { int index = binarySearch(arr, n); byte[] arr2 = new byte[arr.length - 4]; System.arraycopy(arr, 0, arr2, 0, index); System.arraycopy(arr, index + 4, arr2, index, arr.length - index - 4); return arr2; }
java
public static int binarySearch(byte[] a, int key) { int low = 0; int high = a.length; while (low < high) { int mid = (low + high) >>> 1; if (mid % 4 != 0) { if (high == a.length) { mid = low; } else { ...
java
protected FileSystemServer createFileSystemServer( ArtifactStore artifactStore ) { return new FileSystemServer( ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ), Math.max( 0, Math.min( port, 65535 ) ), new...
java
public static void deleteProperties(BeanId id) { Query query = getEmOrFail().createNamedQuery(DELETE_ALL_PROPERTIES_FOR_BEANID_NAME); query.setParameter(1, id.getInstanceId()); query.setParameter(2, id.getSchemaName()); query.setParameter(3, BEAN_MARKER_PROPERTY_NAME); que...
java
public static void deletePropertiesAndMarker(BeanId id) { Query query = getEmOrFail().createNamedQuery(DELETE_ALL_PROPERTIES_FOR_BEANID_NAME); query.setParameter(1, id.getInstanceId()); query.setParameter(2, id.getSchemaName()); // empty will marker will delete the marker aswell ...
java
public static void filterMarkerProperty(List<JpaProperty> properties) { ListIterator<JpaProperty> propIt = properties.listIterator(); while (propIt.hasNext()) { if (BEAN_MARKER_PROPERTY_NAME.equals(propIt.next().getPropertyName())) { propIt.remove(); } ...
java
public static <A extends Comparable<A>> BeanRestriction between(String property, A lower, A upper) { return new Between<>(property, lower, upper); }
java
public final void fireCreate(Collection<Bean> beans) { ConfigChanges changes = new ConfigChanges(); for (Bean bean : beans) { changes.add(ConfigChange.created(bean)); } fire(changes); }
java
public final ConfigChanges deleted(String schemaName, Collection<String> instanceIds) { ConfigChanges changes = new ConfigChanges(); for (String instanceId : instanceIds) { BeanId id = BeanId.create(instanceId, schemaName); Optional<Bean> before = beanManager.getEager(id); ...
java
public final void fireDelete(List<Bean> beans) { ConfigChanges changes = new ConfigChanges(); for (Bean bean : beans) { changes.add(ConfigChange.deleted(bean)); } fire(changes); }
java
public final ConfigChanges updated(Collection<Bean> after) { ConfigChanges changes = new ConfigChanges(); for (Bean bean : after) { Optional<Bean> optional = beanManager.getEager(bean.getId()); if (!optional.isPresent()) { throw Events.CFG304_BEAN_DOESNT_EXIST(bea...
java
private static Path parsePathExpression(Iterator<Token> expression, ConfigOrigin origin, String originalText) { // each builder in "buf" is an element in the path. List<Element> buf = new ArrayList<Element>(); buf.add(new Element("", false)); if (!expression.hasNext()) { ...
java
private static boolean hasUnsafeChars(String s) { for (int i = 0; i < s.length(); ++i) { char c = s.charAt(i); if (Character.isLetter(c) || c == '.') continue; else return true; } return false; }
java
public static void setShort(final byte[] b, final short n, final int offset) { b[offset + 0] = (byte) (n >>> 8); b[offset + 1] = (byte) (n >>> 0); }
java
public static void setInt(final byte[] b, final int n, final int offset) { b[offset + 0] = (byte) (n >>> 24); b[offset + 1] = (byte) (n >>> 16); b[offset + 2] = (byte) (n >>> 8); b[offset + 3] = (byte) (n >>> 0); }
java
public static void setLong(final byte[] b, final long n, final int offset) { b[offset + 0] = (byte) (n >>> 56); b[offset + 1] = (byte) (n >>> 48); b[offset + 2] = (byte) (n >>> 40); b[offset + 3] = (byte) (n >>> 32); b[offset + 4] = (byte) (n >>> 24); b[offset + 5] = (byt...
java
public Set<HBeanRow> filterUnvisted(Set<HBeanRow> rows) { Set<HBeanRow> unvisted = new HashSet<>(); for (HBeanRow row : rows) { if (!references.containsKey(row) && !inital.containsKey(row)) { unvisted.add(row); } } return unvisted; }
java
public List<Bean> getBeans() { Map<BeanId, Bean> referenceMap = new HashMap<>(); List<Bean> result = new ArrayList<>(); for (HBeanRow row : inital.keySet()) { Bean bean = row.getBean(); result.add(bean); referenceMap.put(bean.getId(), bean); } ...
java
public static void validatePublicKey(String value, PublicKeyCrypto crypto) throws BadPublicKeyException { if (org.springframework.util.StringUtils.hasText(value)) { int open = value.indexOf("-----BEGIN PGP PUBLIC KEY BLOCK-----"); int close = value.indexOf("-----END PGP PUBLIC KEY BLOCK-...
java
private static boolean hasReferences(Bean target, BeanId reference) { for (String name : target.getReferenceNames()) { for (BeanId ref : target.getReference(name)) { if (ref.equals(reference)) { return true; } } } return...
java
public static long getId(final byte[] rowkey) { return (rowkey[0] & 0xFFL) << 40 | (rowkey[1] & 0xFFL) << 32 | (rowkey[2] & 0xFFL) << 24 | (rowkey[3] & 0xFFL) << 16 | (rowkey[4] & 0xFFL) << 8 | (rowkey[5] & 0xFFL) << 0; }
java
private static byte[] getRowKey(long id) { final byte[] b = new byte[6]; b[0] = (byte) (id >>> 40); b[1] = (byte) (id >>> 32); b[2] = (byte) (id >>> 24); b[3] = (byte) (id >>> 16); b[4] = (byte) (id >>> 8); b[5] = (byte) (id >>> 0); return b; }
java
public static byte[] getRowKey(final BeanId id, final UniqueIds uids) { final byte[] iid = uids.getUiid().getId(id.getInstanceId()); final byte[] sid = uids.getUsid().getId(id.getSchemaName()); final byte[] rowkey = new byte[sid.length + iid.length]; System.arraycopy(sid, 0, rowkey, 0, s...
java
public static void setColumnFilter(Object op, FetchType... column) { ArrayList<byte[]> columns = new ArrayList<>(); columns.add(DUMMY_COLUMN_FAMILY); if (column.length == 0) { // default behaviour columns.add(PROP_COLUMN_FAMILY); columns.add(PRED_COLUMN_FAMILY...
java
public <T> T convert(final Object source, final Class<T> targetclass) { if (source == null) { return null; } final Class<?> sourceclass = source.getClass(); if (targetclass.isPrimitive() && String.class.isAssignableFrom(sourceclass)) { return (T) parsePrimitive(s...
java
private List<Bean> findReferences(BeanId reference, Collection<Bean> predecessors, ArrayList<Bean> matches, ArrayList<Bean> checked) { for (Bean predecessor : predecessors) { findReferences(reference, predecessor, matches, checked); } return matches; }
java
@SuppressWarnings("unused") private void initalizeReferences(Collection<Bean> beans) { Map<BeanId, Bean> userProvided = BeanUtils.uniqueIndex(beans); for (Bean bean : beans) { for (String name : bean.getReferenceNames()) { List<BeanId> values = bean.getReference(name); ...
java
@Override public void execute() throws BuildException { try { DirectoryScanner dsc = fileset.getDirectoryScanner(getProject()); File baseDir = dsc.getBasedir(); String[] files = dsc.getIncludedFiles(); for (int i = 0; i < files.length; i++) { St...
java
public static Set<Bean> getBeanToValidate(Set<BeanId> ids) { List<JpaRef> targetPredecessors = JpaRef.getDirectPredecessors(ids); Set<BeanId> beansToValidate = new HashSet<>(); for (JpaRef ref : targetPredecessors) { beansToValidate.add(ref.getSource()); } beans...
java
@SuppressWarnings("unused") private static JpaBean getJpaBeanAndProperties(BeanId id) { List<JpaProperty> props = JpaProperty.findProperties(id); if (props.size() == 0) { // no marker, bean does not exist return null; } JpaBean bean = new JpaBean(new Jp...
java
private static void join(ArrayList<AbstractConfigValue> builder, AbstractConfigValue origRight) { AbstractConfigValue left = builder.get(builder.size() - 1); AbstractConfigValue right = origRight; // check for an object which can be converted to a list // (this will be an object with nu...
java
public static void mergeTemplate( VelocityEngine velocityEngine, String templateLocation, String encoding, Map<String, Object> model, Writer writer) throws VelocityException { VelocityContext velocityContext = new VelocityContext(model); velocityEngine.mergeTemplate(templateLocation, encoding, velocityContex...
java
public static long parseDuration(String input, ConfigOrigin originForException, String pathForException) { String s = ConfigImplUtil.unicodeTrim(input); String originalUnitString = getUnits(s); String unitString = originalUnitString; String numberString = ConfigImplUtil.unico...
java
public static Restriction in(String property, Object... values) { return new In(property, Arrays.asList(values)); }
java
public static Restriction and(Restriction r1, Restriction r2) { return new And(Arrays.asList(r1, r2)); }
java
public static Restriction or(Restriction r1, Restriction r2) { return new Or(Arrays.asList(r1, r2)); }
java
@Override public void send(MidiMessage message, long timeStamp) { if (this.launchpadReceiver != null && message instanceof ShortMessage) { ShortMessage sm = (ShortMessage) message; Pad pad = Pad.findMidi(sm); if (pad != null) { this.launchpadReceiver.receive(pad); } } }
java
private synchronized List<Entry> getEntriesList( DirectoryEntry directory ) { List<Entry> entries = contents.get( directory ); if ( entries == null ) { entries = new ArrayList<Entry>(); contents.put( directory, entries ); } return entries; }
java
public Object getObjectReference(String field, String schemaName) { List<String> instanceIds = references.get(field); if(instanceIds == null || instanceIds.size() == 0) { return null; } String instanceId = instanceIds.get(0); if(instanceId == null) { retur...
java
public Collection<Object> getObjectReferenceList(String field, String schemaName) { List<String> instanceIds = references.get(field); if(instanceIds == null || instanceIds.size() == 0) { return null; } List<Object> objects = new ArrayList<>(); for (String instanceId :...
java
public Map<String, Object> getObjectReferenceMap(String field, String schemaName) { List<String> instanceIds = references.get(field); if(instanceIds == null || instanceIds.size() == 0) { return null; } Map<String, Object> objects = new HashMap<>(); for (String instanc...
java
static SysProperties toSystemProperties(final String[] arguments) { final SysProperties retVal = new SysProperties(); if (arguments != null && arguments.length != 0) { for (final String argument : arguments) { if (argument.startsWith("-D")) { ...
java
private static Variable toVariable(final String argument) { final Variable retVal = new Variable(); final int equalSignIndex = argument.indexOf('='); if (equalSignIndex == -1) { final String key = argument.substring(2); retVal.setKey(key); } else { ...
java
public static String[][] getProperties(final Bean bean) { final List<String> propertyNames = bean.getPropertyNames(); final int psize = propertyNames.size(); final String[][] properties = new String[psize][]; for (int i = 0; i < psize; i++) { final String propertyName = prope...
java
public void setPropertiesOn(final Bean bean) { String[][] properties = getProperties(); for (int i = 0; i < properties.length; i++) { if (properties[i].length < 2) { continue; } for (int j = 0; j < properties[i].length - 1; j++) { bean....
java
public static String getPropertyName(KeyValue kv, UniqueIds uids) { final byte[] qualifier = kv.getQualifier(); final byte[] pid = new byte[] { qualifier[2], qualifier[3] }; final String propertyName = uids.getUsid().getName(pid); return propertyName; }
java
public static boolean isProperty(KeyValue kv) { if (Bytes.equals(kv.getFamily(), PROP_COLUMN_FAMILY)) { return true; } return false; }
java
public HBeanRowCollector listEager(String schemaName, FetchType... fetchType) throws HBeanNotFoundException { Set<HBeanRow> rows = listLazy(schemaName, fetchType); HBeanRowCollector collector = new HBeanRowCollector(rows); getEager(rows, collector, FETCH_DEPTH_MAX, fetchType); ...
java
public HBeanRowCollector getEager(Set<HBeanRow> rows, FetchType... fetchType) throws HBeanNotFoundException { Set<HBeanRow> result; result = getLazy(rows, fetchType); HBeanRowCollector collector = new HBeanRowCollector(result); getEager(result, collector, FETCH_DEPTH_MAX, fet...
java
public void put(Set<HBeanRow> rows) { final List<Row> create = new ArrayList<>(); try { for (HBeanRow row : rows) { final Put write = new Put(row.getRowKey()); if (row.getPropertiesKeyValue() != null) { write.add(row.getPropertiesKeyValue()...
java
private void getEager(Set<HBeanRow> rows, HBeanRowCollector collector, int level, FetchType... fetchType) throws HBeanNotFoundException { int size = rows.size(); if (size == 0) { return; } if (--level < 0) { return; } Set<HBeanRow> refs...
java
public void delete(Set<HBeanRow> rows) { final List<Row> delete = new ArrayList<>(); try { for (HBeanRow row : rows) { delete.add(new Delete(row.getRowKey())); } table.batch(delete); table.flushCommits(); } catch (Exception e) { ...
java
public static Optional<ValidationManager> lookup() { ValidationManager manager = lookup.lookup(ValidationManager.class); if (manager != null) { return Optional.of(manager); } else { return Optional.absent(); } }
java
public void addProperties(List<JpaProperty> queryProperties) { for (JpaProperty prop : queryProperties) { Bean bean = putIfAbsent(prop.getId()); if (!JpaProperty.BEAN_MARKER_PROPERTY_NAME.equals(prop.getPropertyName())) { bean.addProperty(prop.getPropertyName(), prop.getV...
java
public void addRefs(Multimap<BeanId, JpaRef> queryRefs) { refs.putAll(queryRefs); for (BeanId id : refs.keySet()) { putIfAbsent(id); for (JpaRef ref : refs.get(id)) { putIfAbsent(ref.getTarget()); } } }
java
public Set<BeanId> getIds() { Set<BeanId> ids = new HashSet<>(); ids.addAll(beansQuery); ids.addAll(beans.keySet()); return ids; }
java
private Bean putIfAbsent(BeanId id) { Bean bean = beans.get(id); if (bean == null) { bean = Bean.create(id); beans.put(id, bean); } return bean; }
java
public List<Bean> assembleBeans() { connectReferences(); if (beansQuery.size() == 0) { // if no specific beans where requested (such as query for a // specific schema) return what is available. return new ArrayList<>(beans.values()); } List<Bean> init...
java
private void connectReferences() { // ready to associate initalized beans with references for (Bean bean : beans.values()) { for (JpaRef ref : refs.get(bean.getId())) { BeanId target = ref.getTarget(); Bean targetBean = beans.get(target); targe...
java
private Set<Bean> flattenReferences(Bean bean) { Set<Bean> beans = new HashSet<>(); for (String referenceName : bean.getReferenceNames()) { List<BeanId> ids = bean.getReference(referenceName); for (BeanId id : ids) { if (id.getBean() == null) { ...
java
public static UniqueIds createUids(Configuration conf) { UniqueId usid = new UniqueId(SID_TABLE, SID_WIDTH, conf, true); UniqueId uiid = new UniqueId(IID_TABLE, IID_WIDTH, conf, true); UniqueId upid = new UniqueId(PID_TABLE, PID_WIDTH, conf, true); return new UniqueIds(uiid, usid, upid);...
java
private byte[] getContent() throws IOException { InputStream is = null; try { MessageDigest digest = MessageDigest.getInstance( "MD5" ); digest.reset(); byte[] buffer = new byte[8192]; int read; try { ...
java
AbstractConfigValue peekPath(Path path) { try { return peekPath(this, path, null); } catch (NotPossibleToResolve e) { throw new BugOrBroken( "NotPossibleToResolve happened though we had no ResolveContext in peekPath"); } }
java
private static AbstractConfigValue peekPath(AbstractConfigObject self, Path path, ResolveContext context) throws NotPossibleToResolve { try { if (context != null) { // walk down through the path resolving only things along that // path, and then recursivel...
java
public String getName() { if ( name == null ) { name = MessageFormat.format( "{0}-{1}{2}.{3}", new Object[]{ artifactId, getTimestampVersion(), ( classifier == null ? "" : "-" + classifier ), type } ); } return name; }
java
public static Bean create(final BeanId id) { Preconditions.checkNotNull(id); Bean bean = new Bean(id); bean.set(id.getSchema()); return bean; }
java
public List<String> getPropertyNames() { ArrayList<String> names = new ArrayList<>(properties.keySet()); Collections.sort(names); return names; }
java
public List<String> getReferenceNames() { ArrayList<String> names = new ArrayList<>(references.keySet()); Collections.sort(names); return names; }
java
public void addProperty(final String propertyName, final Collection<String> values) { Preconditions.checkNotNull(values); Preconditions.checkNotNull(propertyName); List<String> list = properties.get(propertyName); if (list == null) { properties.put(propertyName, new ArrayList...
java
public void addProperty(final String propertyName, final String value) { Preconditions.checkNotNull(propertyName); Preconditions.checkNotNull(value); List<String> values = properties.get(propertyName); if (values == null) { values = new ArrayList<>(); values.add(v...
java
public void setProperty(final String propertyName, final String value) { Preconditions.checkNotNull(propertyName); if (value == null) { properties.put(propertyName, null); return; } List<String> values = new ArrayList<>(); values.add(value); proper...
java
public void clear(final String propertyName) { Preconditions.checkNotNull(propertyName); if (properties.containsKey(propertyName)) { properties.put(propertyName, null); } else if (references.containsKey(propertyName)) { references.put(propertyName, null); } }
java
public void remove(final String propertyName) { Preconditions.checkNotNull(propertyName); if (properties.containsKey(propertyName)) { properties.remove(propertyName); } else if (references.containsKey(propertyName)) { references.remove(propertyName); } }
java
public List<String> getValues(final String propertyName) { Preconditions.checkNotNull(propertyName); List<String> values = properties.get(propertyName); if (values == null) { return null; } // creates a shallow defensive copy return new ArrayList<>(values); ...
java
public String getSingleValue(final String propertyName) { Preconditions.checkNotNull(propertyName); List<String> values = getValues(propertyName); if (values == null || values.size() < 1) { return null; } return values.get(0); }
java
public void addReference(final String propertyName, final Collection<BeanId> refs) { Preconditions.checkNotNull(refs); Preconditions.checkNotNull(propertyName); checkCircularReference(refs.toArray(new BeanId[refs.size()])); List<BeanId> list = references.get(propertyName); if (li...
java
private void checkCircularReference(final BeanId... references) { for (BeanId beanId : references) { if (getId().equals(beanId)) { throw CFG310_CIRCULAR_REF(getId(), getId()); } } }
java
public void addReference(final String propertyName, final BeanId ref) { Preconditions.checkNotNull(ref); Preconditions.checkNotNull(propertyName); checkCircularReference(ref); List<BeanId> list = references.get(propertyName); if (list == null) { list = new ArrayList<>...
java
public List<BeanId> getReference(final String propertyName) { List<BeanId> values = references.get(propertyName); if (values == null) { return null; } return values; }
java
public List<BeanId> getReferences() { if (references == null) { return new ArrayList<>(); } ArrayList<BeanId> result = new ArrayList<>(); for (List<BeanId> b : references.values()) { if (b != null) { result.addAll(b); } } ...
java