code
stringlengths 11
173k
| docstring
stringlengths 2
593k
| func_name
stringlengths 2
189
| language
stringclasses 1
value | repo
stringclasses 844
values | path
stringlengths 11
294
| url
stringlengths 60
339
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public static byte[] getSizeLEInt32(final int size)
{
final byte[] b = new byte[4];
b[0] = (byte) (size & 0xff);
b[1] = (byte) ((size >>> 8) & 0xffL);
b[2] = (byte) ((size >>> 16) & 0xffL);
b[3] = (byte) ((size >>> 24) & 0xffL);
return b;
} |
Convert int to byte representation - Little Endian (as used by ogg vorbis).
@param size number to convert
@return byte representation
| Utils::getSizeLEInt32 | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static String readPascalString(final ByteBuffer bb) throws IOException {
final int len = Utils.u(bb.get()); //Read as unsigned value
final byte[] buf = new byte[len];
bb.get(buf);
return new String(buf, 0, len, ISO_8859_1);
} |
Convert a byte array to a Pascal string. The first byte is the byte count,
followed by that many active characters.
@param bb
@return
@throws IOException
| Utils::readPascalString | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static String getString(final ByteBuffer buffer, final int offset, final int length, final Charset encoding)
{
final byte[] b = new byte[length];
buffer.position(buffer.position() + offset);
buffer.get(b);
return new String(b, 0, length, encoding);
} |
Reads bytes from a ByteBuffer as if they were encoded in the specified CharSet.
@param buffer
@param offset offset from current position
@param length size of data to process
@param encoding
@return
| Utils::getString | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static String getString(final ByteBuffer buffer, final Charset encoding)
{
final byte[] b = new byte[buffer.remaining()];
buffer.get(b);
return new String(b, encoding);
} |
Reads bytes from a ByteBuffer as if they were encoded in the specified CharSet.
@param buffer
@param encoding
@return
| Utils::getString | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static long readUint32(final DataInput di) throws IOException
{
final byte[] buf8 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
di.readFully(buf8, 4, 4);
return ByteBuffer.wrap(buf8).getLong();
} |
Read a 32-bit big-endian unsigned integer using a DataInput.
Reads 4 bytes but returns as long
| Utils::readUint32 | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static int readUint16(final DataInput di) throws IOException
{
final byte[] buf = {0x00, 0x00, 0x00, 0x00};
di.readFully(buf, 2, 2);
return ByteBuffer.wrap(buf).getInt();
} |
Read a 16-bit big-endian unsigned integer.
Reads 2 bytes but returns as an integer
| Utils::readUint16 | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static String readString(final DataInput di, final int charsToRead) throws IOException
{
final byte[] buf = new byte[charsToRead];
di.readFully(buf);
return new String(buf, US_ASCII);
} |
Read a string of a specified number of ASCII bytes.
| Utils::readString | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static String getBaseFilenameForTempFile(final File file)
{
final String filename = getMinBaseFilenameAllowedForTempFile(file);
if(filename.length()<= MAX_BASE_TEMP_FILENAME_LENGTH)
{
return filename;
}
return filename.substring(0, MAX_BASE_TEMP_FILENAME_LENGTH);
} |
Get a base for temp file, this should be long enough so that it easy to work out later what file the temp file
was created for if it is left lying round, but not ridiculously long as this can cause problems with max filename
limits and is not very useful.
@param file
@return
| Utils::getBaseFilenameForTempFile | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static String getMinBaseFilenameAllowedForTempFile(final File file)
{
final String s = AudioFile.getBaseFilename(file);
if (s.length() >= 3)
{
return s;
}
if (s.length() == 1)
{
return s + "000";
}
else if (s.length() == 1)
{
return s + "00";
}
else if (s.length() == 2)
{
return s + "0";
}
return s;
} |
@param file
@return filename with audioformat separator stripped of, lengthened to ensure not too small for valid tempfile
creation.
| Utils::getMinBaseFilenameAllowedForTempFile | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static boolean rename(final File fromFile, final File toFile)
{
logger.log(Level.CONFIG,"Renaming From:"+fromFile.getAbsolutePath() + " to "+toFile.getAbsolutePath());
if(toFile.exists())
{
logger.log(Level.SEVERE,"Destination File:"+toFile + " already exists");
return false;
}
//Rename File, could fail because being used or because trying to rename over filesystems
final boolean result = fromFile.renameTo(toFile);
if (!result)
{
// Might be trying to rename over filesystem, so try copy and delete instead
if (copy(fromFile, toFile))
{
//If copy works but deletion of original file fails then it is because the file is being used
//so we need to delete the file we have just created
boolean deleteResult=fromFile.delete();
if(!deleteResult)
{
logger.log(Level.SEVERE,"Unable to delete File:"+fromFile);
toFile.delete();
return false;
}
return true;
}
else
{
return false;
}
}
return true;
} |
Rename file, and if normal rename fails, try copy and delete instead.
@param fromFile
@param toFile
@return
| Utils::rename | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static boolean copy(final File fromFile, final File toFile)
{
try
{
copyThrowsOnException(fromFile, toFile);
return true;
}
catch (IOException e)
{
e.printStackTrace();
return false;
}
} |
Copy a File.
ToDo refactor AbstractTestCase to use this method as it contains an exact duplicate.
@param fromFile The existing File
@param toFile The new File
@return <code>true</code> if and only if the renaming succeeded;
<code>false</code> otherwise
| Utils::copy | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static String readFourBytesAsChars(final ByteBuffer bytes)
{
byte[] b = new byte[4];
bytes.get(b);
return new String(b, ISO_8859_1);
} |
Reads 4 bytes and concatenates them into a String.
This pattern is used for ID's of various kinds.
@param bytes
@return
@throws IOException
| Utils::readFourBytesAsChars | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static String readThreeBytesAsChars(final ByteBuffer bytes)
{
byte[] b = new byte[3];
bytes.get(b);
return new String(b, ISO_8859_1);
} |
Reads 3 bytes and concatenates them into a String.
This pattern is used for ID's of various kinds.
@param bytes
@return
| Utils::readThreeBytesAsChars | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static long u(final int n)
{
return n & 0xffffffffL;
} |
Used to convert (signed integer) to an long as if signed integer was unsigned hence allowing
it to represent full range of integral values.
@param n
@return
| Utils::u | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static int u(final short n)
{
return n & 0xffff;
} |
Used to convert (signed short) to an integer as if signed short was unsigned hence allowing
it to represent values 0 -> 65536 rather than -32786 -> 32786
@param n
@return
| Utils::u | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static int u(final byte n)
{
return n & 0xff;
} |
Used to convert (signed byte) to an integer as if signed byte was unsigned hence allowing
it to represent values 0 -> 255 rather than -128 -> 127.
@param n
@return
| Utils::u | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static ByteBuffer readFileDataIntoBufferLE(FileChannel fc, final int size) throws IOException
{
final ByteBuffer tagBuffer = ByteBuffer.allocateDirect(size);
fc.read(tagBuffer);
tagBuffer.position(0);
tagBuffer.order(ByteOrder.LITTLE_ENDIAN);
return tagBuffer;
} |
@param fc
@param size
@return
@throws IOException
| Utils::readFileDataIntoBufferLE | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static ByteBuffer readFileDataIntoBufferBE(FileChannel fc, final int size) throws IOException
{
final ByteBuffer tagBuffer = ByteBuffer.allocateDirect(size);
fc.read(tagBuffer);
tagBuffer.position(0);
tagBuffer.order(ByteOrder.BIG_ENDIAN);
return tagBuffer;
} |
@param fc
@param size
@return
@throws IOException
| Utils::readFileDataIntoBufferBE | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static void copyThrowsOnException(final File source, final File destination) throws IOException {
// Must be done in a loop as there's no guarantee that a request smaller than request count will complete in one invocation.
// Setting the transfer size more than about 1MB is pretty pointless because there is no asymptotic benefit. What you're trying
// to achieve with larger transfer sizes is fewer context switches, and every time you double the transfer size you halve the
// context switch cost. Pretty soon it vanishes into the noise.
try (FileInputStream inStream = new FileInputStream(source); FileOutputStream outStream = new FileOutputStream(destination))
{
final FileChannel inChannel = inStream.getChannel();
final FileChannel outChannel = outStream.getChannel();
final long size = inChannel.size();
long position = 0;
while (position < size)
{
position += inChannel.transferTo(position, 1024L * 1024L, outChannel);
}
} //Closeables closed exiting try block in all circumstances
} |
Copy src file to dst file. FileChannels are used to maximize performance.
@param source source File
@param destination destination File which will be created or truncated, before copying, if it already exists
@throws IOException if any error occurS
| Utils::copyThrowsOnException | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public static boolean isOddLength(long length)
{
return (length & 1) != 0;
} |
@param length
@return true if length is an odd number
| Utils::isOddLength | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/Utils.java | Apache-2.0 |
public void fileModified(AudioFile original, File temporary) throws ModifyVetoException
{
// Nothing to do
} |
(overridden)
@see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileModified(org.jaudiotagger.audio.AudioFile,
File)
| AudioFileModificationAdapter::fileModified | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AudioFileModificationAdapter.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AudioFileModificationAdapter.java | Apache-2.0 |
public void fileOperationFinished(File result)
{
// Nothing to do
} |
(overridden)
@see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileOperationFinished(File)
| AudioFileModificationAdapter::fileOperationFinished | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AudioFileModificationAdapter.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AudioFileModificationAdapter.java | Apache-2.0 |
public void fileWillBeModified(AudioFile file, boolean delete) throws ModifyVetoException
{
// Nothing to do
} |
(overridden)
@see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileWillBeModified(org.jaudiotagger.audio.AudioFile,
boolean)
| AudioFileModificationAdapter::fileWillBeModified | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AudioFileModificationAdapter.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AudioFileModificationAdapter.java | Apache-2.0 |
public void vetoThrown(AudioFileModificationListener cause, AudioFile original, ModifyVetoException veto)
{
// Nothing to do
} |
(overridden)
@see org.jaudiotagger.audio.generic.AudioFileModificationListener#vetoThrown(org.jaudiotagger.audio.generic.AudioFileModificationListener,
org.jaudiotagger.audio.AudioFile,
org.jaudiotagger.audio.exceptions.ModifyVetoException)
| AudioFileModificationAdapter::vetoThrown | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AudioFileModificationAdapter.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AudioFileModificationAdapter.java | Apache-2.0 |
public ByteBuffer convert(Tag tag) throws UnsupportedEncodingException
{
return convert(tag, 0);
} |
Convert tagdata to rawdata ready for writing to file with no additional padding
@param tag
@return
@throws UnsupportedEncodingException
| AbstractTagCreator::convert | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AbstractTagCreator.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AbstractTagCreator.java | Apache-2.0 |
public AudioFile read(File f) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
{
if(logger.isLoggable(Level.CONFIG))
{
logger.config(ErrorMessage.GENERAL_READ.getMsg(f.getAbsolutePath()));
}
if (!Files.isReadable(f.toPath()))
{
logger.warning(Permissions.displayPermissions(f.toPath()));
throw new NoReadPermissionsException(ErrorMessage.GENERAL_READ_FAILED_DO_NOT_HAVE_PERMISSION_TO_READ_FILE.getMsg(f.toPath()));
}
if (f.length() <= MINIMUM_SIZE_FOR_VALID_AUDIO_FILE)
{
throw new CannotReadException(ErrorMessage.GENERAL_READ_FAILED_FILE_TOO_SMALL.getMsg(f.getAbsolutePath()));
}
RandomAccessFile raf = null;
try
{
raf = new RandomAccessFile(f, "r");
raf.seek(0);
GenericAudioHeader info = getEncodingInfo(raf);
raf.seek(0);
Tag tag = getTag(raf);
return new AudioFile(f, info, tag);
}
catch (CannotReadException cre)
{
throw cre;
}
catch (Exception e)
{
logger.log(Level.SEVERE, ErrorMessage.GENERAL_READ.getMsg(f.getAbsolutePath()),e);
throw new CannotReadException(f.getAbsolutePath()+":" + e.getMessage(), e);
}
finally
{
try
{
if (raf != null)
{
raf.close();
}
}
catch (Exception ex)
{
logger.log(Level.WARNING, ErrorMessage.GENERAL_READ_FAILED_UNABLE_TO_CLOSE_RANDOM_ACCESS_FILE.getMsg(f.getAbsolutePath()));
}
}
} | /*
Entagged Audio Tag library
Copyright (c) 2003-2005 Raphaël Slinckx <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package org.jaudiotagger.audio.generic;
import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.NoReadPermissionsException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.logging.ErrorMessage;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.tag.TagException;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.util.logging.Level;
import java.util.logging.Logger;
/*
This abstract class is the skeleton for tag readers. It handles the creation/closing of
the randomaccessfile objects and then call the subclass method getEncodingInfo and getTag.
These two method have to be implemented in the subclass.
@author Raphael Slinckx
@version $Id$
@since v0.02
public abstract class AudioFileReader
{
// Logger Object
public static Logger logger = Logger.getLogger("org.jaudiotagger.audio.generic");
protected static final int MINIMUM_SIZE_FOR_VALID_AUDIO_FILE = 100;
/*
Returns the encoding info object associated wih the current File.
The subclass can assume the RAF pointer is at the first byte of the file.
The RandomAccessFile must be kept open after this function, but can point
at any offset in the file.
@param raf The RandomAccessFile associtaed with the current file
@exception IOException is thrown when the RandomAccessFile operations throw it (you should never throw them manually)
@exception CannotReadException when an error occured during the parsing of the encoding infos
protected abstract GenericAudioHeader getEncodingInfo(RandomAccessFile raf) throws CannotReadException, IOException;
/*
Same as above but returns the Tag contained in the file, or a new one.
@param raf The RandomAccessFile associted with the current file
@exception IOException is thrown when the RandomAccessFile operations throw it (you should never throw them manually)
@exception CannotReadException when an error occured during the parsing of the tag
protected abstract Tag getTag(RandomAccessFile raf) throws CannotReadException, IOException;
/*
Reads the given file, and return an AudioFile object containing the Tag
and the encoding infos present in the file. If the file has no tag, an
empty one is returned. If the encodinginfo is not valid , an exception is thrown.
@param f The file to read
@exception CannotReadException If anything went bad during the read of this file
| AudioFileReader::read | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AudioFileReader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AudioFileReader.java | Apache-2.0 |
public String getItem(String id,int index)
{
List<TagField> l = getFields(id);
return (l.size()>index) ? l.get(index).toString() : "";
} |
@param id
@param index
@return
| AbstractTag::getItem | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | Apache-2.0 |
public boolean setEncoding(final Charset enc)
{
if (!isAllowedEncoding(enc))
{
return false;
}
Iterator it = getFields();
while (it.hasNext())
{
TagField field = (TagField) it.next();
if (field instanceof TagTextField)
{
((TagTextField) field).setEncoding(enc);
}
}
return true;
} |
Set or add encoding
@see org.jaudiotagger.tag.Tag#setEncoding(java.lang.String)
| AbstractTag::setEncoding | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | Apache-2.0 |
public String toString()
{
StringBuffer out = new StringBuffer();
out.append("Tag content:\n");
Iterator it = getFields();
while (it.hasNext())
{
TagField field = (TagField) it.next();
out.append("\t");
out.append(field.getId());
out.append(":");
out.append(field);
out.append("\n");
}
return out.toString().substring(0, out.length() - 1);
} |
(overridden)
@see java.lang.Object#toString()
| AbstractTag::toString | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | Apache-2.0 |
public void deleteField(String key)
{
fields.remove(key);
} |
Delete all occurrences of field with this id.
@param key
| AbstractTag::deleteField | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | Apache-2.0 |
public void setField(Artwork artwork) throws FieldDataInvalidException
{
this.setField(createField(artwork));
} |
Create field and then set within tag itself
@param artwork
@throws FieldDataInvalidException
| AbstractTag::setField | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | Apache-2.0 |
public void addField(Artwork artwork) throws FieldDataInvalidException
{
this.addField(createField(artwork));
} |
Create field and then add within tag itself
@param artwork
@throws FieldDataInvalidException
| AbstractTag::addField | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | Apache-2.0 |
public void deleteArtworkField() throws KeyNotFoundException
{
this.deleteField(FieldKey.COVER_ART);
} |
Delete all instance of artwork Field
@throws KeyNotFoundException
| AbstractTag::deleteArtworkField | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/AbstractTag.java | Apache-2.0 |
public GenericAudioHeader()
{
} |
Creates an instance with emtpy values.<br>
| GenericAudioHeader::GenericAudioHeader | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public long getBitRateAsNumber()
{
return bitRate;
} |
This method returns the bitRate of the represented audio clip in
"Kbps".<br>
@return The bitRate in Kbps.
| GenericAudioHeader::getBitRateAsNumber | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public int getChannelNumber()
{
return noOfChannels;
} |
This method returns the number of audio channels the clip contains.<br>
(The stereo, mono thing).
@return The number of channels. (2 for stereo, 1 for mono)
| GenericAudioHeader::getChannelNumber | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public String getChannels()
{
return String.valueOf(getChannelNumber());
} |
@return
| GenericAudioHeader::getChannels | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public String getEncodingType()
{
return encodingType;
} |
Returns the encoding type.
@return The encoding type
| GenericAudioHeader::getEncodingType | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public String getFormat()
{
return encodingType;
} |
Returns the format, same as encoding type
@return The encoding type
| GenericAudioHeader::getFormat | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public int getTrackLength()
{
return (int) Math.round(getPreciseTrackLength());
} |
This method returns the duration of the represented audio clip in
seconds.<br>
@return The duration to the nearest seconds.
@see #getPreciseTrackLength()
| GenericAudioHeader::getTrackLength | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public double getPreciseTrackLength()
{
return trackLength;
} |
This method returns the duration of the represented audio clip in seconds
(single-precision).<br>
@return The duration in seconds.
@see #getTrackLength()
| GenericAudioHeader::getPreciseTrackLength | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public String getSampleRate()
{
return String.valueOf(samplingRate);
} |
This method returns the sample rate, the audio clip was encoded with.<br>
@return Sample rate of the audio clip in "Hz".
| GenericAudioHeader::getSampleRate | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public int getBitsPerSample()
{
//TODO remove bandaid
if(bitsPerSample==null)
{
return -1;
}
return bitsPerSample;
} |
@return The number of bits per sample
| GenericAudioHeader::getBitsPerSample | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public boolean isVariableBitRate()
{
//TODO remove this bandaid
if(isVbr==null)
{
return false;
}
return isVbr;
} |
This method returns <code>true</code>, if the audio file is encoded
with "Variable Bitrate".<br>
@return <code>true</code> if audio clip is encoded with VBR.
| GenericAudioHeader::isVariableBitRate | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public boolean isLossless()
{
//TODO remove this bandaid
if(isLossless==null)
{
return false;
}
return isLossless;
} |
This method returns <code>true</code>, if the audio file is encoded
with "Lossless".<br>
@return <code>true</code> if audio clip is encoded with VBR.
| GenericAudioHeader::isLossless | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public void setBitRate(int bitRate)
{
this.bitRate = bitRate;
} |
This Method sets the bitRate in "Kbps".<br>
@param bitRate bitRate in kbps.
| GenericAudioHeader::setBitRate | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public void setChannelNumber(int channelMode)
{
this.noOfChannels = channelMode;
} |
Sets the number of channels.
@param channelMode number of channels (2 for stereo, 1 for mono).
| GenericAudioHeader::setChannelNumber | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public void setEncodingType(String encodingType)
{
this.encodingType=encodingType;
} |
Sets the type of the encoding.<br>
This is a bit format specific.<br>
eg:Layer I/II/III
@param encodingType Encoding type.
| GenericAudioHeader::setEncodingType | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public void setPreciseLength(double length)
{
this.trackLength = length;
} |
This method sets the audio duration of the represented clip.<br>
@param length The duration of the audio in seconds (single-precision).
| GenericAudioHeader::setPreciseLength | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public void setSamplingRate(int samplingRate)
{
this.samplingRate = samplingRate;
} |
Sets the Sampling rate in "Hz"<br>
@param samplingRate Sample rate.
| GenericAudioHeader::setSamplingRate | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public void setBitsPerSample(int bitsPerSample)
{
this.bitsPerSample = bitsPerSample;
} |
Sets the Sampling rate in "Hz"<br>
@param samplingRate Sample rate.
public void setSamplingRate(int samplingRate)
{
this.samplingRate = samplingRate;
}
/*
Sets the Bits per Sample <br>
@params bitsPerSample Bits Per Sample
| GenericAudioHeader::setBitsPerSample | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public void setByteRate(int byteRate)
{
this.byteRate = byteRate;
} |
Sets the Sampling rate in "Hz"<br>
@param samplingRate Sample rate.
public void setSamplingRate(int samplingRate)
{
this.samplingRate = samplingRate;
}
/*
Sets the Bits per Sample <br>
@params bitsPerSample Bits Per Sample
public void setBitsPerSample(int bitsPerSample)
{
this.bitsPerSample = bitsPerSample;
}
/*
Sets the ByteRate (per second)
@params ByteRate
| GenericAudioHeader::setByteRate | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public void setVariableBitRate(boolean isVbr)
{
this.isVbr=isVbr;
} |
Sets the VBR flag for the represented audio clip.<br>
@param isVbr <code>true</code> if VBR.
| GenericAudioHeader::setVariableBitRate | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public void setLossless(boolean isLossless)
{
this.isLossless = isLossless;
} |
Sets the Lossless flag for the represented audio clip.<br>
@param isLossless <code>true</code> if Lossless.
| GenericAudioHeader::setLossless | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public String toString()
{
StringBuilder out = new StringBuilder();
out.append("Audio Header content:\n");
if(audioDataLength!=null)
{
out.append("\taudioDataLength:"+audioDataLength+"\n");
}
if(audioDataStartPosition!=null)
{
out.append("\taudioDataStartPosition:"+audioDataStartPosition+"\n");
}
if(audioDataEndPosition!=null)
{
out.append("\taudioDataEndPosition:"+audioDataEndPosition+"\n");
}
if(byteRate!=null)
{
out.append("\tbyteRate:"+byteRate+"\n");
}
if(bitRate!=null)
{
out.append("\tbitRate:"+bitRate+"\n");
}
if(samplingRate!=null)
{
out.append("\tsamplingRate:"+samplingRate+"\n");
}
if(bitsPerSample!=null)
{
out.append("\tbitsPerSample:"+bitsPerSample+"\n");
}
if(noOfSamples!=null)
{
out.append("\ttotalNoSamples:"+noOfSamples+"\n");
}
if(noOfChannels!=null)
{
out.append("\tnumberOfChannels:"+noOfChannels+"\n");
}
if(encodingType!=null)
{
out.append("\tencodingType:"+encodingType+"\n");
}
if(isVbr!=null)
{
out.append("\tisVbr:"+isVbr+"\n");
}
if(isLossless!=null)
{
out.append("\tisLossless:"+isLossless+"\n");
}
if(trackLength!=null)
{
out.append("\ttrackDuration:"+trackLength+"\n");
}
return out.toString();
} |
Pretty prints this encoding info
@see java.lang.Object#toString()
| GenericAudioHeader::toString | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericAudioHeader.java | Apache-2.0 |
public GenericTagTextField(final String fieldId, final String initialContent)
{
this.id = fieldId;
this.content = initialContent;
} |
Creates an instance.
@param fieldId The identifier.
@param initialContent The string.
| GenericTagTextField::GenericTagTextField | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/audio/generic/GenericTag.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/audio/generic/GenericTag.java | Apache-2.0 |
public static String xmlOpen(String xmlName)
{
return xmlOpenStart + xmlName + xmlOpenEnd;
} |
Return xml open tag round a string e.g <tag>
@param xmlName
@return
| XMLTagDisplayFormatter::xmlOpen | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/logging/XMLTagDisplayFormatter.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/logging/XMLTagDisplayFormatter.java | Apache-2.0 |
public static String xmlCData(String xmlData)
{
char tempChar;
StringBuffer replacedString = new StringBuffer();
for (int i = 0; i < xmlData.length(); i++)
{
tempChar = xmlData.charAt(i);
if ((Character.isLetterOrDigit(tempChar)) || (Character.isSpaceChar(tempChar)))
{
replacedString.append(tempChar);
}
else
{
replacedString.append("&#x").append(Integer.toString(Character.codePointAt(xmlData,i),16));
}
}
return xmlCDataTagOpen + replacedString + xmlCDataTagClose;
} |
Return CDATA tag around xml data e.g <![CDATA[xmlData]]>
We also need to deal with special chars
@param xmlData
@return
| XMLTagDisplayFormatter::xmlCData | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/logging/XMLTagDisplayFormatter.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/logging/XMLTagDisplayFormatter.java | Apache-2.0 |
public static String xmlClose(String xmlName)
{
return xmlCloseStart + xmlName + xmlCloseEnd;
} |
Return xml close tag around a string e.g </tag>
@param xmlName
@return
| XMLTagDisplayFormatter::xmlClose | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/logging/XMLTagDisplayFormatter.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/logging/XMLTagDisplayFormatter.java | Apache-2.0 |
public static String replaceXMLCharacters(String xmlData)
{
StringBuffer sb = new StringBuffer();
StringCharacterIterator sCI = new StringCharacterIterator(xmlData);
for (char c = sCI.first(); c != CharacterIterator.DONE; c = sCI.next())
{
switch (c)
{
case'&':
sb.append("&");
break;
case'<':
sb.append("<");
break;
case'>':
sb.append(">");
break;
case'"':
sb.append(""");
break;
case'\'':
sb.append("'");
break;
default:
sb.append(c);
}
}
return sb.toString();
} |
Replace any special xml characters with the appropiate escape sequences
required to be done for the actual element names
@param xmlData
@return
| XMLTagDisplayFormatter::replaceXMLCharacters | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/logging/XMLTagDisplayFormatter.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/logging/XMLTagDisplayFormatter.java | Apache-2.0 |
public static String asHex(long value)
{
String val = Long.toHexString(value);
if(val.length()==1)
{
return "0x0" + val;
}
return "0x" + val;
} |
Display as hex
@param value
@return
| Hex::asHex | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/logging/Hex.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/logging/Hex.java | Apache-2.0 |
public static String asHex(byte value)
{
return "0x" + Integer.toHexString(value);
} |
Display as hex
@param value
@return
| Hex::asHex | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/logging/Hex.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/logging/Hex.java | Apache-2.0 |
public static String asDecAndHex(long value)
{
return value + " (" + Hex.asHex(value)+ ")";
} |
Display as integral and hex calue in brackets
@param value
@return
| Hex::asDecAndHex | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/logging/Hex.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/logging/Hex.java | Apache-2.0 |
public static String displayAsBinary(byte buffer)
{
//Convert buffer to hex representation
String hexValue = Integer.toHexString(buffer);
String char1 = "";
String char2 = "";
try
{
if (hexValue.length() == 8)
{
char1 = hexValue.substring(6, 7);
char2 = hexValue.substring(7, 8);
}
else if (hexValue.length() == 2)
{
char1 = hexValue.substring(0, 1);
char2 = hexValue.substring(1, 2);
}
else if (hexValue.length() == 1)
{
char1 = "0";
char2 = hexValue.substring(0, 1);
}
}
catch (StringIndexOutOfBoundsException se)
{
return "";
}
return hexBinaryMap.get(char1) + hexBinaryMap.get(char2);
} |
Use to display headers as their binary representation
@param buffer
@return
| AbstractTagDisplayFormatter::displayAsBinary | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/logging/AbstractTagDisplayFormatter.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/logging/AbstractTagDisplayFormatter.java | Apache-2.0 |
private static ReleaseStrategy decideReleaseStrategy()
{
final String javaVendor = System.getProperty("java.vendor");
if (javaVendor.equals("Sun Microsystems Inc.") || javaVendor.equals("Oracle Corporation"))
{
return OpenJdkReleaseStrategy.INSTANCE;
}
else if (javaVendor.equals("The Android Project"))
{
return AndroidReleaseStrategy.INSTANCE;
}
else
{
LOGGER.log(Level.WARNING, "Won't be able to release direct buffers as this JVM is unsupported: " + javaVendor);
return UnsupportedJvmReleaseStrategy.INSTANCE;
}
} |
Decide which ReleaseStrategy to use, depending on the JVM
@return
| UnsupportedJvmReleaseStrategy::decideReleaseStrategy | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/DirectByteBufferUtils.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/DirectByteBufferUtils.java | Apache-2.0 |
static public boolean areEqual(Object aThis, Object aThat)
{
//System.out.println("Object");
return Objects.equals(aThis, aThat);
} |
Possibly-null object field.
Includes type-safe enumerations and collections, but does not include
arrays. See class comment.
| EqualsUtil::areEqual | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/EqualsUtil.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/EqualsUtil.java | Apache-2.0 |
public TreeModelEvent(Object source, Object[] path, int[] childIndices,
Object[] children)
{
this(source, new TreePath(path), childIndices, children);
} |
Used to create an event when nodes have been changed, inserted, or
removed, identifying the path to the parent of the modified items as
an array of Objects. All of the modified objects are siblings which are
direct descendents (not grandchildren) of the specified parent.
The positions at which the inserts, deletes, or changes occurred are
specified by an array of <code>int</code>. The indexes in that array
must be in order, from lowest to highest.
<p>
For changes, the indexes in the model correspond exactly to the indexes
of items currently displayed in the UI. As a result, it is not really
critical if the indexes are not in their exact order. But after multiple
inserts or deletes, the items currently in the UI no longer correspond
to the items in the model. It is therefore critical to specify the
indexes properly for inserts and deletes.
<p>
For inserts, the indexes represent the <i>final</i> state of the tree,
after the inserts have occurred. Since the indexes must be specified in
order, the most natural processing methodology is to do the inserts
starting at the lowest index and working towards the highest. Accumulate
a Vector of <code>Integer</code> objects that specify the
insert-locations as you go, then convert the Vector to an
array of <code>int</code> to create the event. When the postition-index
equals zero, the node is inserted at the beginning of the list. When the
position index equals the size of the list, the node is "inserted" at
(appended to) the end of the list.
<p>
For deletes, the indexes represent the <i>initial</i> state of the tree,
before the deletes have occurred. Since the indexes must be specified in
order, the most natural processing methodology is to use a delete-counter.
Start by initializing the counter to zero and start work through the
list from lowest to higest. Every time you do a delete, add the current
value of the delete-counter to the index-position where the delete occurred,
and append the result to a Vector of delete-locations, using
<code>addElement()</code>. Then increment the delete-counter. The index
positions stored in the Vector therefore reflect the effects of all previous
deletes, so they represent each object's position in the initial tree.
(You could also start at the highest index and working back towards the
lowest, accumulating a Vector of delete-locations as you go using the
<code>insertElementAt(Integer, 0)</code>.) However you produce the Vector
of initial-positions, you then need to convert the Vector of <code>Integer</code>
objects to an array of <code>int</code> to create the event.
<p>
<b>Notes:</b><ul>
<li>Like the <code>insertNodeInto</code> method in the
<code>DefaultTreeModel</code> class, <code>insertElementAt</code>
appends to the <code>Vector</code> when the index matches the size
of the vector. So you can use <code>insertElementAt(Integer, 0)</code>
even when the vector is empty.
<ul>To create a node changed event for the root node, specify the parent
and the child indices as <code>null</code>.
</ul>
@param source the Object responsible for generating the event (typically
the creator of the event object passes <code>this</code>
for its value)
@param path an array of Object identifying the path to the
parent of the modified item(s), where the first element
of the array is the Object stored at the root node and
the last element is the Object stored at the parent node
@param childIndices an array of <code>int</code> that specifies the
index values of the removed items. The indices must be
in sorted order, from lowest to highest
@param children an array of Object containing the inserted, removed, or
changed objects
@see TreePath
| TreeModelEvent::TreeModelEvent | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | Apache-2.0 |
public TreeModelEvent(Object source, TreePath path, int[] childIndices,
Object[] children)
{
super(source);
this.path = path;
this.childIndices = childIndices;
this.children = children;
} |
Used to create an event when nodes have been changed, inserted, or
removed, identifying the path to the parent of the modified items as
a TreePath object. For more information on how to specify the indexes
and objects, see
<code>TreeModelEvent(Object,Object[],int[],Object[])</code>.
@param source the Object responsible for generating the event (typically
the creator of the event object passes <code>this</code>
for its value)
@param path a TreePath object that identifies the path to the
parent of the modified item(s)
@param childIndices an array of <code>int</code> that specifies the
index values of the modified items
@param children an array of Object containing the inserted, removed, or
changed objects
@see #TreeModelEvent(Object,Object[],int[],Object[])
| TreeModelEvent::TreeModelEvent | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | Apache-2.0 |
public TreeModelEvent(Object source, Object[] path)
{
this(source, new TreePath(path));
} |
Used to create an event when the node structure has changed in some way,
identifying the path to the root of a modified subtree as an array of
Objects. A structure change event might involve nodes swapping position,
for example, or it might encapsulate multiple inserts and deletes in the
subtree stemming from the node, where the changes may have taken place at
different levels of the subtree.
<blockquote>
<b>Note:</b><br>
JTree collapses all nodes under the specified node, so that only its
immediate children are visible.
</blockquote>
@param source the Object responsible for generating the event (typically
the creator of the event object passes <code>this</code>
for its value)
@param path an array of Object identifying the path to the root of the
modified subtree, where the first element of the array is
the object stored at the root node and the last element
is the object stored at the changed node
@see TreePath
| TreeModelEvent::TreeModelEvent | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | Apache-2.0 |
public TreeModelEvent(Object source, TreePath path)
{
super(source);
this.path = path;
this.childIndices = new int[0];
} |
Used to create an event when the node structure has changed in some way,
identifying the path to the root of the modified subtree as a TreePath
object. For more information on this event specification, see
<code>TreeModelEvent(Object,Object[])</code>.
@param source the Object responsible for generating the event (typically
the creator of the event object passes <code>this</code>
for its value)
@param path a TreePath object that identifies the path to the
change. In the DefaultTreeModel,
this object contains an array of user-data objects,
but a subclass of TreePath could use some totally
different mechanism -- for example, a node ID number
@see #TreeModelEvent(Object,Object[])
| TreeModelEvent::TreeModelEvent | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | Apache-2.0 |
public TreePath getTreePath() { return path; } |
For all events, except treeStructureChanged,
returns the parent of the changed nodes.
For treeStructureChanged events, returns the ancestor of the
structure that has changed. This and
<code>getChildIndices</code> are used to get a list of the effected
nodes.
<p>
The one exception to this is a treeNodesChanged event that is to
identify the root, in which case this will return the root
and <code>getChildIndices</code> will return null.
@return the TreePath used in identifying the changed nodes.
@see TreePath#getLastPathComponent
| TreeModelEvent::getTreePath | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | Apache-2.0 |
public Object[] getPath() {
if(path != null)
return path.getPath();
return null;
} |
Convenience method to get the array of objects from the TreePath
instance that this event wraps.
@return an array of Objects, where the first Object is the one
stored at the root and the last object is the one
stored at the node identified by the path
| TreeModelEvent::getPath | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | Apache-2.0 |
public Object[] getChildren() {
if(children != null) {
int cCount = children.length;
Object[] retChildren = new Object[cCount];
System.arraycopy(children, 0, retChildren, 0, cCount);
return retChildren;
}
return null;
} |
Returns the objects that are children of the node identified by
<code>getPath</code> at the locations specified by
<code>getChildIndices</code>. If this is a removal event the
returned objects are no longer children of the parent node.
@return an array of Object containing the children specified by
the event
@see #getPath
@see #getChildIndices
| TreeModelEvent::getChildren | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | Apache-2.0 |
public int[] getChildIndices() {
if(childIndices != null) {
int cCount = childIndices.length;
int[] retArray = new int[cCount];
System.arraycopy(childIndices, 0, retArray, 0, cCount);
return retArray;
}
return null;
} |
Returns the values of the child indexes. If this is a removal event
the indexes point to locations in the initial list where items
were removed. If it is an insert, the indices point to locations
in the final list where the items were added. For node changes,
the indices point to the locations of the modified nodes.
@return an array of <code>int</code> containing index locations for
the children specified by the event
| TreeModelEvent::getChildIndices | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | Apache-2.0 |
public String toString() {
StringBuffer retBuffer = new StringBuffer();
retBuffer.append(getClass().getName() + " " +
hashCode());
if(path != null)
retBuffer.append(" path " + path);
if(childIndices != null) {
retBuffer.append(" indices [ ");
for(int counter = 0; counter < childIndices.length; counter++)
retBuffer.append(childIndices[counter] + " ");
retBuffer.append("]");
}
if(children != null) {
retBuffer.append(" children [ ");
for(int counter = 0; counter < children.length; counter++)
retBuffer.append(children[counter] + " ");
retBuffer.append("]");
}
return retBuffer.toString();
} |
Returns a string that displays and identifies this object's
properties.
@return a String representation of this object
| TreeModelEvent::toString | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreeModelEvent.java | Apache-2.0 |
public DefaultMutableTreeNode() {
this(null);
} |
Creates a tree node that has no parent and no children, but which
allows children.
| DefaultMutableTreeNode::DefaultMutableTreeNode | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public DefaultMutableTreeNode(Object userObject) {
this(userObject, true);
} |
Creates a tree node with no parent, no children, but which allows
children, and initializes it with the specified user object.
@param userObject an Object provided by the user that constitutes
the node's data
| DefaultMutableTreeNode::DefaultMutableTreeNode | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public DefaultMutableTreeNode(Object userObject, boolean allowsChildren) {
super();
parent = null;
this.allowsChildren = allowsChildren;
this.userObject = userObject;
} |
Creates a tree node with no parent, no children, initialized with
the specified user object, and that allows children only if
specified.
@param userObject an Object provided by the user that constitutes
the node's data
@param allowsChildren if true, the node is allowed to have child
nodes -- otherwise, it is always a leaf node
| DefaultMutableTreeNode::DefaultMutableTreeNode | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public void insert(MutableTreeNode newChild, int childIndex) {
if (!allowsChildren) {
throw new IllegalStateException("node does not allow children");
} else if (newChild == null) {
throw new IllegalArgumentException("new child is null");
} else if (isNodeAncestor(newChild)) {
throw new IllegalArgumentException("new child is an ancestor");
}
MutableTreeNode oldParent = (MutableTreeNode)newChild.getParent();
if (oldParent != null) {
oldParent.remove(newChild);
}
newChild.setParent(this);
if (children == null) {
children = new Vector();
}
children.insertElementAt(newChild, childIndex);
} |
Removes <code>newChild</code> from its present parent (if it has a
parent), sets the child's parent to this node, and then adds the child
to this node's child array at index <code>childIndex</code>.
<code>newChild</code> must not be null and must not be an ancestor of
this node.
@param newChild the MutableTreeNode to insert under this node
@param childIndex the index in this node's child array
where this node is to be inserted
@exception ArrayIndexOutOfBoundsException if
<code>childIndex</code> is out of bounds
@exception IllegalArgumentException if
<code>newChild</code> is null or is an
ancestor of this node
@exception IllegalStateException if this node does not allow
children
@see #isNodeDescendant
| DefaultMutableTreeNode::insert | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public void remove(int childIndex) {
MutableTreeNode child = (MutableTreeNode)getChildAt(childIndex);
children.removeElementAt(childIndex);
child.setParent(null);
} |
Removes the child at the specified index from this node's children
and sets that node's parent to null. The child node to remove
must be a <code>MutableTreeNode</code>.
@param childIndex the index in this node's child array
of the child to remove
@exception ArrayIndexOutOfBoundsException if
<code>childIndex</code> is out of bounds
| DefaultMutableTreeNode::remove | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public void setParent(MutableTreeNode newParent) {
parent = newParent;
} |
Sets this node's parent to <code>newParent</code> but does not
change the parent's child array. This method is called from
<code>insert()</code> and <code>remove()</code> to
reassign a child's parent, it should not be messaged from anywhere
else.
@param newParent this node's new parent
| DefaultMutableTreeNode::setParent | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public TreeNode getParent() {
return parent;
} |
Returns this node's parent or null if this node has no parent.
@return this node's parent TreeNode, or null if this node has no parent
| DefaultMutableTreeNode::getParent | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public TreeNode getChildAt(int index) {
if (children == null) {
throw new ArrayIndexOutOfBoundsException("node has no children");
}
return (TreeNode)children.elementAt(index);
} |
Returns the child at the specified index in this node's child array.
@param index an index into this node's child array
@exception ArrayIndexOutOfBoundsException if <code>index</code>
is out of bounds
@return the TreeNode in this node's child array at the specified index
| DefaultMutableTreeNode::getChildAt | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public int getChildCount() {
if (children == null) {
return 0;
} else {
return children.size();
}
} |
Returns the number of children of this node.
@return an int giving the number of children of this node
| DefaultMutableTreeNode::getChildCount | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public int getIndex(TreeNode aChild) {
if (aChild == null) {
throw new IllegalArgumentException("argument is null");
}
if (!isNodeChild(aChild)) {
return -1;
}
return children.indexOf(aChild); // linear search
} |
Returns the index of the specified child in this node's child array.
If the specified node is not a child of this node, returns
<code>-1</code>. This method performs a linear search and is O(n)
where n is the number of children.
@param aChild the TreeNode to search for among this node's children
@exception IllegalArgumentException if <code>aChild</code>
is null
@return an int giving the index of the node in this node's child
array, or <code>-1</code> if the specified node is a not
a child of this node
| DefaultMutableTreeNode::getIndex | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public Enumeration children() {
if (children == null) {
return EMPTY_ENUMERATION;
} else {
return children.elements();
}
} |
Creates and returns a forward-order enumeration of this node's
children. Modifying this node's child array invalidates any child
enumerations created before the modification.
@return an Enumeration of this node's children
| DefaultMutableTreeNode::children | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public void setAllowsChildren(boolean allows) {
if (allows != allowsChildren) {
allowsChildren = allows;
if (!allowsChildren) {
removeAllChildren();
}
}
} |
Determines whether or not this node is allowed to have children.
If <code>allows</code> is false, all of this node's children are
removed.
<p>
Note: By default, a node allows children.
@param allows true if this node is allowed to have children
| DefaultMutableTreeNode::setAllowsChildren | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public boolean getAllowsChildren() {
return allowsChildren;
} |
Returns true if this node is allowed to have children.
@return true if this node allows children, else false
| DefaultMutableTreeNode::getAllowsChildren | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public void setUserObject(Object userObject) {
this.userObject = userObject;
} |
Sets the user object for this node to <code>userObject</code>.
@param userObject the Object that constitutes this node's
user-specified data
@see #getUserObject
@see #toString
| DefaultMutableTreeNode::setUserObject | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public Object getUserObject() {
return userObject;
} |
Returns this node's user object.
@return the Object stored at this node by the user
@see #setUserObject
@see #toString
| DefaultMutableTreeNode::getUserObject | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public void removeFromParent() {
MutableTreeNode parent = (MutableTreeNode)getParent();
if (parent != null) {
parent.remove(this);
}
} |
Removes the subtree rooted at this node from the tree, giving this
node a null parent. Does nothing if this node is the root of its
tree.
| DefaultMutableTreeNode::removeFromParent | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public void remove(MutableTreeNode aChild) {
if (aChild == null) {
throw new IllegalArgumentException("argument is null");
}
if (!isNodeChild(aChild)) {
throw new IllegalArgumentException("argument is not a child");
}
remove(getIndex(aChild)); // linear search
} |
Removes <code>aChild</code> from this node's child array, giving it a
null parent.
@param aChild a child of this node to remove
@exception IllegalArgumentException if <code>aChild</code>
is null or is not a child of this node
| DefaultMutableTreeNode::remove | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public void removeAllChildren() {
for (int i = getChildCount()-1; i >= 0; i--) {
remove(i);
}
} |
Removes all of this node's children, setting their parents to null.
If this node has no children, this method does nothing.
| DefaultMutableTreeNode::removeAllChildren | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public void add(MutableTreeNode newChild) {
if(newChild != null && newChild.getParent() == this)
insert(newChild, getChildCount() - 1);
else
insert(newChild, getChildCount());
} |
Removes <code>newChild</code> from its parent and makes it a child of
this node by adding it to the end of this node's child array.
@see #insert
@param newChild node to add as a child of this node
@exception IllegalArgumentException if <code>newChild</code>
is null
@exception IllegalStateException if this node does not allow
children
| DefaultMutableTreeNode::add | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public boolean isNodeAncestor(TreeNode anotherNode) {
if (anotherNode == null) {
return false;
}
TreeNode ancestor = this;
do {
if (ancestor == anotherNode) {
return true;
}
} while((ancestor = ancestor.getParent()) != null);
return false;
} |
Returns true if <code>anotherNode</code> is an ancestor of this node
-- if it is this node, this node's parent, or an ancestor of this
node's parent. (Note that a node is considered an ancestor of itself.)
If <code>anotherNode</code> is null, this method returns false. This
operation is at worst O(h) where h is the distance from the root to
this node.
@see #isNodeDescendant
@see #getSharedAncestor
@param anotherNode node to test as an ancestor of this node
@return true if this node is a descendant of <code>anotherNode</code>
| DefaultMutableTreeNode::isNodeAncestor | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public boolean isNodeDescendant(DefaultMutableTreeNode anotherNode) {
if (anotherNode == null)
return false;
return anotherNode.isNodeAncestor(this);
} |
Returns true if <code>anotherNode</code> is a descendant of this node
-- if it is this node, one of this node's children, or a descendant of
one of this node's children. Note that a node is considered a
descendant of itself. If <code>anotherNode</code> is null, returns
false. This operation is at worst O(h) where h is the distance from the
root to <code>anotherNode</code>.
@see #isNodeAncestor
@see #getSharedAncestor
@param anotherNode node to test as descendant of this node
@return true if this node is an ancestor of <code>anotherNode</code>
| DefaultMutableTreeNode::isNodeDescendant | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public TreeNode getSharedAncestor(DefaultMutableTreeNode aNode) {
if (aNode == this) {
return this;
} else if (aNode == null) {
return null;
}
int level1, level2, diff;
TreeNode node1, node2;
level1 = getLevel();
level2 = aNode.getLevel();
if (level2 > level1) {
diff = level2 - level1;
node1 = aNode;
node2 = this;
} else {
diff = level1 - level2;
node1 = this;
node2 = aNode;
}
// Go up the tree until the nodes are at the same level
while (diff > 0) {
node1 = node1.getParent();
diff--;
}
// Move up the tree until we find a common ancestor. Since we know
// that both nodes are at the same level, we won't cross paths
// unknowingly (if there is a common ancestor, both nodes hit it in
// the same iteration).
do {
if (node1 == node2) {
return node1;
}
node1 = node1.getParent();
node2 = node2.getParent();
} while (node1 != null);// only need to check one -- they're at the
// same level so if one is null, the other is
if (node1 != null || node2 != null) {
throw new Error ("nodes should be null");
}
return null;
} |
Returns the nearest common ancestor to this node and <code>aNode</code>.
Returns null, if no such ancestor exists -- if this node and
<code>aNode</code> are in different trees or if <code>aNode</code> is
null. A node is considered an ancestor of itself.
@see #isNodeAncestor
@see #isNodeDescendant
@param aNode node to find common ancestor with
@return nearest ancestor common to this node and <code>aNode</code>,
or null if none
| DefaultMutableTreeNode::getSharedAncestor | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public boolean isNodeRelated(DefaultMutableTreeNode aNode) {
return (aNode != null) && (getRoot() == aNode.getRoot());
} |
Returns true if and only if <code>aNode</code> is in the same tree
as this node. Returns false if <code>aNode</code> is null.
@see #getSharedAncestor
@see #getRoot
@return true if <code>aNode</code> is in the same tree as this node;
false if <code>aNode</code> is null
| DefaultMutableTreeNode::isNodeRelated | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public int getDepth() {
Object last = null;
Enumeration enum_ = breadthFirstEnumeration();
while (enum_.hasMoreElements()) {
last = enum_.nextElement();
}
if (last == null) {
throw new Error ("nodes should be null");
}
return ((DefaultMutableTreeNode)last).getLevel() - getLevel();
} |
Returns the depth of the tree rooted at this node -- the longest
distance from this node to a leaf. If this node has no children,
returns 0. This operation is much more expensive than
<code>getLevel()</code> because it must effectively traverse the entire
tree rooted at this node.
@see #getLevel
@return the depth of the tree whose root is this node
| DefaultMutableTreeNode::getDepth | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
public int getLevel() {
TreeNode ancestor;
int levels = 0;
ancestor = this;
while((ancestor = ancestor.getParent()) != null){
levels++;
}
return levels;
} |
Returns the number of levels above this node -- the distance from
the root to this node. If this node is the root, returns 0.
@see #getDepth
@return the number of levels above this node
| DefaultMutableTreeNode::getLevel | java | ZTFtrue/MonsterMusic | app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java | Apache-2.0 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.