code
stringlengths
73
34.1k
label
stringclasses
1 value
@SuppressWarnings("unckecked") public static Class<?> getRawType(Type type) { if (type instanceof Class<?>) { // type is a normal class. return (Class<?>) type; } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedTy...
java
public TaskRec eventQueueReserveTask(long taskId) { String sqlLogId = "reserve_task"; String sql = "update tedtask set status = 'WORK', startTs = $now, nextTs = null" + " where status in ('NEW','RETRY') and system = '$sys'" + " and taskid in (" + " select taskid from tedtask " + " where status in (...
java
public static void initialize() { if (InfinispanCache.get().exists(Field.IDCACHE)) { InfinispanCache.get().<Long, Field>getCache(Field.IDCACHE).clear(); } else { InfinispanCache.get().<Long, Field>getCache(Field.IDCACHE); InfinispanCache.get().<Long, Field>getCach...
java
public void configure() throws LRException { // Trim or nullify strings nodeHost = StringUtil.nullifyBadInput(nodeHost); publishAuthUser = StringUtil.nullifyBadInput(publishAuthUser); publishAuthPassword = StringUtil.nullifyBadInput(publishAuthPassword); // Throw an exce...
java
public void addDocument(LREnvelope envelope) throws LRException { if(!configured) { throw new LRException(LRException.NOT_CONFIGURED); } docs.add(envelope.getSendableData()); }
java
public void forward(String controllerName) throws Throwable { SilentGo instance = SilentGo.me(); ((ActionChain) instance.getConfig().getActionChain().getObject()).doAction(instance.getConfig().getCtx().get().getActionParam()); }
java
@Override public void characters(char[] ch, int start, int length) throws SAXException { if (vIsOpen) { value.append(ch, start, length); } if (fIsOpen) { formula.append(ch, start, length); } if (hfIsOpen) { headerFooter.append(ch, s...
java
private void checkForEmptyCellComments(XSSFSheetXMLHandlerPlus.EmptyCellCommentsCheckType type) { if (commentCellRefs != null && !commentCellRefs.isEmpty()) { // If we've reached the end of the sheet data, output any // comments we haven't yet already handled if (type == XSS...
java
private void outputEmptyCellComment(CellAddress cellRef) { XSSFComment comment = commentsTable.findCellComment(cellRef); output.cell(cellRef.formatAsString(), null, comment); }
java
public String format(GeometryIndex index) { if (index.hasChild()) { return "geometry" + index.getValue() + "." + format(index.getChild()); } switch (index.getType()) { case TYPE_VERTEX: return "vertex" + index.getValue(); case TYPE_EDGE: return "edge" + index.getValue(); default: return "g...
java
public Coordinate getVertex(Geometry geometry, GeometryIndex index) throws GeometryIndexNotFoundException { if (index.hasChild()) { if (geometry.getGeometries() != null && geometry.getGeometries().length > index.getValue()) { return getVertex(geometry.getGeometries()[index.getValue()], index.getChild()); } ...
java
public boolean isVertex(GeometryIndex index) { if (index.hasChild()) { return isVertex(index.getChild()); } return index.getType() == GeometryIndexType.TYPE_VERTEX; }
java
public boolean isEdge(GeometryIndex index) { if (index.hasChild()) { return isEdge(index.getChild()); } return index.getType() == GeometryIndexType.TYPE_EDGE; }
java
public boolean isGeometry(GeometryIndex index) { if (index.hasChild()) { return isGeometry(index.getChild()); } return index.getType() == GeometryIndexType.TYPE_GEOMETRY; }
java
public GeometryIndexType getType(GeometryIndex index) { if (index.hasChild()) { return getType(index.getChild()); } return index.getType(); }
java
public String getGeometryType(Geometry geometry, GeometryIndex index) throws GeometryIndexNotFoundException { if (index != null && index.getType() == GeometryIndexType.TYPE_GEOMETRY) { if (geometry.getGeometries() != null && geometry.getGeometries().length > index.getValue()) { return getGeometryType(geometry....
java
public int getValue(GeometryIndex index) { if (index.hasChild()) { return getValue(index.getChild()); } return index.getValue(); }
java
public GeometryIndex getParent(GeometryIndex index) { GeometryIndex parent = new GeometryIndex(index); GeometryIndex deepestParent = null; GeometryIndex p = parent; while (p.hasChild()) { deepestParent = p; p = p.getChild(); } if (deepestParent != null) { deepestParent.setChild(null); } return ...
java
public GeometryIndex getNextVertex(GeometryIndex index) { if (index.hasChild()) { return new GeometryIndex(index.getType(), index.getValue(), getNextVertex(index.getChild())); } else { return new GeometryIndex(GeometryIndexType.TYPE_VERTEX, index.getValue() + 1, null); } }
java
public Coordinate[] getSiblingVertices(Geometry geometry, GeometryIndex index) throws GeometryIndexNotFoundException { if (index.hasChild() && geometry.getGeometries() != null && geometry.getGeometries().length > index.getValue()) { return getSiblingVertices(geometry.getGeometries()[index.getValue()], inde...
java
public static LeetLevel fromString(String str) throws Exception { if (str == null || str.equalsIgnoreCase("null") || str.length() == 0) return LEVEL1; try { int i = Integer.parseInt(str); if (i >= 1 && i <= LEVELS.length) return LEVELS[i -...
java
public void addLocalTypeVariable(VariableElement ve, String signature, int index) { localTypeVariables.add(new LocalTypeVariable(ve, signature, index)); }
java
private static File writePartToFile(File splitDir, List<String> data) { BufferedWriter writer = null; File splitFile; try { splitFile = File.createTempFile("split-", ".part", splitDir); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(splitFile.getA...
java
private static long storageCalculation(int rows, int lineChars, long totalCharacters) { long size = (long) Math.ceil((rows* ARRAY_LIST_ROW_OVERHEAD + lineChars + totalCharacters) * LIST_CAPACITY_MULTIPLIER); return size; }
java
private String extractBoundary(String line) { // Use lastIndexOf() because IE 4.01 on Win98 has been known to send the // "boundary=" string multiple times. Thanks to David Wall for this fix. int index = line.lastIndexOf("boundary="); if (index == -1) { return null; } String boundary = li...
java
private static String extractContentType(String line) throws IOException { // Convert the line to a lowercase string line = line.toLowerCase(); // Get the content type, if any // Note that Opera at least puts extra info after the type, so handle // that. For example: Content-Type: text/plain; nam...
java
private String readLine() throws IOException { StringBuffer sbuf = new StringBuffer(); int result; String line; do { result = in.readLine(buf, 0, buf.length); // does += if (result != -1) { sbuf.append(new String(buf, 0, result, encoding)); } } while (result == buf.length...
java
public Set<String> getNeverGroupedIds() { String s = props.getProperty("neverGroupedIds"); if(s == null) return Collections.emptySet(); Set<String> res = new HashSet<String>(); String[] parts = s.split("[,]"); for(String part : parts) { res.add(part); ...
java
public Map<String, String> getRightIdentityIds() { String s = props.getProperty("rightIdentityIds"); if(s == null) return Collections.emptyMap(); Map<String, String> res = new HashMap<String, String>(); String[] parts = s.split("[,]"); res.put(parts[0], parts[1]); ...
java
public String serialize(Object object) { ObjectOutputStream oos = null; ByteArrayOutputStream bos = null; try { bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(object); return new String(Base64.encodeBase64(bos.toByteArray())); } catch (IOException e) { LOGGE...
java
public Object deserialize(String data) { if ((data == null) || (data.length() == 0)) { return null; } ObjectInputStream ois = null; ByteArrayInputStream bis = null; try { bis = new ByteArrayInputStream(Base64.decodeBase64(data.getBytes())); ois = new ObjectInputStream(bis); return ois.readObject()...
java
int getMethodIndex(ExecutableElement method) { TypeElement declaringClass = (TypeElement) method.getEnclosingElement(); String fullyQualifiedname = declaringClass.getQualifiedName().toString(); return getRefIndex(Methodref.class, fullyQualifiedname, method.getSimpleName().toString(), Descrip...
java
protected int getRefIndex(Class<? extends Ref> refType, String fullyQualifiedname, String name, String descriptor) { String internalForm = fullyQualifiedname.replace('.', '/'); for (ConstantInfo ci : listConstantInfo(refType)) { Ref mr = (Ref) ci; int classIndex = mr....
java
public int getNameIndex(CharSequence name) { for (ConstantInfo ci : listConstantInfo(Utf8.class)) { Utf8 utf8 = (Utf8) ci; String str = utf8.getString(); if (str.contentEquals(name)) { return constantPoolIndexMap.get(ci); } ...
java
public int getNameAndTypeIndex(String name, String descriptor) { for (ConstantInfo ci : listConstantInfo(NameAndType.class)) { NameAndType nat = (NameAndType) ci; int nameIndex = nat.getName_index(); String str = getString(nameIndex); if (name.equals(s...
java
public final int getConstantIndex(int constant) { for (ConstantInfo ci : listConstantInfo(ConstantInteger.class)) { ConstantInteger ic = (ConstantInteger) ci; if (constant == ic.getConstant()) { return constantPoolIndexMap.get(ci); } ...
java
Object getIndexedType(int index) { Object ae = indexedElementMap.get(index); if (ae == null) { throw new VerifyError("constant pool at "+index+" not proper type"); } return ae; }
java
public String getFieldDescription(int index) { ConstantInfo constantInfo = getConstantInfo(index); if (constantInfo instanceof Fieldref) { Fieldref fr = (Fieldref) getConstantInfo(index); int nt = fr.getName_and_type_index(); NameAndType nat = (NameAndType...
java
public String getMethodDescription(int index) { ConstantInfo constantInfo = getConstantInfo(index); if (constantInfo instanceof Methodref) { Methodref mr = (Methodref) getConstantInfo(index); int nt = mr.getName_and_type_index(); NameAndType nat = (NameAnd...
java
public String getClassDescription(int index) { Clazz cz = (Clazz) getConstantInfo(index); int ni = cz.getName_index(); return getString(ni); }
java
public boolean referencesMethod(ExecutableElement method) { TypeElement declaringClass = (TypeElement) method.getEnclosingElement(); String fullyQualifiedname = declaringClass.getQualifiedName().toString(); String name = method.getSimpleName().toString(); assert name.indexOf('.') == ...
java
public final String getString(int index) { Utf8 utf8 = (Utf8) getConstantInfo(index); return utf8.getString(); }
java
public static ExecutableElement getMethod(TypeElement typeElement, String name, TypeMirror... parameters) { List<ExecutableElement> allMethods = getAllMethods(typeElement, name, parameters); if (allMethods.isEmpty()) { return null; } else { Col...
java
public static List<? extends ExecutableElement> getEffectiveMethods(TypeElement cls) { List<ExecutableElement> list = new ArrayList<>(); while (cls != null) { for (ExecutableElement method : ElementFilter.methodsIn(cls.getEnclosedElements())) { if (!ov...
java
public static <T> List<T> createList(T... args) { ArrayList<T> newList = new ArrayList<T>(); Collections.addAll(newList, args); return newList; }
java
public static <T> List<T> arrayToList(T [] array) { return new ArrayList<T>(Arrays.asList(array)); }
java
public static <T> List<T> subList(List<T> list, Criteria<T> criteria) { ArrayList<T> subList = new ArrayList<T>(); for(T item : list) { if(criteria.meetsCriteria(item)) { subList.add(item); } } return subList; }
java
public String generateAuthnRequest(final String requestId) throws SAMLException { final String request = _createAuthnRequest(requestId); try { final byte[] compressed = deflate(request.getBytes("UTF-8")); return DatatypeConverter.printBase64Binary(compressed); } ...
java
public AttributeSet validateResponsePOST(final String _authnResponse) throws SAMLException { final byte[] decoded = DatatypeConverter.parseBase64Binary(_authnResponse); final String authnResponse; try { authnResponse = new String(decoded, "UTF-8"); if (LOG.isTraceEnabled(...
java
private void treeWalker(Node node, int level, List<PathQueryMatcher> queryMatchers, List<Node> collector) { MatchType matchType = queryMatchers.get(level).match(level, node); if(matchType == MatchType.NOT_A_MATCH) { // no reason to scan deeper //noinspection UnnecessaryReturnStat...
java
public String capitalize(String string) { if (string == null || string.length() < 1) { return ""; } return string.substring(0, 1).toUpperCase() + string.substring(1); }
java
public String singularize(String noun) { String singular = noun; if (singulars.get(noun) != null) { singular = singulars.get(noun); } else if (noun.matches(".*is$")) { // Singular of *is => *es singular = noun.substring(0, noun.length() - 2) + "es"; } else if (noun.matches(".*ies$")) { // Singular o...
java
public String getExtension(String url) { int dotIndex = url.lastIndexOf('.'); String extension = null; if (dotIndex > 0) { extension = url.substring(dotIndex + 1); } return extension; }
java
public void write(String... columns) throws DataUtilException { if(columns.length != tableColumns) { throw new DataUtilException("Invalid column count. Expected " + tableColumns + " but found: " + columns.length); } try { if(currentRow == 0) { ...
java
private void writeRow(String... columns) throws IOException { StringBuilder html = new StringBuilder(); html.append("<tr>"); for(String data : columns) { html.append("<td>").append(data).append("</td>"); } html.append("</tr>\n"); writer.write(html.toString());...
java
private void writeTop() throws IOException { // setup output HTML file File outputFile = new File(outputDirectory, createFilename(currentPageNumber)); writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(outputFile, false), Charset.forName(encoding))); ...
java
private void writeBottom(boolean hasNext) throws IOException { String template = Template.readResourceAsStream("com/btaz/util/templates/html-table-footer.ftl"); Map<String,Object> map = new HashMap<String,Object>(); String prev = " "; String next = ""; if(currentPageNumber > 1) {...
java
public void close() throws DataUtilException { // render footer try { if(writer != null) { writeBottom(false); } } catch (IOException e) { throw new DataUtilException("Failed to close the HTML table file", e); } }
java
public static void setEnableFileLog(boolean enable, String path, String fileName) { sEnableFileLog = enable; if (enable && path != null && fileName != null) { sLogFilePath = path.trim(); sLogFileName = fileName.trim(); if (!sLogFilePath.endsWith("/")) { ...
java
public static List<String> buildList(String... args) { List<String> newList = new ArrayList<String>(); Collections.addAll(newList, args); return newList; }
java
public static String asCommaSeparatedValues(String... args) { List<String> newList = new ArrayList<String>(); Collections.addAll(newList, args); return Strings.asTokenSeparatedValues(",", newList); }
java
public static String asTokenSeparatedValues(String token, Collection<String> strings) { StringBuilder newString = new StringBuilder(); boolean first = true; for(String str : strings) { if(! first) { newString.append(token); } first = false; ...
java
public SecureCharArray generatePassword(CharSequence masterPassword, String inputText) { return generatePassword(masterPassword, inputText, null); }
java
public SecureUTF8String generatePassword(CharSequence masterPassword, String inputText, String username) { SecureUTF8String securedMasterPassword; if ( ! (masterPassword instanceof SecureUTF8String) ) { securedMasterPassword = new SecureUTF8String(masterPassword.toString()); } else {...
java
public Account getAccountForInputText(String inputText) { if ( selectedProfile != null ) return selectedProfile; Account account = pwmProfiles.findAccountByUrl(inputText); if ( account == null ) return getDefaultAccount(); return account; }
java
public void decodeFavoritesUrls(String encodedUrlList, boolean clearFirst) { int start = 0; int end = encodedUrlList.length(); if ( encodedUrlList.startsWith("<") ) start++; if ( encodedUrlList.endsWith(">") ) end--; encodedUrlList = encodedUrlList.substring(start, end); ...
java
public void setCurrentPasswordHashPassword(String newPassword) { this.passwordSalt = UUID.randomUUID().toString(); try { this.currentPasswordHash = pwm.makePassword(new SecureUTF8String(newPassword), masterPwdHashAccount, getPasswordSalt()); } catch (Exception ig...
java
private Boolean isMainId(String id, String resource, String lastElement) { Boolean isMainId = false; if (id == null) { if (!utils.singularize(utils.cleanURL(lastElement)).equals(resource) && resource == null) { isMainId = true; } } return isMainId; }
java
Boolean isResource(String resource) { Boolean isResource = false; if (!utils.isIdentifier(resource)) { try { String clazz = getControllerClass(resource); if (clazz != null) { Class.forName(clazz); isResource = true; } } catch (ClassNotFoundException e) { // It isn't a resource becaus...
java
String getControllerClass(String resource) { ControllerFinder finder = new ControllerFinder(config); String controllerClass = finder.findResource(resource); LOGGER.debug("Controller class: {}", controllerClass); return controllerClass; }
java
protected String getSerializerClass(String resource, String urlLastElement) { String serializerClass = null; String extension = this.utils.getExtension(urlLastElement); if (extension != null) { SerializerFinder finder = new SerializerFinder(config, extension); serializerClass = finder.findResource(resource)...
java
public static void concatenate(List<File> files, File concatenatedFile) { BufferedWriter writer; try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(concatenatedFile.getAbsoluteFile(), false), DataUtilDefaults.charSet)); FileInputSt...
java
public static String getMessage(int code) { Code codeEnum = getCode(code); if (codeEnum != null) { return codeEnum.getMessage(); } else { return Integer.toString(code); } }
java
public static Pair<AlgorithmType, Boolean> fromRdfString(String str, boolean convert) throws IncompatibleException { // default if (str.length() == 0) return pair(MD5, true); // Search the list of registered algorithms for (AlgorithmType algoType : TYPES) { ...
java
@Override protected void log(final String msg) { if (config.getLogLevel().equals(LogLevel.DEBUG)) { logger.debug(msg); } else if (config.getLogLevel().equals(LogLevel.TRACE)) { logger.trace(msg); } else if (config.getLogLevel().equals(LogLevel.INFO)) { log...
java
public Object getRequest(String restUrl, Map<String, String> params) throws IOException, WebServiceException { HttpURLConnection conn = null; try { // Make the URL urlString = new StringBuilder(this.host).append(restUrl); urlString.append(this.makeParamsString(params, true)); LOGGER.debug("Doing HTTP...
java
public Object putRequest(String restUrl, Map<String, String> params) throws IOException, WebServiceException { return this.postRequest(HttpMethod.PUT, restUrl, params); }
java
public Object deleteRequest(String restUrl, Map<String, String> params) throws IOException, WebServiceException { return this.postRequest(HttpMethod.DELETE, restUrl, params); }
java
private String makeParamsString(Map<String, String> params, boolean isGet) { StringBuilder url = new StringBuilder(); if (params != null) { boolean first = true; for (Map.Entry<String, String> entry : params.entrySet()) { if (first) { if (isGet) { url.append("?"); } first = false; ...
java
private Object deserialize(String serializedObject, String extension) throws IOException { LOGGER.debug("Deserializing object [{}] to [{}]", serializedObject, extension); SerializerFinder finder = new SerializerFinder(extension); String serializerClass = finder.findResource(null); if (serializerClass == null) {...
java
public HttpResponse execute( final HttpUriRequest request ) throws IOException, ReadOnlyException { if ( readOnly ) { switch ( request.getMethod().toLowerCase() ) { case "copy": case "delete": case "move": case "patch": case "post": case "put": throw new ReadOnlyE...
java
private static String queryString( final Map<String, List<String>> params ) { final StringBuilder builder = new StringBuilder(); if (params != null && params.size() > 0) { for (final Iterator<String> it = params.keySet().iterator(); it.hasNext(); ) { final String key = it.nex...
java
public HttpGet createGetMethod(final String path, final Map<String, List<String>> params) { return new HttpGet(repositoryURL + path + queryString(params)); }
java
public HttpPatch createPatchMethod(final String path, final String sparqlUpdate) throws FedoraException { if ( isBlank(sparqlUpdate) ) { throw new FedoraException("SPARQL Update command must not be blank"); } final HttpPatch patch = new HttpPatch(repositoryURL + path); patch...
java
public HttpPost createPostMethod(final String path, final Map<String, List<String>> params) { return new HttpPost(repositoryURL + path + queryString(params)); }
java
public HttpPut createPutMethod(final String path, final Map<String, List<String>> params) { return new HttpPut(repositoryURL + path + queryString(params)); }
java
public HttpPut createTriplesPutMethod(final String path, final InputStream updatedProperties, final String contentType) throws FedoraException { if ( updatedProperties == null ) { throw new FedoraException("updatedProperties must not be null"); } els...
java
public HttpCopy createCopyMethod(final String sourcePath, final String destinationPath) { return new HttpCopy(repositoryURL + sourcePath, repositoryURL + destinationPath); }
java
public HttpMove createMoveMethod(final String sourcePath, final String destinationPath) { return new HttpMove(repositoryURL + sourcePath, repositoryURL + destinationPath); }
java
public static void leetConvert(LeetLevel level, SecureCharArray message) throws Exception { // pre-allocate an array that is 4 times the size of the message. I don't // see anything in the leet-table that is larger than 3 characters, but I'm // using 4-characters to calcualte the si...
java
public String getValue(final ConfigParam param) { if (param == null) { return null; } // Buscamos en las variables del sistema Object obj = System.getProperty(param.getName()); // Si no, se busca en el fichero de configuracion if (obj == null) { ob...
java
private void init() throws ConfigFileIOException { this.props = new Properties(); log.info("Reading config file: {}", this.configFile); boolean ok = true; try { // El fichero esta en el CLASSPATH this.props.load(SystemConfig.class.getResourceAsStream(this.configFi...
java
public static void sortFile(File sortDir, File inputFile, File outputFile, Comparator<String> comparator, boolean skipHeader) { sortFile(sortDir, inputFile, outputFile, comparator, skipHeader, DEFAULT_MAX_BYTES, MERGE_FACTOR); }
java
public static void sortFile(File sortDir, File inputFile, File outputFile, Comparator<String> comparator, boolean skipHeader, long maxBytes, int mergeFactor) { // validation if(comparator == null) { comparator = Lexical.ascending(); } // steps...
java
public void setWideIndex(boolean wideIndex) { this.wideIndex = wideIndex; if (types != null) { for (TypeASM t : types.values()) { Assembler as = (Assembler) t; as.setWideIndex(wideIndex); } } }
java
public void fixAddress(String name) throws IOException { Label label = labels.get(name); if (label == null) { label = new Label(name); labels.put(name, label); } int pos = position(); label.setAddress(pos); labelMap.put(pos, label); ...
java
public Branch createBranch(String name) throws IOException { Label label = labels.get(name); if (label == null) { label = new Label(name); labels.put(name, label); } return label.createBranch(position()); }
java
public void ifeq(String target) throws IOException { if (wideIndex) { out.writeByte(NOT_IFEQ); out.writeShort(WIDEFIXOFFSET); Branch branch = createBranch(target); out.writeByte(GOTO_W); out.writeInt(branch); } else ...
java
public void ifne(String target) throws IOException { if (wideIndex) { out.writeByte(NOT_IFNE); out.writeShort(WIDEFIXOFFSET); Branch branch = createBranch(target); out.writeByte(GOTO_W); out.writeInt(branch); } else ...
java
public void iflt(String target) throws IOException { if (wideIndex) { out.writeByte(NOT_IFLT); out.writeShort(WIDEFIXOFFSET); Branch branch = createBranch(target); out.writeByte(GOTO_W); out.writeInt(branch); } else ...
java